mirror of
https://github.com/kubescape/kubescape.git
synced 2026-04-15 06:58:11 +00:00
Fixed relative path in git repo scan
This commit is contained in:
@@ -116,3 +116,12 @@ func (g *LocalGitRepository) GetFileLastCommit(filePath string) (*apis.Commit, e
|
||||
Files: []apis.Files{},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (g *LocalGitRepository) GetRootDir() (string, error) {
|
||||
wt, err := g.repo.Worktree()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to get repo root")
|
||||
}
|
||||
|
||||
return wt.Filesystem.Root(), nil
|
||||
}
|
||||
|
||||
@@ -65,8 +65,21 @@ func (fileHandler *FileResourceHandler) GetResources(sessionObj *cautils.OPASess
|
||||
if err != nil {
|
||||
return nil, allResources, nil, err
|
||||
}
|
||||
|
||||
// Get repo root
|
||||
repoRoot := ""
|
||||
giRepo, err := cautils.NewLocalGitRepository(path)
|
||||
if err == nil {
|
||||
repoRoot, _ = giRepo.GetRootDir()
|
||||
}
|
||||
|
||||
for source, ws := range sourceToWorkloads {
|
||||
workloads = append(workloads, ws...)
|
||||
|
||||
relSource, err := filepath.Rel(repoRoot, source)
|
||||
if err == nil {
|
||||
source = relSource
|
||||
}
|
||||
for i := range ws {
|
||||
workloadIDToSource[ws[i].GetID()] = reporthandling.Source{RelativePath: source}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user