cloudflare/pint

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v0.55.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

internal/config/annotation.go

50lines · 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 Token string `hcl:"token,optional" json:"token,omitempty"`
12 Value string `hcl:"value,optional" json:"value,omitempty"`
13 Severity string `hcl:"severity,optional" json:"severity,omitempty"`
14 Values []string `hcl:"values,optional" json:"values,omitempty"`
15 Required bool `hcl:"required,optional" json:"required,omitempty"`
16}
17
18func (as AnnotationSettings) validate() error {
19 if as.Key == "" {
20 return errors.New("annotation key cannot be empty")
21 }
22
23 if _, err := checks.NewTemplatedRegexp(as.Key); err != nil {
24 return err
25 }
26
27 if _, err := checks.NewRawTemplatedRegexp(as.Token); err != nil {
28 return err
29 }
30
31 if _, err := checks.NewTemplatedRegexp(as.Value); err != nil {
32 return err
33 }
34
35 if as.Severity != "" {
36 if _, err := checks.ParseSeverity(as.Severity); err != nil {
37 return err
38 }
39 }
40
41 return nil
42}
43
44func (as AnnotationSettings) getSeverity(fallback checks.Severity) checks.Severity {
45 if as.Severity != "" {
46 sev, _ := checks.ParseSeverity(as.Severity)
47 return sev
48 }
49 return fallback
50}
51