cloudflare/pint
Publicmirrored from https://github.com/cloudflare/pintAvailable
internal/config/annotation.go
44lines · modecode
| 1 | package config |
| 2 | |
| 3 | import ( |
| 4 | "errors" |
| 5 | |
| 6 | "github.com/cloudflare/pint/internal/checks" |
| 7 | ) |
| 8 | |
| 9 | type AnnotationSettings struct { |
| 10 | Key string `hcl:",label" json:"key"` |
| 11 | Value string `hcl:"value,optional" json:"value,omitempty"` |
| 12 | Required bool `hcl:"required,optional" json:"required,omitempty"` |
| 13 | Severity string `hcl:"severity,optional" json:"severity,omitempty"` |
| 14 | } |
| 15 | |
| 16 | func (as AnnotationSettings) validate() error { |
| 17 | if as.Key == "" { |
| 18 | return errors.New("annotation key cannot be empty") |
| 19 | } |
| 20 | |
| 21 | if _, err := checks.NewTemplatedRegexp(as.Key); err != nil { |
| 22 | return err |
| 23 | } |
| 24 | |
| 25 | if _, err := checks.NewTemplatedRegexp(as.Value); err != nil { |
| 26 | return err |
| 27 | } |
| 28 | |
| 29 | if as.Severity != "" { |
| 30 | if _, err := checks.ParseSeverity(as.Severity); err != nil { |
| 31 | return err |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | return nil |
| 36 | } |
| 37 | |
| 38 | func (as AnnotationSettings) getSeverity(fallback checks.Severity) checks.Severity { |
| 39 | if as.Severity != "" { |
| 40 | sev, _ := checks.ParseSeverity(as.Severity) |
| 41 | return sev |
| 42 | } |
| 43 | return fallback |
| 44 | } |
| 45 | |