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/annotation.go

45lines · modecode

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