cloudflare/pint

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v0.77.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

internal/config/options/selector.go

44lines · modecode

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