Skip to content

Commit

Permalink
Add in the config file settings for exclude and include options
Browse files Browse the repository at this point in the history
Co-authored-by: kaiili <kaii@openingsource.org>
  • Loading branch information
kaiili and justpurekl committed Dec 20, 2021
1 parent bf0dd2f commit 3038a30
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
19 changes: 18 additions & 1 deletion cmd/gosec/main.go
Expand Up @@ -185,6 +185,14 @@ func loadConfig(configFile string) (gosec.Config, error) {
if *flagAlternativeNoSec != "" {
config.SetGlobal(gosec.NoSecAlternative, *flagAlternativeNoSec)
}
// set global option IncludeRules ,when flag set or global option IncludeRules is nil
if v, _ := config.GetGlobal(gosec.IncludeRules); *flagRulesInclude != "" || v == "" {
config.SetGlobal(gosec.IncludeRules, *flagRulesInclude)
}
// set global option ExcludeRules ,when flag set or global option IncludeRules is nil
if v, _ := config.GetGlobal(gosec.ExcludeRules); flagRulesExclude.String() != "" || v == "" {
config.SetGlobal(gosec.ExcludeRules, flagRulesExclude.String())
}
return config, nil
}

Expand Down Expand Up @@ -348,7 +356,16 @@ func main() {
}

// Load enabled rule definitions
ruleList := loadRules(*flagRulesInclude, flagRulesExclude.String())
excludeRules, err := config.GetGlobal(gosec.ExcludeRules)
if err != nil {
logger.Fatal(err)
}
includeRules, err := config.GetGlobal(gosec.IncludeRules)
if err != nil {
logger.Fatal(err)
}
// get a bug
ruleList := loadRules(includeRules, excludeRules)
if len(ruleList.Rules) == 0 {
logger.Fatal("No rules are configured")
}
Expand Down
4 changes: 4 additions & 0 deletions config.go
Expand Up @@ -26,6 +26,10 @@ const (
Audit GlobalOption = "audit"
// NoSecAlternative global option alternative for #nosec directive
NoSecAlternative GlobalOption = "#nosec"
// ExcludeRules global option for some rules should not be load
ExcludeRules GlobalOption = "exclude"
// IncludeRules global option for should be load
IncludeRules GlobalOption = "include"
)

// Config is used to provide configuration and customization to each of the rules.
Expand Down

0 comments on commit 3038a30

Please sign in to comment.