cloudflare/pint

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v0.57.1

Branches

Tags

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

Clone

HTTPS

Download ZIP

internal/config/annotation.go

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