mirror of
https://github.com/lukaszraczylo/gohoarder.git
synced 2026-06-10 23:29:22 +00:00
fixes
This commit is contained in:
@@ -49,7 +49,7 @@ func (cs *CredentialStore) LoadFromFile(path string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
data, err := os.ReadFile(path)
|
||||
data, err := os.ReadFile(path) // #nosec G304 -- Path is from config, not user input
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to read credential file: %w", err)
|
||||
}
|
||||
|
||||
+5
-5
@@ -65,7 +65,7 @@ func (g *GitFetcher) FetchModule(ctx context.Context, modulePath, version, crede
|
||||
// Set up credentials
|
||||
credentialHelper, cleanup, err := g.setupCredentials(repoURL, modulePath, credentials)
|
||||
if err != nil {
|
||||
os.RemoveAll(cloneDir)
|
||||
_ = os.RemoveAll(cloneDir) // #nosec G104 -- Cleanup
|
||||
return "", fmt.Errorf("failed to setup credentials: %w", err)
|
||||
}
|
||||
defer cleanup()
|
||||
@@ -76,13 +76,13 @@ func (g *GitFetcher) FetchModule(ctx context.Context, modulePath, version, crede
|
||||
|
||||
// Fallback to full clone
|
||||
if err := g.fullClone(ctx, repoURL, cloneDir, credentialHelper); err != nil {
|
||||
os.RemoveAll(cloneDir)
|
||||
_ = os.RemoveAll(cloneDir) // #nosec G104 -- Cleanup
|
||||
return "", fmt.Errorf("git clone failed: %w", err)
|
||||
}
|
||||
|
||||
// Checkout specific version
|
||||
if err := g.checkout(ctx, cloneDir, version); err != nil {
|
||||
os.RemoveAll(cloneDir)
|
||||
_ = os.RemoveAll(cloneDir) // #nosec G104 -- Cleanup
|
||||
return "", fmt.Errorf("git checkout failed: %w", err)
|
||||
}
|
||||
}
|
||||
@@ -165,7 +165,7 @@ func (g *GitFetcher) createTempNetrc(repoURL, username, token string) (map[strin
|
||||
netrcPath := filepath.Join(tempDir, ".netrc")
|
||||
netrcContent := fmt.Sprintf("machine %s\nlogin %s\npassword %s\n", host, username, token)
|
||||
if err := os.WriteFile(netrcPath, []byte(netrcContent), 0600); err != nil {
|
||||
os.RemoveAll(tempDir)
|
||||
_ = os.RemoveAll(tempDir) // #nosec G104 -- Cleanup
|
||||
return nil, nil, fmt.Errorf("failed to write .netrc: %w", err)
|
||||
}
|
||||
|
||||
@@ -175,7 +175,7 @@ func (g *GitFetcher) createTempNetrc(repoURL, username, token string) (map[strin
|
||||
}
|
||||
|
||||
cleanup := func() {
|
||||
os.RemoveAll(tempDir)
|
||||
_ = os.RemoveAll(tempDir) // #nosec G104 -- Cleanup
|
||||
}
|
||||
|
||||
log.Debug().Str("host", host).Msg("Created temporary .netrc for git authentication")
|
||||
|
||||
+4
-4
@@ -57,7 +57,7 @@ func (b *ModuleBuilder) BuildModuleZip(ctx context.Context, srcPath, modulePath,
|
||||
prefix := fmt.Sprintf("%s@%s/", modulePath, version)
|
||||
for _, relPath := range files {
|
||||
if err := b.addFileToZip(zipWriter, srcPath, relPath, prefix); err != nil {
|
||||
zipWriter.Close()
|
||||
zipWriter.Close() // #nosec G104 -- Cleanup, error not critical
|
||||
return nil, fmt.Errorf("failed to add file %s: %w", relPath, err)
|
||||
}
|
||||
}
|
||||
@@ -148,11 +148,11 @@ func (b *ModuleBuilder) addFileToZip(zipWriter *zip.Writer, srcPath, relPath, pr
|
||||
}
|
||||
|
||||
// Copy file contents
|
||||
file, err := os.Open(fullPath)
|
||||
file, err := os.Open(fullPath) // #nosec G304 -- Path is from zip archive extraction
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer file.Close()
|
||||
defer file.Close() // #nosec G104 -- Cleanup, error not critical
|
||||
|
||||
if _, err := io.Copy(writer, file); err != nil {
|
||||
return err
|
||||
@@ -207,7 +207,7 @@ func (b *ModuleBuilder) getGitCommitTime(repoPath string) (time.Time, error) {
|
||||
func (b *ModuleBuilder) ExtractGoMod(ctx context.Context, srcPath string) ([]byte, error) {
|
||||
goModPath := filepath.Join(srcPath, "go.mod")
|
||||
|
||||
data, err := os.ReadFile(goModPath)
|
||||
data, err := os.ReadFile(goModPath) // #nosec G304 -- Path is from controlled temp directory
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to read go.mod: %w", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user