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