-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
iothub.go
47 lines (36 loc) · 1.31 KB
/
iothub.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
package validate
import (
"fmt"
"regexp"
)
func IoTHubName(v interface{}, k string) (warnings []string, errors []error) {
value := v.(string)
// Portal: The value must contain only alphanumeric characters or the following: -
if matched := regexp.MustCompile(`^[0-9a-zA-Z-]{1,}$`).Match([]byte(value)); !matched {
errors = append(errors, fmt.Errorf("%q may only contain alphanumeric characters and dashes", k))
}
return warnings, errors
}
func IoTHubConsumerGroupName(v interface{}, k string) (warnings []string, errors []error) {
value := v.(string)
// Portal: The value must contain only alphanumeric characters or the following: - . _
if matched := regexp.MustCompile(`^[0-9a-zA-Z-._]{1,}$`).Match([]byte(value)); !matched {
errors = append(errors, fmt.Errorf("%q may only contain alphanumeric characters and dashes, periods and underscores", k))
}
return warnings, errors
}
func IoTHubEndpointName(v interface{}, _ string) (warnings []string, errors []error) {
value := v.(string)
reservedNames := []string{
"events",
"operationsMonitoringEvents",
"fileNotifications",
"$default",
}
for _, name := range reservedNames {
if name == value {
errors = append(errors, fmt.Errorf("The reserved endpoint name %s could not be used as a name for a custom endpoint", name))
}
}
return warnings, errors
}