-
Notifications
You must be signed in to change notification settings - Fork 351
/
ingressvalidator.go
52 lines (43 loc) · 1.44 KB
/
ingressvalidator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package definitions
import (
"fmt"
"github.com/zalando/skipper/eskip"
)
type IngressV1Validator struct{}
func (igv *IngressV1Validator) Validate(item *IngressV1Item) error {
var errs []error
errs = append(errs, igv.validateFilterAnnotation(item.Metadata.Annotations))
errs = append(errs, igv.validatePredicateAnnotation(item.Metadata.Annotations))
errs = append(errs, igv.validateRoutesAnnotation(item.Metadata.Annotations))
return errorsJoin(errs...)
}
func (igv *IngressV1Validator) validateFilterAnnotation(annotations map[string]string) error {
if filters, ok := annotations[IngressFilterAnnotation]; ok {
_, err := eskip.ParseFilters(filters)
if err != nil {
err = fmt.Errorf("invalid \"%s\" annotation: %w", IngressFilterAnnotation, err)
}
return err
}
return nil
}
func (igv *IngressV1Validator) validatePredicateAnnotation(annotations map[string]string) error {
if predicates, ok := annotations[IngressPredicateAnnotation]; ok {
_, err := eskip.ParsePredicates(predicates)
if err != nil {
err = fmt.Errorf("invalid \"%s\" annotation: %w", IngressPredicateAnnotation, err)
}
return err
}
return nil
}
func (igv *IngressV1Validator) validateRoutesAnnotation(annotations map[string]string) error {
if routes, ok := annotations[IngressRoutesAnnotation]; ok {
_, err := eskip.Parse(routes)
if err != nil {
err = fmt.Errorf("invalid \"%s\" annotation: %w", IngressRoutesAnnotation, err)
}
return err
}
return nil
}