-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Integrated trivy in code base and in Dockerfile * changed to dockerfile in action.yml * changed entrypoint.sh for aws auth * feat: changed action.yml image to version 2.0.0 release * feat: changed to release 1.0.0 in action.yml
- Loading branch information
1 parent
2926b32
commit fae2c73
Showing
5 changed files
with
73 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,53 @@ | ||
package sdkr | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/clouddrove/smurf/configs" | ||
"github.com/clouddrove/smurf/internal/docker" | ||
"github.com/pterm/pterm" | ||
"github.com/spf13/cobra" | ||
"errors" | ||
"fmt" | ||
"github.com/clouddrove/smurf/configs" | ||
"github.com/clouddrove/smurf/internal/docker" | ||
"github.com/pterm/pterm" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// scanCmd provides functionality to scan a Docker image for known security issues. | ||
// It supports both direct command-line arguments and configuration file values for the image name, | ||
// and optionally allows saving the scan report to a specified SARIF file. | ||
var scanCmd = &cobra.Command{ | ||
Use: "scan [IMAGE_NAME[:TAG]]", | ||
Short: "Scan a Docker image for known vulnerabilities.", | ||
Args: cobra.MaximumNArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
var imageRef string | ||
|
||
if len(args) == 1 { | ||
imageRef = args[0] | ||
} else { | ||
data, err := configs.LoadConfig(configs.FileName) | ||
if err != nil { | ||
return fmt.Errorf("failed to load config: %w", err) | ||
} | ||
if data.Sdkr.ImageName == "" { | ||
return errors.New("image name (with optional tag) must be provided either as an argument or in the config") | ||
} | ||
imageRef = data.Sdkr.ImageName | ||
} | ||
|
||
pterm.Info.Printf("Scanning Docker image %q...\n", imageRef) | ||
err := docker.Scout(imageRef, configs.SarifFile) | ||
if err != nil { | ||
pterm.Error.Println("Scan failed:", err) | ||
return err | ||
} | ||
pterm.Success.Println("Scan completed successfully.") | ||
return nil | ||
}, | ||
Example: ` | ||
smurf sdkr scan my-image:latest | ||
smurf sdkr scan | ||
# In the second example, it will read IMAGE_NAME from the config file | ||
smurf sdkr scan my-image:latest --output scan.json | ||
# Saves the scan report to 'scan.json' in SARIF format | ||
Use: "scan [IMAGE_NAME[:TAG]]", | ||
Short: "Scan a Docker image for known vulnerabilities.", | ||
Args: cobra.MaximumNArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
var imageRef string | ||
if len(args) == 1 { | ||
imageRef = args[0] | ||
} else { | ||
data, err := configs.LoadConfig(configs.FileName) | ||
if err != nil { | ||
return fmt.Errorf("failed to load config: %w", err) | ||
} | ||
if data.Sdkr.ImageName == "" { | ||
return errors.New("image name (with optional tag) must be provided either as an argument or in the config") | ||
} | ||
imageRef = data.Sdkr.ImageName | ||
} | ||
|
||
pterm.Info.Printf("Scanning Docker image %q...\n", imageRef) | ||
err := docker.Trivy(imageRef) | ||
if err != nil { | ||
pterm.Error.Println("Scan failed:", err) | ||
return err | ||
} | ||
|
||
pterm.Success.Println("Scan completed successfully.") | ||
return nil | ||
}, | ||
Example: ` | ||
smurf sdkr scan my-image:latest | ||
smurf sdkr scan | ||
# In the second example, it will read IMAGE_NAME from the config file | ||
`, | ||
} | ||
|
||
func init() { | ||
scanCmd.Flags().StringVarP(&configs.SarifFile, "output", "o", "", "Output file for SARIF report") | ||
sdkrCmd.AddCommand(scanCmd) | ||
} | ||
sdkrCmd.AddCommand(scanCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters