Improve parsing of annotations and use of Ingress wrapper
This commit is contained in:
parent
ccd7b890fd
commit
67808c0ed8
13 changed files with 278 additions and 334 deletions
|
|
@ -86,43 +86,38 @@ func NewParser(r resolver.Resolver) parser.IngressAnnotation {
|
|||
// used to indicate if the location/s contains a fragment of
|
||||
// configuration to be included inside the paths of the rules
|
||||
func (a luarestywaf) Parse(ing *extensions.Ingress) (interface{}, error) {
|
||||
var err error
|
||||
config := &Config{}
|
||||
|
||||
mode, err := parser.GetStringAnnotation("lua-resty-waf", ing)
|
||||
if err != nil {
|
||||
return &Config{}, err
|
||||
}
|
||||
|
||||
mode = strings.ToUpper(mode)
|
||||
if _, ok := luaRestyWAFModes[mode]; !ok {
|
||||
config.Mode = strings.ToUpper(mode)
|
||||
if _, ok := luaRestyWAFModes[config.Mode]; !ok {
|
||||
return &Config{}, errors.NewInvalidAnnotationContent("lua-resty-waf", mode)
|
||||
}
|
||||
|
||||
debug, _ := parser.GetBoolAnnotation("lua-resty-waf-debug", ing)
|
||||
config.Debug, _ = parser.GetBoolAnnotation("lua-resty-waf-debug", ing)
|
||||
|
||||
ignoredRuleSetsStr, _ := parser.GetStringAnnotation("lua-resty-waf-ignore-rulesets", ing)
|
||||
ignoredRuleSets := strings.FieldsFunc(ignoredRuleSetsStr, func(c rune) bool {
|
||||
config.IgnoredRuleSets = strings.FieldsFunc(ignoredRuleSetsStr, func(c rune) bool {
|
||||
strC := string(c)
|
||||
return strC == "," || strC == " "
|
||||
})
|
||||
|
||||
// TODO(elvinefendi) maybe validate the ruleset string here
|
||||
extraRulesetString, _ := parser.GetStringAnnotation("lua-resty-waf-extra-rules", ing)
|
||||
config.ExtraRulesetString, _ = parser.GetStringAnnotation("lua-resty-waf-extra-rules", ing)
|
||||
|
||||
scoreThreshold, _ := parser.GetIntAnnotation("lua-resty-waf-score-threshold", ing)
|
||||
config.ScoreThreshold, _ = parser.GetIntAnnotation("lua-resty-waf-score-threshold", ing)
|
||||
|
||||
allowUnknownContentTypes, _ := parser.GetBoolAnnotation("lua-resty-waf-allow-unknown-content-types", ing)
|
||||
config.AllowUnknownContentTypes, _ = parser.GetBoolAnnotation("lua-resty-waf-allow-unknown-content-types", ing)
|
||||
|
||||
processMultipartBody, err := parser.GetBoolAnnotation("lua-resty-waf-process-multipart-body", ing)
|
||||
config.ProcessMultipartBody, err = parser.GetBoolAnnotation("lua-resty-waf-process-multipart-body", ing)
|
||||
if err != nil {
|
||||
processMultipartBody = true
|
||||
config.ProcessMultipartBody = true
|
||||
}
|
||||
|
||||
return &Config{
|
||||
Mode: mode,
|
||||
Debug: debug,
|
||||
IgnoredRuleSets: ignoredRuleSets,
|
||||
ExtraRulesetString: extraRulesetString,
|
||||
ScoreThreshold: scoreThreshold,
|
||||
AllowUnknownContentTypes: allowUnknownContentTypes,
|
||||
ProcessMultipartBody: processMultipartBody,
|
||||
}, nil
|
||||
return config, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue