@@ -1187,6 +1187,10 @@ func addScaScan(cmd *cobra.Command, resubmitConfig []wrappers.Config, hasContain
11871187 return nil
11881188}
11891189
1190+ // addContainersScan creates the container security scan configuration with validation.
1191+ // Container-security scan-type related function.
1192+ // This function validates all --container-images inputs including tar files, image:tag formats,
1193+ // and various prefixed formats (docker:, podman:, file:, etc.) before creating the scan config.
11901194func addContainersScan (cmd * cobra.Command , resubmitConfig []wrappers.Config ) (map [string ]interface {}, error ) {
11911195 if ! scanTypeEnabled (commonParams .ContainersType ) {
11921196 return nil , nil
@@ -1255,6 +1259,8 @@ func addContainersScan(cmd *cobra.Command, resubmitConfig []wrappers.Config) (ma
12551259 return containerMapConfig , nil
12561260}
12571261
1262+ // initializeContainersConfigWithResubmitValues populates container config from previous scan settings.
1263+ // Container-security scan-type related function.
12581264func initializeContainersConfigWithResubmitValues (resubmitConfig []wrappers.Config , containerConfig * wrappers.ContainerConfig , containerResolveLocally , isGitScan bool ) {
12591265 for _ , config := range resubmitConfig {
12601266 if config .Type != commonParams .ContainersType {
@@ -2015,7 +2021,9 @@ func getUploadURLFromSource(cmd *cobra.Command, uploadsWrapper wrappers.UploadsW
20152021 return preSignedURL , zipFilePath , nil
20162022}
20172023
2018- // cleanCheckmarxContainersDirectory removes only the .checkmarx/containers directory after container scan completion
2024+ // cleanCheckmarxContainersDirectory removes only the .checkmarx/containers directory after container scan completion.
2025+ // Container-security scan-type related function.
2026+ // This function performs cleanup of temporary container scan artifacts.
20192027func cleanCheckmarxContainersDirectory (directoryPath string ) error {
20202028 containersPath := filepath .Join (directoryPath , ".checkmarx" , "containers" )
20212029 if _ , err := os .Stat (containersPath ); os .IsNotExist (err ) {
@@ -2033,6 +2041,9 @@ func cleanCheckmarxContainersDirectory(directoryPath string) error {
20332041 return nil
20342042}
20352043
2044+ // runContainerResolver executes the container resolver to analyze container images locally.
2045+ // Container-security scan-type related function.
2046+ // This function processes and normalizes container image inputs before passing them to the resolver.
20362047func runContainerResolver (cmd * cobra.Command , directoryPath , containerImageFlag string , containerResolveLocally bool ) error {
20372048 debug , _ := cmd .Flags ().GetBool (commonParams .DebugFlag )
20382049 var containerImagesList []string
@@ -2065,7 +2076,10 @@ func runContainerResolver(cmd *cobra.Command, directoryPath, containerImageFlag
20652076 return nil
20662077}
20672078
2068- // processContainerImagesForSyft processes container image references using syft's scheme extraction logic
2079+ // processContainerImagesForSyft processes container image references using syft's scheme extraction logic.
2080+ // Container-security scan-type related function.
2081+ // This function strips known prefixes (docker:, podman:, file:, etc.) from image references
2082+ // to match syft/stereoscope's expected input format.
20692083func processContainerImagesForSyft (images []string ) []string {
20702084 var processedImages []string
20712085
@@ -2094,7 +2108,9 @@ func processContainerImagesForSyft(images []string) []string {
20942108 return processedImages
20952109}
20962110
2097- // extractSchemeSource mimics stereoscope.ExtractSchemeSource behavior
2111+ // extractSchemeSource mimics stereoscope.ExtractSchemeSource behavior.
2112+ // Container-security scan-type related function.
2113+ // This function extracts and validates source prefixes from container image references.
20982114func extractSchemeSource (userInput string , sources []string ) (source , newInput string ) {
20992115 const SchemeSeparator = ":"
21002116 parts := strings .SplitN (userInput , SchemeSeparator , 2 )
@@ -3400,6 +3416,13 @@ func validateCreateScanFlags(cmd *cobra.Command) error {
34003416 return nil
34013417}
34023418
3419+ // validateContainerImageFormat validates container image references for the --container-images flag.
3420+ // Container-security scan-type related function.
3421+ // This function implements comprehensive validation logic for all supported container image formats:
3422+ // - Standard image:tag format
3423+ // - Tar files (.tar)
3424+ // - Prefixed formats (docker:, podman:, containerd:, registry:, docker-archive:, oci-archive:, oci-dir:, file:)
3425+ // It provides helpful error messages and hints for common user mistakes.
34033426func validateContainerImageFormat (containerImage string ) error {
34043427 // Define known sources (prefixes) for container image references
34053428 knownSources := []string {
@@ -3487,7 +3510,9 @@ func validateContainerImageFormat(containerImage string) error {
34873510 return errors .Errorf ("--container-images flag error: image does not have a tag" )
34883511}
34893512
3490- // Helper function to get the prefix from input
3513+ // getPrefixFromInput extracts the prefix from a container image reference.
3514+ // Container-security scan-type related function.
3515+ // Helper function to identify which known prefix is used in the input.
34913516func getPrefixFromInput (input string , prefixes []string ) string {
34923517 for _ , prefix := range prefixes {
34933518 if strings .HasPrefix (input , prefix ) {
@@ -3497,6 +3522,10 @@ func getPrefixFromInput(input string, prefixes []string) string {
34973522 return ""
34983523}
34993524
3525+ // validatePrefixedContainerImage validates container image references with specific prefixes.
3526+ // Container-security scan-type related function.
3527+ // This function handles prefix-specific validation for archive types (file:, docker-archive:, oci-archive:),
3528+ // daemon types (docker:, podman:, containerd:), registry types, and oci-dir types.
35003529func validatePrefixedContainerImage (containerImage , prefix string ) error {
35013530 // Remove the prefix to get the actual image reference
35023531 imageRef := strings .TrimPrefix (containerImage , prefix )
0 commit comments