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
|
|
@ -66,31 +66,28 @@ type modSecurity struct {
|
|||
// Parse parses the annotations contained in the ingress
|
||||
// rule used to enable ModSecurity in a particular location
|
||||
func (a modSecurity) Parse(ing *extensions.Ingress) (interface{}, error) {
|
||||
var err error
|
||||
config := &Config{}
|
||||
|
||||
enableModSecurity, err := parser.GetBoolAnnotation("enable-modsecurity", ing)
|
||||
config.Enable, err = parser.GetBoolAnnotation("enable-modsecurity", ing)
|
||||
if err != nil {
|
||||
enableModSecurity = false
|
||||
config.Enable = false
|
||||
}
|
||||
|
||||
owaspRules, err := parser.GetBoolAnnotation("enable-owasp-core-rules", ing)
|
||||
config.OWASPRules, err = parser.GetBoolAnnotation("enable-owasp-core-rules", ing)
|
||||
if err != nil {
|
||||
owaspRules = false
|
||||
config.OWASPRules = false
|
||||
}
|
||||
|
||||
transactionID, err := parser.GetStringAnnotation("modsecurity-transaction-id", ing)
|
||||
config.TransactionID, err = parser.GetStringAnnotation("modsecurity-transaction-id", ing)
|
||||
if err != nil {
|
||||
transactionID = ""
|
||||
config.TransactionID = ""
|
||||
}
|
||||
|
||||
snippet, err := parser.GetStringAnnotation("modsecurity-snippet", ing)
|
||||
config.Snippet, err = parser.GetStringAnnotation("modsecurity-snippet", ing)
|
||||
if err != nil {
|
||||
snippet = ""
|
||||
config.Snippet = ""
|
||||
}
|
||||
|
||||
return Config{
|
||||
Enable: enableModSecurity,
|
||||
OWASPRules: owaspRules,
|
||||
TransactionID: transactionID,
|
||||
Snippet: snippet,
|
||||
}, nil
|
||||
return config, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,7 +70,8 @@ func TestParse(t *testing.T) {
|
|||
for _, testCase := range testCases {
|
||||
ing.SetAnnotations(testCase.annotations)
|
||||
result, _ := ap.Parse(ing)
|
||||
if result != testCase.expected {
|
||||
config := result.(*Config)
|
||||
if !config.Equal(&testCase.expected) {
|
||||
t.Errorf("expected %v but returned %v, annotations: %s", testCase.expected, result, testCase.annotations)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue