cloudflare/pint

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v0.28.2

Branches

Tags

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

Clone

HTTPS

Download ZIP

internal/config/annotation.go

44lines · modecode

1package config
2
3import (
4 "errors"
5
6 "github.com/cloudflare/pint/internal/checks"
7)
8
9type AnnotationSettings struct {
10 Key string `hcl:",label" json:"key"`
11 Value string `hcl:"value,optional" json:"value,omitempty"`
12 Required bool `hcl:"required,optional" json:"required,omitempty"`
13 Severity string `hcl:"severity,optional" json:"severity,omitempty"`
14}
15
16func (as AnnotationSettings) validate() error {
17 if as.Key == "" {
18 return errors.New("annotation key cannot be empty")
19 }
20
21 if _, err := checks.NewTemplatedRegexp(as.Key); err != nil {
22 return err
23 }
24
25 if _, err := checks.NewTemplatedRegexp(as.Value); err != nil {
26 return err
27 }
28
29 if as.Severity != "" {
30 if _, err := checks.ParseSeverity(as.Severity); err != nil {
31 return err
32 }
33 }
34
35 return nil
36}
37
38func (as AnnotationSettings) getSeverity(fallback checks.Severity) checks.Severity {
39 if as.Severity != "" {
40 sev, _ := checks.ParseSeverity(as.Severity)
41 return sev
42 }
43 return fallback
44}
45