cloudflare/pint

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v0.13.1

Branches

Tags

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

Clone

HTTPS

Download ZIP

internal/config/aggregate.go

45lines · modecode

1package config
2
3import (
4 "errors"
5 "regexp"
6
7 "github.com/cloudflare/pint/internal/checks"
8)
9
10type AggregateSettings struct {
11 Name string `hcl:",label" json:"name"`
12 Keep []string `hcl:"keep,optional" json:"keep,omitempty"`
13 Strip []string `hcl:"strip,optional" json:"strip,omitempty"`
14 Severity string `hcl:"severity,optional" json:"severity,omitempty"`
15}
16
17func (ag AggregateSettings) validate() error {
18 if ag.Name == "" {
19 return errors.New("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
32 if len(ag.Keep) == 0 && len(ag.Strip) == 0 {
33 return errors.New("must specify keep or strip list")
34 }
35
36 return nil
37}
38
39func (ag AggregateSettings) getSeverity(fallback checks.Severity) checks.Severity {
40 if ag.Severity != "" {
41 sev, _ := checks.ParseSeverity(ag.Severity)
42 return sev
43 }
44 return fallback
45}