mirror of
https://github.com/securego/gosec.git
synced 2025-11-23 22:15:04 +02:00
Add in the config file settings for exclude and include options
Co-authored-by: kaiili <kaii@openingsource.org>
This commit is contained in:
@@ -185,6 +185,14 @@ func loadConfig(configFile string) (gosec.Config, error) {
|
|||||||
if *flagAlternativeNoSec != "" {
|
if *flagAlternativeNoSec != "" {
|
||||||
config.SetGlobal(gosec.NoSecAlternative, *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
|
return config, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -348,7 +356,16 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Load enabled rule definitions
|
// 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 {
|
if len(ruleList.Rules) == 0 {
|
||||||
logger.Fatal("No rules are configured")
|
logger.Fatal("No rules are configured")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,10 @@ const (
|
|||||||
Audit GlobalOption = "audit"
|
Audit GlobalOption = "audit"
|
||||||
// NoSecAlternative global option alternative for #nosec directive
|
// NoSecAlternative global option alternative for #nosec directive
|
||||||
NoSecAlternative GlobalOption = "#nosec"
|
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.
|
// Config is used to provide configuration and customization to each of the rules.
|
||||||
|
|||||||
Reference in New Issue
Block a user