forked from dihedron/terraform-provider-jenkins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
34 lines (30 loc) · 757 Bytes
/
util.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
package main
import (
"fmt"
"log"
"strings"
"github.com/hashicorp/terraform/helper/schema"
)
func validateAllowedStringsCaseInsensitive(ss []string) schema.SchemaValidateFunc {
log.Printf("[DEBUG] jenkins_pipeline::validate - length of %v: %d", ss, len(ss))
ll := make([]string, 0, len(ss))
for _, s := range ss {
ll = append(ll, strings.ToLower(s))
}
return func(v interface{}, k string) (ws []string, errors []error) {
value := strings.ToLower(v.(string))
existed := false
for _, s := range ll {
if strings.ToLower(s) == value {
existed = true
break
}
}
if !existed {
errors = append(errors, fmt.Errorf(
"%q must contain a valid string value should in array %#v, got %q",
k, ll, value))
}
return
}
}