|
|
@@ -77,9 +77,10 @@ type Config struct {
|
|
|
// Extend is a struct that allows users to define how they want their
|
|
|
// configuration extended by other configuration files.
|
|
|
type Extend struct {
|
|
|
- Path string
|
|
|
- URL string
|
|
|
- UseDefault bool
|
|
|
+ Path string
|
|
|
+ URL string
|
|
|
+ UseDefault bool
|
|
|
+ DisabledRules []string
|
|
|
}
|
|
|
|
|
|
func (vc *ViperConfig) Translate() (Config, error) {
|
|
|
@@ -216,7 +217,7 @@ func (vc *ViperConfig) Translate() (Config, error) {
|
|
|
|
|
|
// Validate the rules after everything has been assembled (including extended configs).
|
|
|
if extendDepth == 0 {
|
|
|
- for _, rule := range rulesMap {
|
|
|
+ for _, rule := range c.Rules {
|
|
|
if err := rule.Validate(); err != nil {
|
|
|
return Config{}, err
|
|
|
}
|
|
|
@@ -284,7 +285,35 @@ func (c *Config) extendURL() {
|
|
|
}
|
|
|
|
|
|
func (c *Config) extend(extensionConfig Config) {
|
|
|
+ // Get config name for helpful log messages.
|
|
|
+ var configName string
|
|
|
+ if c.Extend.Path != "" {
|
|
|
+ configName = c.Extend.Path
|
|
|
+ } else {
|
|
|
+ configName = "default"
|
|
|
+ }
|
|
|
+ // Convert |Config.DisabledRules| into a map for ease of access.
|
|
|
+ disabledRuleIDs := map[string]struct{}{}
|
|
|
+ for _, id := range c.Extend.DisabledRules {
|
|
|
+ if _, ok := extensionConfig.Rules[id]; !ok {
|
|
|
+ log.Warn().
|
|
|
+ Str("rule-id", id).
|
|
|
+ Str("config", configName).
|
|
|
+ Msg("Disabled rule doesn't exist in extended config.")
|
|
|
+ }
|
|
|
+ disabledRuleIDs[id] = struct{}{}
|
|
|
+ }
|
|
|
+
|
|
|
for ruleID, baseRule := range extensionConfig.Rules {
|
|
|
+ // Skip the rule.
|
|
|
+ if _, ok := disabledRuleIDs[ruleID]; ok {
|
|
|
+ log.Debug().
|
|
|
+ Str("rule-id", ruleID).
|
|
|
+ Str("config", configName).
|
|
|
+ Msg("Ignoring rule from extended config.")
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
currentRule, ok := c.Rules[ruleID]
|
|
|
if !ok {
|
|
|
// Rule doesn't exist, add it to the config.
|