Skip to content

Commit e6dfd50

Browse files
committed
fix: fmt
1 parent 3a9f45c commit e6dfd50

15 files changed

Lines changed: 166 additions & 168 deletions

cmd/atlas/search/search_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func TestNewSearchCmd_VisibleAndSubcommands(t *testing.T) {
1313
if cmd.Hidden {
1414
t.Fatalf("expected search command to be visible, but it was hidden")
1515
}
16-
16+
1717
// Verify command properties
1818
if cmd.Use != "search" {
1919
t.Errorf("expected Use to be 'search', got '%s'", cmd.Use)
@@ -24,13 +24,13 @@ func TestNewSearchCmd_VisibleAndSubcommands(t *testing.T) {
2424
if cmd.Long == "" {
2525
t.Error("expected Long description to be non-empty")
2626
}
27-
27+
2828
// Verify aliases are present
2929
expectedAliases := []string{"search-index", "search-indexes"}
3030
if len(cmd.Aliases) != len(expectedAliases) {
3131
t.Errorf("expected %d aliases, got %d", len(expectedAliases), len(cmd.Aliases))
3232
}
33-
33+
3434
// Ensure all expected subcommands are present
3535
found := map[string]bool{}
3636
for _, c := range cmd.Commands() {
@@ -42,7 +42,7 @@ func TestNewSearchCmd_VisibleAndSubcommands(t *testing.T) {
4242
t.Errorf("expected subcommand '%s' to be present", expectedCmd)
4343
}
4444
}
45-
45+
4646
if len(found) != len(expectedCommands) {
4747
t.Errorf("expected exactly %d subcommands, got %d: %+v", len(expectedCommands), len(found), found)
4848
}

cmd/config/config.go

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -906,27 +906,27 @@ func detectFileFormat(filename string, data []byte) string {
906906
func parseEnvFile(data []byte) map[string]interface{} {
907907
config := make(map[string]interface{})
908908
lines := strings.Split(string(data), "\n")
909-
909+
910910
for _, line := range lines {
911911
line = strings.TrimSpace(line)
912912
if line == "" || strings.HasPrefix(line, "#") {
913913
continue
914914
}
915-
915+
916916
parts := strings.SplitN(line, "=", 2)
917917
if len(parts) != 2 {
918918
continue
919919
}
920-
920+
921921
key := strings.TrimSpace(parts[0])
922922
value := strings.TrimSpace(parts[1])
923-
923+
924924
// Remove quotes if present
925925
if (strings.HasPrefix(value, "\"") && strings.HasSuffix(value, "\"")) ||
926-
(strings.HasPrefix(value, "'") && strings.HasSuffix(value, "'")) {
926+
(strings.HasPrefix(value, "'") && strings.HasSuffix(value, "'")) {
927927
value = value[1 : len(value)-1]
928928
}
929-
929+
930930
// Convert common Atlas environment variables to config keys
931931
switch key {
932932
case "ATLAS_PROJECT_ID":
@@ -952,13 +952,13 @@ func parseEnvFile(data []byte) map[string]interface{} {
952952
}
953953
}
954954
}
955-
955+
956956
return config
957957
}
958958

959959
func normalizeConfigKeys(config map[string]interface{}) map[string]interface{} {
960960
normalized := make(map[string]interface{})
961-
961+
962962
for key, value := range config {
963963
// Convert various key formats to standard camelCase
964964
normalKey := key
@@ -974,26 +974,26 @@ func normalizeConfigKeys(config map[string]interface{}) map[string]interface{} {
974974
case "public_key", "public-key", "pub_key", "pub-key", "publickey":
975975
normalKey = "publicKey"
976976
}
977-
977+
978978
normalized[normalKey] = value
979979
}
980-
980+
981981
return normalized
982982
}
983983

984984
func mergeConfigs(existing, source map[string]interface{}) map[string]interface{} {
985985
result := make(map[string]interface{})
986-
986+
987987
// Copy existing config
988988
for key, value := range existing {
989989
result[key] = value
990990
}
991-
991+
992992
// Overlay source config (source wins conflicts)
993993
for key, value := range source {
994994
result[key] = value
995995
}
996-
996+
997997
return result
998998
}
999999

@@ -1121,7 +1121,7 @@ func detectConfigVersion(config map[string]interface{}) string {
11211121
}
11221122

11231123
// Check for schema indicators to detect version
1124-
1124+
11251125
// v2.0.0+ indicators (current format)
11261126
if _, hasProjectId := config["projectId"]; hasProjectId {
11271127
// Check for new camelCase format
@@ -1147,7 +1147,7 @@ func detectConfigVersion(config map[string]interface{}) string {
11471147

11481148
func applyMigrations(config map[string]interface{}, fromVersion, toVersion string) (map[string]interface{}, error) {
11491149
result := make(map[string]interface{})
1150-
1150+
11511151
// Copy original config
11521152
for k, v := range config {
11531153
result[k] = v
@@ -1176,7 +1176,7 @@ func applyMigrations(config map[string]interface{}, fromVersion, toVersion strin
11761176

11771177
// Add version field to migrated config
11781178
result["version"] = toVersion
1179-
1179+
11801180
return result, nil
11811181
}
11821182

@@ -1189,11 +1189,11 @@ type migration struct {
11891189
func shouldApplyMigration(currentVersion, targetVersion, migrationFrom, migrationTo string) bool {
11901190
// Apply migration if:
11911191
// 1. Current version is at or past the migration starting point
1192-
// 2. Target version includes this migration step
1192+
// 2. Target version includes this migration step
11931193
// 3. Current version is before the migration endpoint (to avoid applying migrations we've already done)
1194-
return versionLessOrEqual(migrationFrom, currentVersion) &&
1195-
versionLessOrEqual(migrationTo, targetVersion) &&
1196-
versionLess(currentVersion, migrationTo)
1194+
return versionLessOrEqual(migrationFrom, currentVersion) &&
1195+
versionLessOrEqual(migrationTo, targetVersion) &&
1196+
versionLess(currentVersion, migrationTo)
11971197
}
11981198

11991199
func versionLessOrEqual(v1, v2 string) bool {
@@ -1210,64 +1210,64 @@ func versionLess(v1, v2 string) bool {
12101210

12111211
func migrateV0_9ToV1_0(config map[string]interface{}) (map[string]interface{}, error) {
12121212
result := make(map[string]interface{})
1213-
1213+
12141214
// Copy all existing values
12151215
for k, v := range config {
12161216
result[k] = v
12171217
}
1218-
1218+
12191219
// Add default values that were introduced in v1.0.0
12201220
if _, exists := result["timeout"]; !exists {
12211221
result["timeout"] = "30s"
12221222
}
12231223
if _, exists := result["output"]; !exists {
12241224
result["output"] = "text"
12251225
}
1226-
1226+
12271227
return result, nil
12281228
}
12291229

12301230
func migrateV1_0ToV1_5(config map[string]interface{}) (map[string]interface{}, error) {
12311231
result := make(map[string]interface{})
1232-
1232+
12331233
// Migrate from snake_case to camelCase (partial migration)
12341234
keyMappings := map[string]string{
12351235
"project_id": "projectId",
1236-
"org_id": "orgId",
1236+
"org_id": "orgId",
12371237
"cluster_name": "clusterName",
12381238
"api_key": "apiKey",
12391239
"public_key": "publicKey",
12401240
}
1241-
1241+
12421242
for oldKey, newKey := range keyMappings {
12431243
if value, exists := config[oldKey]; exists {
12441244
result[newKey] = value
12451245
}
12461246
}
1247-
1247+
12481248
// Copy other values as-is
12491249
for k, v := range config {
12501250
if _, isMapped := keyMappings[k]; !isMapped {
12511251
result[k] = v
12521252
}
12531253
}
1254-
1254+
12551255
return result, nil
12561256
}
12571257

12581258
func migrateV1_5ToV2_0(config map[string]interface{}) (map[string]interface{}, error) {
12591259
result := make(map[string]interface{})
1260-
1260+
12611261
// Copy all existing values (v1.5.0 → v2.0.0 is mostly compatible)
12621262
for k, v := range config {
12631263
result[k] = v
12641264
}
1265-
1265+
12661266
// Ensure all keys are in proper camelCase format
12671267
result = normalizeConfigKeys(result)
1268-
1268+
12691269
// Remove any deprecated keys
12701270
delete(result, "deprecated_field") // Example - remove any deprecated fields
1271-
1271+
12721272
return result, nil
12731273
}

cmd/config/config_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
"github.com/stretchr/testify/assert"
1111
"github.com/stretchr/testify/require"
12-
12+
1313
"github.com/teabranch/matlas-cli/internal/config"
1414
)
1515

@@ -412,12 +412,12 @@ func TestConfigToMap(t *testing.T) {
412412
t.Run("Exclude secrets", func(t *testing.T) {
413413
result := configToMap(cfg, false)
414414
expected := map[string]interface{}{
415-
"projectId": "12345",
416-
"clusterName": "my-cluster",
417-
"output": "json",
418-
"timeout": "45s",
419-
"# apiKey": "[REDACTED - use --include-secrets to export]",
420-
"# publicKey": "[REDACTED - use --include-secrets to export]",
415+
"projectId": "12345",
416+
"clusterName": "my-cluster",
417+
"output": "json",
418+
"timeout": "45s",
419+
"# apiKey": "[REDACTED - use --include-secrets to export]",
420+
"# publicKey": "[REDACTED - use --include-secrets to export]",
421421
}
422422
assert.Equal(t, expected, result)
423423
})
@@ -432,7 +432,7 @@ func TestConvertToEnvFormat(t *testing.T) {
432432
}
433433

434434
result := convertToEnvFormat(configMap, true)
435-
435+
436436
assert.Contains(t, result, "ATLAS_PROJECT_ID=12345")
437437
assert.Contains(t, result, "ATLAS_CLUSTER_NAME=my-cluster")
438438
assert.Contains(t, result, "ATLAS_OUTPUT=json")
@@ -447,7 +447,7 @@ func TestConvertToShellExportFormat(t *testing.T) {
447447
}
448448

449449
result := convertToShellExportFormat(configMap, true)
450-
450+
451451
assert.Contains(t, result, `export ATLAS_PROJECT_ID="12345"`)
452452
assert.Contains(t, result, `export ATLAS_OUTPUT="json"`)
453453
assert.Contains(t, result, "# matlas-cli configuration as shell export statements")
@@ -586,8 +586,8 @@ func TestMigrationTransformations(t *testing.T) {
586586

587587
t.Run("migrateV1_5ToV2_0", func(t *testing.T) {
588588
input := map[string]interface{}{
589-
"projectId": "12345",
590-
"cluster-name": "my-cluster", // Mixed format
589+
"projectId": "12345",
590+
"cluster-name": "my-cluster", // Mixed format
591591
"deprecated_field": "should-be-removed",
592592
}
593593

cmd/database/database.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -781,11 +781,11 @@ func testConnection(ctx context.Context, connectionString string) bool {
781781

782782
// Create MongoDB client options
783783
clientOptions := options.Client().ApplyURI(connectionString)
784-
784+
785785
// Set connection timeout and server selection timeout
786786
clientOptions.SetConnectTimeout(5 * time.Second)
787787
clientOptions.SetServerSelectionTimeout(5 * time.Second)
788-
788+
789789
// Create MongoDB client
790790
client, err := mongo.Connect(testCtx, clientOptions)
791791
if err != nil {

cmd/infra/apply.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ func convertToClusterSpec(spec interface{}) types.ClusterSpec {
837837
if clusterType, ok := specMap["clusterType"].(string); ok {
838838
clusterSpec.ClusterType = clusterType
839839
}
840-
840+
841841
// Convert complex fields
842842
if replicationSpecs, ok := specMap["replicationSpecs"].([]interface{}); ok {
843843
clusterSpec.ReplicationSpecs = convertToReplicationSpecs(replicationSpecs)
@@ -854,7 +854,7 @@ func convertToClusterSpec(spec interface{}) types.ClusterSpec {
854854
if tags, ok := specMap["tags"].(map[string]interface{}); ok {
855855
clusterSpec.Tags = convertToStringMap(tags)
856856
}
857-
857+
858858
return clusterSpec
859859
}
860860
return types.ClusterSpec{}

internal/config/credentials.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,19 +129,19 @@ func getCredentialFromWindowsCredentialManager(service string) string {
129129
// Use PowerShell to access Windows Credential Manager
130130
// Get-StoredCredential -Target "matlas:<service>" | Select-Object -ExpandProperty Password
131131
target := "matlas:" + service
132-
cmd := exec.Command("powershell", "-Command",
132+
cmd := exec.Command("powershell", "-Command",
133133
"try { $cred = Get-StoredCredential -Target '"+target+"' -ErrorAction Stop; "+
134-
"[Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($cred.Password)) "+
135-
"} catch { exit 1 }") // #nosec G204 -- target is sanitized service name
136-
134+
"[Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($cred.Password)) "+
135+
"} catch { exit 1 }") // #nosec G204 -- target is sanitized service name
136+
137137
out, err := cmd.Output()
138138
if err == nil {
139139
credential := strings.TrimSpace(string(out))
140140
if credential != "" {
141141
return credential
142142
}
143143
}
144-
144+
145145
// Fallback: try cmdkey (older method)
146146
// This doesn't retrieve passwords, but we can check if the credential exists
147147
// For security reasons, Windows doesn't easily expose stored passwords via cmdkey
@@ -160,7 +160,7 @@ func getCredentialFromLinuxSecretService(service string) string {
160160
return credential
161161
}
162162
}
163-
163+
164164
// Fallback: try GNOME Keyring directly (older systems)
165165
cmd = exec.Command("gnome-keyring", "get", "matlas-"+service) // #nosec G204 -- service is validated input
166166
out, err = cmd.Output()
@@ -170,6 +170,6 @@ func getCredentialFromLinuxSecretService(service string) string {
170170
return credential
171171
}
172172
}
173-
173+
174174
return ""
175175
}

internal/types/apply.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ type DatabaseUserSpec struct {
170170
Scopes []UserScopeConfig `yaml:"scopes,omitempty" json:"scopes,omitempty"`
171171
}
172172

173-
174173
// DatabaseRoleManifest represents a database role resource manifest
175174
type DatabaseRoleManifest struct {
176175
APIVersion APIVersion `yaml:"apiVersion" json:"apiVersion"`

internal/types/apply_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,6 @@ func TestDatabaseUserManifest_YAMLMarshaling(t *testing.T) {
319319
}
320320
}
321321

322-
323322
func TestNetworkAccessManifest_YAMLMarshaling(t *testing.T) {
324323
networkAccess := NetworkAccessManifest{
325324
APIVersion: APIVersionV1,

0 commit comments

Comments
 (0)