cloudflare/pint

Public

mirrored from https://github.com/cloudflare/pintAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v0.17.0

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

internal/config/aggregate.go

44lines · modecode

1package config
2
3import (
4 "errors"
5
6 "github.com/cloudflare/pint/internal/checks"
7)
8
9type 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
16func (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
38func (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