Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ COPY . .
RUN GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -a -o /app/2ms .

# Runtime image
FROM cgr.dev/chainguard/git@sha256:2545cd570d26257e45c9d302cc459816ffc1e97de90d31e599782d56be7ab40e
FROM cgr.dev/chainguard/git@sha256:b0dbd0c3c6a0f44c0522663c3a7f9b47f8e62ed419c88c37199f61308f19829c

WORKDIR /app

COPY --chown=65532:65532 --from=builder /app/2ms /app/2ms
RUN chown -R 65532:65532 /app

USER 65532

COPY --from=builder /app/2ms /app/2ms

RUN git config --global --add safe.directory /repo

ENTRYPOINT [ "/app/2ms" ]
ENTRYPOINT [ "/app/2ms" ]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ The following table describes the global flags that can be used together with an
|--ignore-on-exit | | None | Defines which kind of non-zero exits code should be ignored. Options are: all, results, errors, none. For example, if 'results' is set, only engine errors will make 2ms exit code different from 0. |
|--ignore-result | strings | | Ignore specific result by ID |
|--ignore-rule | strings | | Ignore rules by name or tag. |
|--log-level | string | info | Type of log to return. Options are: trace, debug, info, warn, error, fatal |
|--log-level | string | info | Type of log to return. Options are: trace, debug, info, warn, error, fatal, none |
|--max-target-megabytes | int | | Files larger than than the specified threshold will be skipped. Omit or set to 0 to disable this check. |
|--regex | stringArray | | Custom regexes to apply to the scan. Must be valid Go regex. |
|--report-path | strings | | Path to generate report files. The output format will be determined by the file extension (.json, .yaml, .sarif) |
Expand Down
5 changes: 5 additions & 0 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,20 @@ import (
)

func initialize() {

configFilePath, err := rootCmd.Flags().GetString(configFileFlag)
if err != nil {
cobra.CheckErr(err)
}
cobra.CheckErr(utils.LoadConfig(vConfig, configFilePath))
cobra.CheckErr(utils.BindFlags(rootCmd, vConfig, envPrefix))

logLevelVar, _ = rootCmd.Flags().GetString(logLevelFlagName)

logLevel := zerolog.InfoLevel
switch strings.ToLower(logLevelVar) {
case "none":
logLevel = zerolog.Disabled
case "trace":
logLevel = zerolog.TraceLevel
case "debug":
Expand Down
2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func Execute() (int, error) {
cobra.OnInitialize(initialize)
rootCmd.PersistentFlags().StringVar(&configFilePath, configFileFlag, "", "config file path")
cobra.CheckErr(rootCmd.MarkPersistentFlagFilename(configFileFlag, "yaml", "yml", "json"))
rootCmd.PersistentFlags().StringVar(&logLevelVar, logLevelFlagName, "info", "log level (trace, debug, info, warn, error, fatal)")
rootCmd.PersistentFlags().StringVar(&logLevelVar, logLevelFlagName, "info", "log level (trace, debug, info, warn, error, fatal, none)")
rootCmd.PersistentFlags().StringSliceVar(&reportPathVar, reportPathFlagName, []string{}, "path to generate report files. The output format will be determined by the file extension (.json, .yaml, .sarif)")
rootCmd.PersistentFlags().StringVar(&stdoutFormatVar, stdoutFormatFlagName, "yaml", "stdout output format, available formats are: json, yaml, sarif")
rootCmd.PersistentFlags().StringArrayVar(&customRegexRuleVar, customRegexRuleFlagName, []string{}, "custom regexes to apply to the scan, must be valid Go regex")
Expand Down
6 changes: 6 additions & 0 deletions lib/reporting/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import (
"path/filepath"
"strings"

"github.com/checkmarx/2ms/lib/utils"

"github.com/checkmarx/2ms/lib/config"
"github.com/checkmarx/2ms/lib/secrets"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)

Expand Down Expand Up @@ -64,6 +67,9 @@ func (r *Report) GetOutput(format string, cfg *config.Config) (string, error) {
var output string
var err error

if zerolog.GlobalLevel() == utils.NoneLevel {
return "", nil
}
switch format {
case jsonFormat:
output, err = writeJson(r)
Expand Down
4 changes: 4 additions & 0 deletions lib/reporting/report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/checkmarx/2ms/lib/config"
"github.com/checkmarx/2ms/lib/secrets"
"github.com/rs/zerolog"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3"
)
Expand Down Expand Up @@ -229,6 +230,9 @@ func TestWriteReportInNonExistingDir(t *testing.T) {
}

func TestGetOutputSarif(t *testing.T) {

zerolog.SetGlobalLevel(zerolog.InfoLevel)

tests := []struct {
name string
arg Report
Expand Down
3 changes: 3 additions & 0 deletions lib/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ import (
"path/filepath"
"strings"

"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"
)

var NoneLevel = zerolog.Level(-1)

func LoadConfig(v *viper.Viper, configFilePath string) error {
if configFilePath == "" {
return nil
Expand Down
Loading