cloudflare/pint
Publicmirrored from https://github.com/cloudflare/pintAvailable
internal/config/aggregate.go
44lines · modecode
| 1 | package config |
| 2 | |
| 3 | import ( |
| 4 | "errors" |
| 5 | |
| 6 | "github.com/cloudflare/pint/internal/checks" |
| 7 | ) |
| 8 | |
| 9 | type AggregateSettings struct { |
| 10 | Name string `hcl:",label" json:"name"` |
| 11 | Keep []string `hcl:"keep,optional" json:"keep,omitempty"` |
| 12 | Strip []string `hcl:"strip,optional" json:"strip,omitempty"` |
| 13 | Severity string `hcl:"severity,optional" json:"severity,omitempty"` |
| 14 | } |
| 15 | |
| 16 | func (ag AggregateSettings) validate() error { |
| 17 | if ag.Name == "" { |
| 18 | return errors.New("empty name regex") |
| 19 | } |
| 20 | |
| 21 | if ag.Severity != "" { |
| 22 | if _, err := checks.ParseSeverity(ag.Severity); err != nil { |
| 23 | return err |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | if _, err := checks.NewTemplatedRegexp(ag.Name); err != nil { |
| 28 | return err |
| 29 | } |
| 30 | |
| 31 | if len(ag.Keep) == 0 && len(ag.Strip) == 0 { |
| 32 | return errors.New("must specify keep or strip list") |
| 33 | } |
| 34 | |
| 35 | return nil |
| 36 | } |
| 37 | |
| 38 | func (ag AggregateSettings) getSeverity(fallback checks.Severity) checks.Severity { |
| 39 | if ag.Severity != "" { |
| 40 | sev, _ := checks.ParseSeverity(ag.Severity) |
| 41 | return sev |
| 42 | } |
| 43 | return fallback |
| 44 | } |
| 45 | |