diff options
author | Jake Champlin <jake@gnu.space> | 2017-06-09 17:54:32 +0000 |
---|---|---|
committer | Jake Champlin <jake@gnu.space> | 2017-06-09 17:54:32 +0000 |
commit | 9b12e4fe6f3c95986f1f3ec791636c58ca7e7583 (patch) | |
tree | 38f5f12bec0e488a12f0459a7356e6b7de7d8f84 /vendor/github.com/hashicorp/terraform/helper/validation | |
parent | cec3de8a3bcaffd21dedd1bf42da4b490cae7e16 (diff) | |
download | terraform-provider-statuscake-9b12e4fe6f3c95986f1f3ec791636c58ca7e7583.tar.gz terraform-provider-statuscake-9b12e4fe6f3c95986f1f3ec791636c58ca7e7583.tar.zst terraform-provider-statuscake-9b12e4fe6f3c95986f1f3ec791636c58ca7e7583.zip |
Transfer of provider code
Diffstat (limited to 'vendor/github.com/hashicorp/terraform/helper/validation')
-rw-r--r-- | vendor/github.com/hashicorp/terraform/helper/validation/validation.go | 108 |
1 files changed, 0 insertions, 108 deletions
diff --git a/vendor/github.com/hashicorp/terraform/helper/validation/validation.go b/vendor/github.com/hashicorp/terraform/helper/validation/validation.go deleted file mode 100644 index 7b894f5..0000000 --- a/vendor/github.com/hashicorp/terraform/helper/validation/validation.go +++ /dev/null | |||
@@ -1,108 +0,0 @@ | |||
1 | package validation | ||
2 | |||
3 | import ( | ||
4 | "fmt" | ||
5 | "net" | ||
6 | "strings" | ||
7 | |||
8 | "github.com/hashicorp/terraform/helper/schema" | ||
9 | "github.com/hashicorp/terraform/helper/structure" | ||
10 | ) | ||
11 | |||
12 | // IntBetween returns a SchemaValidateFunc which tests if the provided value | ||
13 | // is of type int and is between min and max (inclusive) | ||
14 | func IntBetween(min, max int) schema.SchemaValidateFunc { | ||
15 | return func(i interface{}, k string) (s []string, es []error) { | ||
16 | v, ok := i.(int) | ||
17 | if !ok { | ||
18 | es = append(es, fmt.Errorf("expected type of %s to be int", k)) | ||
19 | return | ||
20 | } | ||
21 | |||
22 | if v < min || v > max { | ||
23 | es = append(es, fmt.Errorf("expected %s to be in the range (%d - %d), got %d", k, min, max, v)) | ||
24 | return | ||
25 | } | ||
26 | |||
27 | return | ||
28 | } | ||
29 | } | ||
30 | |||
31 | // StringInSlice returns a SchemaValidateFunc which tests if the provided value | ||
32 | // is of type string and matches the value of an element in the valid slice | ||
33 | // will test with in lower case if ignoreCase is true | ||
34 | func StringInSlice(valid []string, ignoreCase bool) schema.SchemaValidateFunc { | ||
35 | return func(i interface{}, k string) (s []string, es []error) { | ||
36 | v, ok := i.(string) | ||
37 | if !ok { | ||
38 | es = append(es, fmt.Errorf("expected type of %s to be string", k)) | ||
39 | return | ||
40 | } | ||
41 | |||
42 | for _, str := range valid { | ||
43 | if v == str || (ignoreCase && strings.ToLower(v) == strings.ToLower(str)) { | ||
44 | return | ||
45 | } | ||
46 | } | ||
47 | |||
48 | es = append(es, fmt.Errorf("expected %s to be one of %v, got %s", k, valid, v)) | ||
49 | return | ||
50 | } | ||
51 | } | ||
52 | |||
53 | // StringLenBetween returns a SchemaValidateFunc which tests if the provided value | ||
54 | // is of type string and has length between min and max (inclusive) | ||
55 | func StringLenBetween(min, max int) schema.SchemaValidateFunc { | ||
56 | return func(i interface{}, k string) (s []string, es []error) { | ||
57 | v, ok := i.(string) | ||
58 | if !ok { | ||
59 | es = append(es, fmt.Errorf("expected type of %s to be string", k)) | ||
60 | return | ||
61 | } | ||
62 | if len(v) < min || len(v) > max { | ||
63 | es = append(es, fmt.Errorf("expected length of %s to be in the range (%d - %d), got %s", k, min, max, v)) | ||
64 | } | ||
65 | return | ||
66 | } | ||
67 | } | ||
68 | |||
69 | // CIDRNetwork returns a SchemaValidateFunc which tests if the provided value | ||
70 | // is of type string, is in valid CIDR network notation, and has significant bits between min and max (inclusive) | ||
71 | func CIDRNetwork(min, max int) schema.SchemaValidateFunc { | ||
72 | return func(i interface{}, k string) (s []string, es []error) { | ||
73 | v, ok := i.(string) | ||
74 | if !ok { | ||
75 | es = append(es, fmt.Errorf("expected type of %s to be string", k)) | ||
76 | return | ||
77 | } | ||
78 | |||
79 | _, ipnet, err := net.ParseCIDR(v) | ||
80 | if err != nil { | ||
81 | es = append(es, fmt.Errorf( | ||
82 | "expected %s to contain a valid CIDR, got: %s with err: %s", k, v, err)) | ||
83 | return | ||
84 | } | ||
85 | |||
86 | if ipnet == nil || v != ipnet.String() { | ||
87 | es = append(es, fmt.Errorf( | ||
88 | "expected %s to contain a valid network CIDR, expected %s, got %s", | ||
89 | k, ipnet, v)) | ||
90 | } | ||
91 | |||
92 | sigbits, _ := ipnet.Mask.Size() | ||
93 | if sigbits < min || sigbits > max { | ||
94 | es = append(es, fmt.Errorf( | ||
95 | "expected %q to contain a network CIDR with between %d and %d significant bits, got: %d", | ||
96 | k, min, max, sigbits)) | ||
97 | } | ||
98 | |||
99 | return | ||
100 | } | ||
101 | } | ||
102 | |||
103 | func ValidateJsonString(v interface{}, k string) (ws []string, errors []error) { | ||
104 | if _, err := structure.NormalizeJsonString(v); err != nil { | ||
105 | errors = append(errors, fmt.Errorf("%q contains an invalid JSON: %s", k, err)) | ||
106 | } | ||
107 | return | ||
108 | } | ||