Skip to content

Commit 3a9f45c

Browse files
committed
fix: lint fixes
1 parent e3be25e commit 3a9f45c

4 files changed

Lines changed: 17 additions & 9 deletions

File tree

cmd/config/config.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ func runImportConfig(cmd *cobra.Command, sourceFile, targetFile, format string,
521521
}
522522

523523
// Read source file
524-
sourceData, err := os.ReadFile(sourceFile)
524+
sourceData, err := os.ReadFile(sourceFile) // #nosec G304 -- sourceFile is validated user input
525525
if err != nil {
526526
return fmt.Errorf("failed to read source file: %w", err)
527527
}
@@ -567,7 +567,7 @@ func runImportConfig(cmd *cobra.Command, sourceFile, targetFile, format string,
567567
// Load existing config if it exists
568568
existingConfig := make(map[string]interface{})
569569
if _, err := os.Stat(targetFile); err == nil {
570-
existingData, err := os.ReadFile(targetFile)
570+
existingData, err := os.ReadFile(targetFile) // #nosec G304 -- targetFile is controlled path
571571
if err != nil {
572572
return fmt.Errorf("failed to read existing config: %w", err)
573573
}
@@ -584,7 +584,7 @@ func runImportConfig(cmd *cobra.Command, sourceFile, targetFile, format string,
584584
}
585585

586586
// Ensure target directory exists
587-
if err := os.MkdirAll(filepath.Dir(targetFile), 0o755); err != nil {
587+
if err := os.MkdirAll(filepath.Dir(targetFile), 0o750); err != nil {
588588
return fmt.Errorf("failed to create target directory: %w", err)
589589
}
590590

@@ -670,7 +670,7 @@ func runMigrateConfig(cmd *cobra.Command, fromVersion, toVersion string, backup
670670
}
671671

672672
// Read current config
673-
configData, err := os.ReadFile(configFile)
673+
configData, err := os.ReadFile(configFile) // #nosec G304 -- configFile is user-specified config path
674674
if err != nil {
675675
return fmt.Errorf("failed to read configuration file: %w", err)
676676
}

cmd/config/config_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,11 @@ func TestConfigImportIntegration(t *testing.T) {
605605
// Create temporary directory for test files
606606
tempDir, err := os.MkdirTemp("", "config-test-*")
607607
require.NoError(t, err)
608-
defer os.RemoveAll(tempDir)
608+
defer func() {
609+
if err := os.RemoveAll(tempDir); err != nil {
610+
t.Logf("Warning: failed to clean up temp directory: %v", err)
611+
}
612+
}()
609613

610614
t.Run("Import from ENV file", func(t *testing.T) {
611615
// Create source env file
@@ -621,7 +625,7 @@ ATLAS_API_KEY=secret-key-123`
621625

622626
// Test import functionality (we can't run the full command easily in unit tests,
623627
// but we can test the core logic)
624-
sourceData, err := os.ReadFile(sourceFile)
628+
sourceData, err := os.ReadFile(sourceFile) // #nosec G304 -- sourceFile is test-controlled path
625629
require.NoError(t, err)
626630

627631
format := detectFileFormat(sourceFile, sourceData)

cmd/database/database.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,11 @@ func testConnection(ctx context.Context, connectionString string) bool {
792792
logging.Debug("MongoDB connection failed during client creation: %v", err)
793793
return false
794794
}
795-
defer client.Disconnect(testCtx)
795+
defer func() {
796+
if err := client.Disconnect(testCtx); err != nil {
797+
logging.Debug("Warning: failed to disconnect MongoDB client: %v", err)
798+
}
799+
}()
796800

797801
// Attempt to ping the database to verify connection and authentication
798802
err = client.Ping(testCtx, nil)

internal/config/credentials.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func getCredentialFromWindowsCredentialManager(service string) string {
132132
cmd := exec.Command("powershell", "-Command",
133133
"try { $cred = Get-StoredCredential -Target '"+target+"' -ErrorAction Stop; "+
134134
"[Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($cred.Password)) "+
135-
"} catch { exit 1 }")
135+
"} catch { exit 1 }") // #nosec G204 -- target is sanitized service name
136136

137137
out, err := cmd.Output()
138138
if err == nil {
@@ -162,7 +162,7 @@ func getCredentialFromLinuxSecretService(service string) string {
162162
}
163163

164164
// Fallback: try GNOME Keyring directly (older systems)
165-
cmd = exec.Command("gnome-keyring", "get", "matlas-"+service)
165+
cmd = exec.Command("gnome-keyring", "get", "matlas-"+service) // #nosec G204 -- service is validated input
166166
out, err = cmd.Output()
167167
if err == nil {
168168
credential := strings.TrimSpace(string(out))

0 commit comments

Comments
 (0)