mirror of
https://github.com/kubescape/kubescape.git
synced 2026-02-14 18:09:55 +00:00
Fix RelSource for Files
This commit is contained in:
@@ -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 ""
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user