Skip to content
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

feat: ignore-on-exit flag to control the error code #162

Merged
merged 28 commits into from
Sep 28, 2023
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
9fdbd5a
Addded ignore-secret flag to all plugins (relevant sub-commands)
Aug 6, 2023
db979d9
Added ignore-on-exit flag to all sub commands
Aug 8, 2023
a17f2ae
Merge branch 'Checkmarx:master' into issue_155
nirmo Aug 8, 2023
b5860fb
changed IgnoreOnExitFlag var to ignoreOnExitFlag
Aug 8, 2023
06373e6
Merge branch 'issue_155' of https://github.com/nirmo/2ms into issue_155
Aug 8, 2023
6f4361a
issue 155 - add ignore-on-exit flag and change exit code logic
Aug 11, 2023
61ffa53
Merge branch 'Checkmarx:master' into issue_155
nirmo Aug 11, 2023
c5a866f
Merge branch 'Checkmarx:master' into issue_155
nirmo Aug 11, 2023
48ed7c0
Merge branch 'issue_155' of https://github.com/nirmo/2ms into issue_155
Aug 11, 2023
7b35e70
Issue 155 - minor changes
Aug 11, 2023
f74f216
Issue155 - added error channel and removed log fatal(s)
Aug 18, 2023
b399c8b
moved errorChan check after sleep wait
Aug 18, 2023
193afd6
merging changes from master
Aug 24, 2023
3b56fc8
sync with main
Sep 2, 2023
a3e131c
simplfying showError, removing comments and adding error channel check
Sep 2, 2023
dfcad26
modified ShowError and getFiles funcs
Sep 4, 2023
2eb264d
Merge pull request #2 from nirmo/master
nirmo Sep 4, 2023
40342fb
make the ignore-on-exit to be enum flag
Sep 27, 2023
417451f
refactor: reduce main size
Sep 27, 2023
7cc6483
move error decide to exit_handler
Sep 27, 2023
2785d3b
refactor: listen for errors
Sep 27, 2023
75a159a
one exit point
Sep 27, 2023
4d8a234
Merge remote-tracking branch 'origin/master' into pr/nirmo/162-1
Sep 27, 2023
060fde0
update README
Sep 27, 2023
2d328a7
Merge remote-tracking branch 'origin/master' into pr/nirmo/162-1
Sep 28, 2023
c880867
avoid using log.Fatal
Sep 28, 2023
1cbb777
remove comment
Sep 28, 2023
4a268a9
simplify the cmd.Error
Sep 28, 2023
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
33 changes: 14 additions & 19 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@ import (
"path/filepath"
"regexp"
"strings"
"sync"

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

"sync"

"github.com/checkmarx/2ms/plugins"
"github.com/checkmarx/2ms/reporting"
"github.com/checkmarx/2ms/secrets"

"github.com/rs/zerolog"
"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand Down Expand Up @@ -168,6 +165,10 @@ func validateFormat(stdout string, reportPath []string) error {
}

func preRun(cmd *cobra.Command, args []string) error {
if err := InitShouldIgnoreArg(ignoreOnExitVar); err != nil {
return err
}

if err := validateFormat(stdoutFormatVar, reportPathVar); err != nil {
return err
}
Expand All @@ -181,10 +182,6 @@ func preRun(cmd *cobra.Command, args []string) error {
return err
}

if err := InitShouldIgnoreArg(ignoreOnExitVar); err != nil {
return err
}

channels.WaitGroup.Add(1)
go func() {
defer channels.WaitGroup.Done()
Expand All @@ -210,7 +207,6 @@ func preRun(cmd *cobra.Command, args []string) error {

go func() {
for err := range channels.Errors {
//log.Fatal().Msg(err.Error())
fmt.Println(err.Error())
}
}()
Expand All @@ -221,16 +217,14 @@ func preRun(cmd *cobra.Command, args []string) error {
func postRun(cmd *cobra.Command, args []string) error {
channels.WaitGroup.Wait()

//if len(channels.Errors) != 0 {
// errorInChan := <-channels.Errors
// close(channels.Errors)
// return errorInChan
// }
if len(channels.Errors) != 0 {
errorInChan := <-channels.Errors
close(channels.Errors)
return errorInChan
}

cfg := config.LoadConfig("2ms", Version)

// -------------------------------------
// Show Report
if report.TotalItemsScanned > 0 {
if err := report.ShowReport(stdoutFormatVar, cfg); err != nil {
return err
Expand All @@ -249,7 +243,6 @@ func postRun(cmd *cobra.Command, args []string) error {
return nil
}

// InitShouldIgnoreArg initializes what kind of errors should be used on exit codes
func InitShouldIgnoreArg(arg string) error {
validArgs := []string{"none", "all", "results", "errors"}
for _, validArg := range validArgs {
Expand All @@ -261,7 +254,9 @@ func InitShouldIgnoreArg(arg string) error {
return fmt.Errorf("unknown argument for --ignore-on-exit: %s\nvalid arguments:\n %s", arg, strings.Join(validArgs, "\n "))
}

// ShowError returns true if should show error, otherwise returns false
func ShowError(kind string) bool {
return strings.EqualFold(ignoreOnExitVar, "none") || (!strings.EqualFold(ignoreOnExitVar, "all") && !strings.EqualFold(ignoreOnExitVar, kind))
if strings.EqualFold(ignoreOnExitVar, "none") || strings.EqualFold(ignoreOnExitVar, "results") {
return true
}
return false
}
baruchiro marked this conversation as resolved.
Show resolved Hide resolved