Add in the config file settings for exclude and include options

Co-authored-by: kaiili <kaii@openingsource.org>
This commit is contained in:
kaiili 2021-12-21 06:43:50 +08:00 committed by GitHub
parent bf0dd2fdd3
commit 3038a30e3c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 1 deletions

View file

@ -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
}
@ -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")
}

View file

@ -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.