Fix RelSource for Files

This commit is contained in:
suhasgumma
2022-11-29 23:55:19 +05:30
committed by Vlad Klokun
parent a3defe3025
commit 92a2704fa6
2 changed files with 15 additions and 3 deletions

View File

@@ -62,11 +62,12 @@ func NewFixHandler(fixInfo *metav1.FixInfo) (*FixHandler, error) {
}
func isSupportedScanningTarget(report *reporthandlingv2.PostureReport) error {
if report.Metadata.ScanMetadata.ScanningTarget == reporthandlingv2.GitLocal || report.Metadata.ScanMetadata.ScanningTarget == reporthandlingv2.Directory {
scanningTarget := report.Metadata.ScanMetadata.ScanningTarget
if scanningTarget == reporthandlingv2.GitLocal || scanningTarget == reporthandlingv2.Directory || scanningTarget == reporthandlingv2.File {
return nil
}
return fmt.Errorf("unsupported scanning target. Only local git and directory scanning targets are supported")
return fmt.Errorf("unsupported scanning target. Only local git, directory and file scanning targets are supported")
}
func getLocalPath(report *reporthandlingv2.PostureReport) string {
@@ -78,6 +79,10 @@ func getLocalPath(report *reporthandlingv2.PostureReport) string {
return report.Metadata.ContextMetadata.DirectoryContextMetadata.BasePath
}
if report.Metadata.ScanMetadata.ScanningTarget == reporthandlingv2.File {
return report.Metadata.ContextMetadata.FileContextMetadata.FilePath
}
return ""
}

View File

@@ -88,6 +88,7 @@ func (fileHandler *FileResourceHandler) GetResources(sessionObj *cautils.OPASess
}
func getResourcesFromPath(path string) (map[string]reporthandling.Source, []workloadinterface.IMetadata, error) {
workloadIDToSource := make(map[string]reporthandling.Source, 0)
workloads := []workloadinterface.IMetadata{}
@@ -116,7 +117,13 @@ func getResourcesFromPath(path string) (map[string]reporthandling.Source, []work
for source, ws := range sourceToWorkloads {
workloads = append(workloads, ws...)
relSource, err := filepath.Rel(repoRoot, source)
var relSource string
if repoRoot == source {
relSource = repoRoot
} else {
relSource, err = filepath.Rel(repoRoot, source)
}
if err == nil {
source = relSource
}