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