/
validation.go
29 lines (27 loc) · 933 Bytes
/
validation.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
package storage
import (
"fmt"
"regexp"
)
// Following the naming convention as laid out in the docs https://msdn.microsoft.com/library/azure/dn167011.aspx
func ValidateArmStorageShareName(v interface{}, k string) (warnings []string, errors []error) {
value := v.(string)
if !regexp.MustCompile(`^[0-9a-z-]+$`).MatchString(value) {
errors = append(errors, fmt.Errorf(
"only lowercase alphanumeric characters and hyphens allowed in %q: %q",
k, value))
}
if len(value) < 3 || len(value) > 63 {
errors = append(errors, fmt.Errorf(
"%q must be between 3 and 63 characters: %q", k, value))
}
if regexp.MustCompile(`^-`).MatchString(value) {
errors = append(errors, fmt.Errorf(
"%q cannot begin with a hyphen: %q", k, value))
}
if regexp.MustCompile(`[-]{2,}`).MatchString(value) {
errors = append(errors, fmt.Errorf(
"%q does not allow consecutive hyphens: %q", k, value))
}
return warnings, errors
}