-
Notifications
You must be signed in to change notification settings - Fork 132
/
validators.go
142 lines (120 loc) · 2.84 KB
/
validators.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package fastly
import (
"fmt"
"strings"
gofastly "github.com/fastly/go-fastly/v2/fastly"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
)
func validateLoggingFormatVersion() schema.SchemaValidateFunc {
return validation.IntBetween(1, 2)
}
func validateLoggingMessageType() schema.SchemaValidateFunc {
return validation.StringInSlice([]string{
"classic",
"loggly",
"logplex",
"blank",
}, false)
}
func validateLoggingPlacement() schema.SchemaValidateFunc {
return validation.StringInSlice([]string{
"none",
"waf_debug",
}, false)
}
func validateLoggingServerSideEncryption() schema.SchemaValidateFunc {
return validation.StringInSlice([]string{
string(gofastly.S3ServerSideEncryptionAES),
string(gofastly.S3ServerSideEncryptionKMS),
}, false)
}
func validateDirectorQuorum() schema.SchemaValidateFunc {
return validation.IntBetween(0, 100)
}
func validateDirectorType() schema.SchemaValidateFunc {
return validation.IntInSlice([]int{1, 3, 4})
}
func validateConditionType() schema.SchemaValidateFunc {
return validation.StringInSlice([]string{
"REQUEST",
"RESPONSE",
"CACHE",
"PREFETCH",
}, false)
}
func validateHeaderAction() schema.SchemaValidateFunc {
return validation.StringInSlice([]string{
"set",
"append",
"delete",
"regex",
"regex_repeat",
}, false)
}
func validateHeaderType() schema.SchemaValidateFunc {
return validation.StringInSlice([]string{
"request",
"fetch",
"cache",
"response",
}, false)
}
func validateSnippetType() schema.SchemaValidateFunc {
return validation.StringInSlice([]string{
"init",
"recv",
"hash",
"hit",
"miss",
"pass",
"fetch",
"error",
"deliver",
"log",
"none",
}, false)
}
func validateRuleStatusType() schema.SchemaValidateFunc {
return validation.StringInSlice([]string{
"log",
"score",
"block",
}, false)
}
func validateDictionaryItems() schema.SchemaValidateFunc {
max := gofastly.MaximumDictionarySize
return func(i interface{}, k string) (s []string, es []error) {
v, ok := i.(map[string]interface{})
if !ok {
es = append(es, fmt.Errorf("expected type of %s to be a map[string]interface", k))
return
}
if len(v) > max {
es = append(es, fmt.Errorf("expected %s to be at most (%d), got %d", k, max, len(v)))
return
}
return
}
}
func validateUserRole() schema.SchemaValidateFunc {
return validation.StringInSlice(
[]string{
"user",
"billing",
"engineer",
"superuser",
},
false,
)
}
// TODO: Use SDK's validation.IsURLWithHTTPS() after we upgrade
func validateHTTPSURL() schema.SchemaValidateFunc {
return func(val interface{}, key string) (warns []string, errs []error) {
v := val.(string)
if !strings.HasPrefix(v, "https://") {
errs = append(errs, fmt.Errorf("%q must be https URL, got: %s", key, v))
}
return
}
}