-
Notifications
You must be signed in to change notification settings - Fork 28
Add support for containers scan in cloud by default (AST-00000) #1024
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -312,7 +312,6 @@ func TestRunGetResultsByScanIdSarifFormat(t *testing.T) { | |
| } | ||
| func TestRunGetResultsByScanIdSarifFormatWithContainers(t *testing.T) { | ||
| clearFlags() | ||
| mock.Flag = wrappers.FeatureFlagResponseModel{Name: wrappers.ContainerEngineCLIEnabled, Status: true} | ||
| execCmdNilAssertion(t, "results", "show", "--scan-id", "MOCK", "--report-format", "sarif") | ||
| // Remove generated sarif file | ||
| removeFileBySuffix(t, printer.FormatSarif) | ||
|
|
@@ -334,7 +333,6 @@ func TestRunGetResultsByScanIdSonarFormat(t *testing.T) { | |
|
|
||
| func TestRunGetResultsByScanIdSonarFormatWithContainers(t *testing.T) { | ||
| clearFlags() | ||
| mock.Flag = wrappers.FeatureFlagResponseModel{Name: wrappers.ContainerEngineCLIEnabled, Status: true} | ||
| execCmdNilAssertion(t, "results", "show", "--scan-id", "MOCK", "--report-format", "sonar") | ||
| // Remove generated sonar file | ||
| removeFile(t, fileName+"_"+printer.FormatSonar, printer.FormatJSON) | ||
|
|
@@ -367,7 +365,6 @@ func TestDecodeHTMLEntitiesInResults(t *testing.T) { | |
|
|
||
| func TestRunGetResultsByScanIdJsonFormatWithContainers(t *testing.T) { | ||
| clearFlags() | ||
| mock.Flag = wrappers.FeatureFlagResponseModel{Name: wrappers.ContainerEngineCLIEnabled, Status: true} | ||
| execCmdNilAssertion(t, "results", "show", "--scan-id", "MOCK", "--report-format", "json") | ||
|
|
||
| // Remove generated json file | ||
|
|
@@ -390,7 +387,6 @@ func TestRunGetResultsByScanIdSummaryJsonFormat(t *testing.T) { | |
|
|
||
| func TestRunGetResultsByScanIdSummaryJsonFormatWithContainers(t *testing.T) { | ||
| clearFlags() | ||
| mock.Flag = wrappers.FeatureFlagResponseModel{Name: wrappers.ContainerEngineCLIEnabled, Status: true} | ||
| execCmdNilAssertion(t, "results", "show", "--scan-id", "MOCK", "--report-format", "summaryJSON") | ||
|
|
||
| // Remove generated json file | ||
|
|
@@ -406,7 +402,6 @@ func TestRunGetResultsByScanIdSummaryHtmlFormat(t *testing.T) { | |
|
|
||
| func TestRunGetResultsByScanIdSummaryHtmlFormatWithContainers(t *testing.T) { | ||
| clearFlags() | ||
| mock.Flag = wrappers.FeatureFlagResponseModel{Name: wrappers.ContainerEngineCLIEnabled, Status: true} | ||
| execCmdNilAssertion(t, "results", "show", "--scan-id", "MOCK", "--report-format", "summaryHTML") | ||
|
|
||
| // Remove generated html file | ||
|
|
@@ -425,13 +420,11 @@ func TestRunGetResultsByScanIdSummaryMarkdownFormatWithContainers(t *testing.T) | |
|
|
||
| func TestRunGetResultsByScanIdSummaryConsoleFormatWithContainers(t *testing.T) { | ||
| clearFlags() | ||
| mock.Flag = wrappers.FeatureFlagResponseModel{Name: wrappers.ContainerEngineCLIEnabled, Status: true} | ||
| execCmdNilAssertion(t, "results", "show", "--scan-id", "MOCK", "--report-format", "summaryConsole") | ||
| } | ||
|
|
||
| func TestRunGetResultsByScanIdSummaryMarkdownFormat(t *testing.T) { | ||
| clearFlags() | ||
| mock.Flag = wrappers.FeatureFlagResponseModel{Name: wrappers.ContainerEngineCLIEnabled, Status: true} | ||
| execCmdNilAssertion(t, "results", "show", "--scan-id", "MOCK", "--report-format", "markdown") | ||
| // Remove generated md file | ||
| removeFileBySuffix(t, "md") | ||
|
|
@@ -480,7 +473,6 @@ func TestRunGetResultsByScanIdPDFFormat(t *testing.T) { | |
|
|
||
| func TestRunGetResultsByScanIdPDFFormatWithContainers(t *testing.T) { | ||
| clearFlags() | ||
| mock.Flag = wrappers.FeatureFlagResponseModel{Name: wrappers.ContainerEngineCLIEnabled, Status: true} | ||
| execCmdNilAssertion(t, "results", "show", "--scan-id", "MOCK", "--report-format", "pdf") | ||
| _, err := os.Stat(fmt.Sprintf("%s.%s", fileName, printer.FormatPDF)) | ||
| assert.NilError(t, err, "Report file should exist for extension "+printer.FormatPDF) | ||
|
|
@@ -759,7 +751,6 @@ func TestSBOMReportXML(t *testing.T) { | |
|
|
||
| func TestSBOMReportJsonWithContainers(t *testing.T) { | ||
| clearFlags() | ||
| mock.Flag = wrappers.FeatureFlagResponseModel{Name: wrappers.ContainerEngineCLIEnabled, Status: true} | ||
| execCmdNilAssertion(t, "results", "show", "--scan-id", "MOCK", "--report-format", "sbom") | ||
| _, err := os.Stat(fmt.Sprintf("%s.%s", fileName+"_"+printer.FormatSbom, printer.FormatJSON)) | ||
| assert.NilError(t, err, "Report file should exist for extension "+printer.FormatJSON) | ||
|
|
@@ -769,7 +760,6 @@ func TestSBOMReportJsonWithContainers(t *testing.T) { | |
|
|
||
| func TestSBOMReportXMLWithContainers(t *testing.T) { | ||
| clearFlags() | ||
| mock.Flag = wrappers.FeatureFlagResponseModel{Name: wrappers.ContainerEngineCLIEnabled, Status: true} | ||
| execCmdNilAssertion(t, "results", "show", "--scan-id", "MOCK", "--report-format", "sbom", "--report-sbom-format", "CycloneDxXml") | ||
| _, err := os.Stat(fmt.Sprintf("%s.%s", fileName+"_"+printer.FormatSbom, printer.FormatXML)) | ||
| assert.NilError(t, err, "Report file should exist for extension "+printer.FormatXML) | ||
|
|
@@ -782,26 +772,17 @@ func TestRunGetResultsByScanIdGLFormat(t *testing.T) { | |
| // Run test for gl-sast report type | ||
| os.Remove(fmt.Sprintf("%s.%s", fileName, printer.FormatGLSast)) | ||
| } | ||
|
|
||
| func TestRunResultsShow_ContainersFFIsOn_includeContainersResult(t *testing.T) { | ||
| clearFlags() | ||
| clearFlags() | ||
| mock.Flag = wrappers.FeatureFlagResponseModel{Name: wrappers.ContainerEngineCLIEnabled, Status: true} | ||
| execCmdNilAssertion(t, "results", "show", "--scan-id", "MOCK", "--report-format", "json") | ||
| assertTypePresentJSON(t, params.ContainersType, 1) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's unclear what |
||
| // Remove generated json file | ||
| removeFileBySuffix(t, printer.FormatJSON) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The removal of the generated file should be done in a |
||
| } | ||
| func TestRunResultsShow_ContainersFFIsOff_excludeContainersResult(t *testing.T) { | ||
| clearFlags() | ||
| mock.Flag = wrappers.FeatureFlagResponseModel{Name: wrappers.ContainerEngineCLIEnabled, Status: false} | ||
| execCmdNilAssertion(t, "results", "show", "--scan-id", "MOCK", "--report-format", "json") | ||
| assertTypePresentJSON(t, params.ContainersType, 0) | ||
| // Remove generated json file | ||
| removeFileBySuffix(t, printer.FormatJSON) | ||
| } | ||
|
|
||
| func TestRunResultsShow_jetbrainsIsNotSupported_excludeContainersResult(t *testing.T) { | ||
cx-alex-cohen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| clearFlags() | ||
| mock.Flag = wrappers.FeatureFlagResponseModel{Name: wrappers.ContainerEngineCLIEnabled, Status: true} | ||
| execCmdNilAssertion(t, "results", "show", "--scan-id", "MOCK", "--report-format", "json", "--agent", "jetbrains") | ||
| assertTypePresentJSON(t, params.ContainersType, 0) | ||
| // Remove generated json file | ||
|
|
@@ -810,7 +791,6 @@ func TestRunResultsShow_jetbrainsIsNotSupported_excludeContainersResult(t *testi | |
|
|
||
| func TestRunResultsShow_EclipseIsNotSupported_excludeContainersResult(t *testing.T) { | ||
| clearFlags() | ||
| mock.Flag = wrappers.FeatureFlagResponseModel{Name: wrappers.ContainerEngineCLIEnabled, Status: true} | ||
| execCmdNilAssertion(t, "results", "show", "--scan-id", "MOCK", "--report-format", "json", "--agent", "Eclipse") | ||
| assertTypePresentJSON(t, params.ContainersType, 0) | ||
| // Remove generated json file | ||
|
|
@@ -819,7 +799,6 @@ func TestRunResultsShow_EclipseIsNotSupported_excludeContainersResult(t *testing | |
|
|
||
| func TestRunResultsShow_VsCodeIsNotSupported_excludeContainersResult(t *testing.T) { | ||
| clearFlags() | ||
| mock.Flag = wrappers.FeatureFlagResponseModel{Name: wrappers.ContainerEngineCLIEnabled, Status: true} | ||
| execCmdNilAssertion(t, "results", "show", "--scan-id", "MOCK", "--report-format", "json", "--agent", "vs code") | ||
| assertTypePresentJSON(t, params.ContainersType, 0) | ||
| // Remove generated json file | ||
|
|
@@ -828,7 +807,6 @@ func TestRunResultsShow_VsCodeIsNotSupported_excludeContainersResult(t *testing. | |
|
|
||
| func TestRunResultsShow_VisualStudioIsNotSupported_excludeContainersResult(t *testing.T) { | ||
| clearFlags() | ||
| mock.Flag = wrappers.FeatureFlagResponseModel{Name: wrappers.ContainerEngineCLIEnabled, Status: true} | ||
| execCmdNilAssertion(t, "results", "show", "--scan-id", "MOCK", "--report-format", "json", "--agent", "Visual Studio") | ||
| assertTypePresentJSON(t, params.ContainersType, 0) | ||
| // Remove generated json file | ||
|
|
@@ -952,11 +930,7 @@ func assertResultsPresentSummaryJSON(t *testing.T, isResultsEnabled bool, scanTy | |
| assert.Assert(t, false, "%s result summary should be present", scanType) | ||
| } | ||
| } | ||
| func TestRunGetResultsShow_ContainersFFOffAndResultsHasContainersResultsOnly_NilAssertion(t *testing.T) { | ||
| clearFlags() | ||
| mock.Flag = wrappers.FeatureFlagResponseModel{Name: wrappers.ContainerEngineCLIEnabled, Status: false} | ||
| execCmdNilAssertion(t, "results", "show", "--scan-id", "CONTAINERS_ONLY", "--report-format", "summaryConsole") | ||
| } | ||
|
|
||
| func TestRunGetResultsByScanIdGLSastAndAScaFormat(t *testing.T) { | ||
| execCmdNilAssertion(t, "results", "show", "--scan-id", "MOCK", "--report-format", "gl-sast,gl-sca") | ||
| // Run test for gl-sast report type | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -560,7 +560,8 @@ func scanCreateSubCommand( | |
| "", | ||
| fmt.Sprintf("Parameters to use in SCA resolver (requires --%s).", commonParams.ScaResolverFlag), | ||
| ) | ||
| createScanCmd.PersistentFlags().String(commonParams.ContainerImagesFlag, "", "List of container images to scan, ex: manuelbcd/vulnapp:latest,debian:10. (Not supported yet)") | ||
| createScanCmd.PersistentFlags().String(commonParams.ContainerResolveLocallyFlag, "", "Execute container resolver locally.") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The flag |
||
| createScanCmd.PersistentFlags().String(commonParams.ContainerImagesFlag, "", "List of container images to scan, ex: manuelbcd/vulnapp:latest,debian:10.") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The help message for |
||
| createScanCmd.PersistentFlags().String(commonParams.ScanTypes, "", "Scan types, ex: (sast,iac-security,sca,api-security)") | ||
|
|
||
| createScanCmd.PersistentFlags().String(commonParams.TagList, "", "List of tags, ex: (tagA,tagB:val,etc)") | ||
|
|
@@ -746,7 +747,6 @@ func setupScanTypeProjectAndConfig( | |
| return err | ||
| } | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The removal of the |
||
| containerEngineCLIEnabled, _ := wrappers.GetSpecificFeatureFlag(featureFlagsWrapper, wrappers.ContainerEngineCLIEnabled) | ||
|
|
||
| sastConfig := addSastScan(cmd, resubmitConfig) | ||
| if sastConfig != nil { | ||
|
|
@@ -764,7 +764,7 @@ func setupScanTypeProjectAndConfig( | |
| if apiSecConfig != nil { | ||
| configArr = append(configArr, apiSecConfig) | ||
| } | ||
| var containersConfig = addContainersScan(containerEngineCLIEnabled.Status) | ||
| var containersConfig = addContainersScan() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The removal of the |
||
| if containersConfig != nil { | ||
| configArr = append(configArr, containersConfig) | ||
| } | ||
|
|
@@ -935,8 +935,8 @@ func addScaScan(cmd *cobra.Command, resubmitConfig []wrappers.Config, hasContain | |
| return nil | ||
| } | ||
|
|
||
| func addContainersScan(containerEngineCLIEnabled bool) map[string]interface{} { | ||
| if !scanTypeEnabled(commonParams.ContainersType) || !containerEngineCLIEnabled { | ||
| func addContainersScan() map[string]interface{} { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The removal of the |
||
| if !scanTypeEnabled(commonParams.ContainersType) { | ||
| return nil | ||
| } | ||
| containerMapConfig := make(map[string]interface{}) | ||
|
|
@@ -1071,7 +1071,6 @@ func validateScanTypes(cmd *cobra.Command, jwtWrapper wrappers.JWTWrapper, featu | |
| var scanTypes []string | ||
| var SCSScanTypes []string | ||
|
|
||
| containerEngineCLIEnabled, _ := featureFlagsWrapper.GetSpecificFlag(wrappers.ContainerEngineCLIEnabled) | ||
| allowedEngines, err := jwtWrapper.GetAllowedEngines(featureFlagsWrapper) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The removal of |
||
| if err != nil { | ||
| err = errors.Errorf("Error validating scan types: %v", err) | ||
|
|
@@ -1088,7 +1087,7 @@ func validateScanTypes(cmd *cobra.Command, jwtWrapper wrappers.JWTWrapper, featu | |
|
|
||
| scanTypes = strings.Split(userScanTypes, ",") | ||
| for _, scanType := range scanTypes { | ||
| if !allowedEngines[scanType] || (scanType == commonParams.ContainersType && !(containerEngineCLIEnabled.Status)) { | ||
| if !allowedEngines[scanType] { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The removal of the condition |
||
| keys := reflect.ValueOf(allowedEngines).MapKeys() | ||
| err = errors.Errorf(engineNotAllowed, scanType, scanType, keys) | ||
| return err | ||
|
|
@@ -1104,9 +1103,6 @@ func validateScanTypes(cmd *cobra.Command, jwtWrapper wrappers.JWTWrapper, featu | |
|
|
||
| } else { | ||
| for k := range allowedEngines { | ||
| if k == commonParams.ContainersType && !(containerEngineCLIEnabled.Status) { | ||
| continue | ||
| } | ||
| scanTypes = append(scanTypes, k) | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The removal of the condition checking |
||
| } | ||
|
|
@@ -1303,7 +1299,6 @@ func isDirFiltered(filename string, filters []string) (bool, error) { | |
| } | ||
| } | ||
| } | ||
|
|
||
| return false, nil | ||
| } | ||
|
|
||
|
|
@@ -1398,17 +1393,16 @@ func addScaResults(zipWriter *zip.Writer) error { | |
| } | ||
|
|
||
| func getUploadURLFromSource(cmd *cobra.Command, uploadsWrapper wrappers.UploadsWrapper, featureFlagsWrapper wrappers.FeatureFlagsWrapper) ( | ||
| url, zipFilePath string, | ||
| err error, | ||
| ) { | ||
| url, zipFilePath string, err error) { | ||
|
|
||
| var preSignedURL string | ||
|
|
||
| sourceDirFilter, _ := cmd.Flags().GetString(commonParams.SourceDirFilterFlag) | ||
| userIncludeFilter, _ := cmd.Flags().GetString(commonParams.IncludeFilterFlag) | ||
| projectName, _ := cmd.Flags().GetString(commonParams.ProjectName) | ||
| containerEngineCLIEnabled, _ := wrappers.GetSpecificFeatureFlag(featureFlagsWrapper, wrappers.ContainerEngineCLIEnabled) | ||
|
|
||
| containerScanTriggered := strings.Contains(actualScanTypes, commonParams.ContainersType) && containerEngineCLIEnabled.Status | ||
| containerScanTriggered := strings.Contains(actualScanTypes, commonParams.ContainersType) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The removal of the |
||
| containerResolveLocallyFlag, _ := cmd.Flags().GetString(commonParams.ContainerResolveLocallyFlag) | ||
| containerResolveLocally := strings.EqualFold(containerResolveLocallyFlag, "true") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
| scaResolverParams, scaResolver := getScaResolverFlags(cmd) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The variables |
||
|
|
||
| zipFilePath, directoryPath, err := definePathForZipFileOrDirectory(cmd) | ||
|
|
@@ -1419,7 +1413,7 @@ func getUploadURLFromSource(cmd *cobra.Command, uploadsWrapper wrappers.UploadsW | |
| var errorUnzippingFile error | ||
| userProvidedZip := len(zipFilePath) > 0 | ||
|
|
||
| unzip := ((len(sourceDirFilter) > 0 || len(userIncludeFilter) > 0) || containerScanTriggered) && userProvidedZip | ||
| unzip := ((len(sourceDirFilter) > 0 || len(userIncludeFilter) > 0) || containerResolveLocally) && userProvidedZip | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The variable |
||
| if unzip { | ||
| directoryPath, errorUnzippingFile = UnzipFile(zipFilePath) | ||
| if errorUnzippingFile != nil { | ||
|
|
@@ -1429,14 +1423,29 @@ func getUploadURLFromSource(cmd *cobra.Command, uploadsWrapper wrappers.UploadsW | |
|
|
||
| if directoryPath != "" { | ||
| var dirPathErr error | ||
| resolversErr := runScannerResolvers(cmd, directoryPath, projectName, containerScanTriggered, scaResolver, scaResolverParams) | ||
| if resolversErr != nil { | ||
| if unzip { | ||
| _ = cleanTempUnzipDirectory(directoryPath) | ||
|
|
||
| // execute scaResolver only in sca type of scans | ||
| if strings.Contains(actualScanTypes, commonParams.ScaType) { | ||
| scaErr := runScaResolver(directoryPath, scaResolver, scaResolverParams, projectName) | ||
| if scaErr != nil { | ||
| if unzip { | ||
| _ = cleanTempUnzipDirectory(directoryPath) | ||
| } | ||
| return "", "", errors.Wrapf(scaErr, "ScaResolver error") | ||
| } | ||
| } | ||
|
|
||
| if containerScanTriggered { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider handling the error from |
||
| containerResolverError := runContainerResolver(cmd, directoryPath, containerResolveLocally) | ||
| if containerResolverError != nil { | ||
| if unzip { | ||
| _ = cleanTempUnzipDirectory(directoryPath) | ||
| } | ||
| return "", "", containerResolverError | ||
| } | ||
| return "", "", resolversErr | ||
| } | ||
| if isSingleContainerScanTriggered() { | ||
|
|
||
| if isSingleContainerScanTriggered() && containerResolveLocally { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The condition |
||
| logger.PrintIfVerbose("Single container scan triggered: compressing only the container resolution file") | ||
| containerResolutionFilePath := filepath.Join(directoryPath, containerResolutionFileName) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The variable |
||
| zipFilePath, dirPathErr = util.CompressFile(containerResolutionFilePath, containerResolutionFileName, directoryCreationPrefix) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error handling for |
||
|
|
@@ -1462,7 +1471,7 @@ func getUploadURLFromSource(cmd *cobra.Command, uploadsWrapper wrappers.UploadsW | |
| return preSignedURL, zipFilePath, nil | ||
| } | ||
|
|
||
| func runContainerResolver(cmd *cobra.Command, directoryPath string) error { | ||
| func runContainerResolver(cmd *cobra.Command, directoryPath string, containerResolveLocally bool) error { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new parameter |
||
| containerImages, _ := cmd.Flags().GetString(commonParams.ContainerImagesFlag) | ||
| debug, _ := cmd.Flags().GetBool(commonParams.DebugFlag) | ||
| var containerImagesList []string | ||
|
|
@@ -1476,26 +1485,11 @@ func runContainerResolver(cmd *cobra.Command, directoryPath string) error { | |
| } | ||
| logger.PrintIfVerbose(fmt.Sprintf("User input container images identified: %v", strings.Join(containerImagesList, ", "))) | ||
| } | ||
| containerResolverERR := containerResolver.Resolve(directoryPath, directoryPath, containerImagesList, debug) | ||
| if containerResolverERR != nil { | ||
| return containerResolverERR | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func runScannerResolvers(cmd *cobra.Command, directoryPath, projectName string, containerScanTriggered bool, scaResolver, scaResolverParams string) error { | ||
| // Make sure scaResolver only runs in sca type of scans | ||
| if strings.Contains(actualScanTypes, commonParams.ScaType) { | ||
| dirPathErr := runScaResolver(directoryPath, scaResolver, scaResolverParams, projectName) | ||
| if dirPathErr != nil { | ||
| return errors.Wrapf(dirPathErr, "ScaResolver error") | ||
| } | ||
| } | ||
|
|
||
| if containerScanTriggered { | ||
| containerResolverError := runContainerResolver(cmd, directoryPath) | ||
| if containerResolverError != nil { | ||
| return containerResolverError | ||
| if containerResolveLocally || len(containerImagesList) > 0 { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The variable |
||
| containerResolverERR := containerResolver.Resolve(directoryPath, directoryPath, containerImagesList, debug) | ||
| if containerResolverERR != nil { | ||
| return containerResolverERR | ||
| } | ||
| } | ||
| return nil | ||
|
|
@@ -2743,9 +2737,13 @@ func validateCreateScanFlags(cmd *cobra.Command) error { | |
| } | ||
|
|
||
| func validateContainerImageFormat(containerImage string) error { | ||
| if strings.HasSuffix(containerImage, ".tar") { | ||
| return nil | ||
| } | ||
|
|
||
| imageParts := strings.Split(containerImage, ":") | ||
| if len(imageParts) != 2 || imageParts[0] == "" || imageParts[1] == "" { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The validation logic for the container image format only checks for the presence of a colon and non-empty parts before and after the colon. However, it does not validate the actual format of the image name and tag. Consider adding more robust validation to ensure the image name and tag conform to the expected patterns. |
||
| return errors.Errorf("Invalid value for --container-images flag. The value must be in the format <image-name>:<image-tag>") | ||
| return errors.Errorf("Invalid value for --container-images flag. The value must be in the format <image-name>:<image-tag> or <image-name>.tar") | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider validating the
--scan-idflag to ensure that it is not empty and has a proper format before executing the command.