This repository has been archived by the owner on Jul 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 100
/
locations.go
79 lines (73 loc) · 1.59 KB
/
locations.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
package azure
import (
"fmt"
"github.com/Azure/open-service-broker-azure/pkg/service"
)
var azurePublicCloudLocations = []string{
"australiaeast",
"australiasoutheast",
"brazilsouth",
"canadacentral",
"canadaeast",
"centralindia",
"centralus",
"eastasia",
"eastus",
"eastus2",
"japaneast",
"japanwest",
"koreacentral",
"koreasouth",
"northcentralus",
"northeurope",
"southcentralus",
"southeastasia",
"southindia",
"uksouth",
"ukwest",
"westcentralus",
"westeurope",
"westindia",
"westus",
"westus2",
}
var azureChinaCloudLocations = []string{
"chinanorth2",
"chinanorth",
"chinaeast2",
"chinaeast",
}
// IsValidLocation returns a bool indicating whether the provided location is a
// valid one
func IsValidLocation(location string) bool {
environmentName := GetEnvironmentName()
var locations []string
switch environmentName {
case "AzureChinaCloud":
locations = azureChinaCloudLocations
case "AzurePublicCloud":
locations = azurePublicCloudLocations
// We shouldn't run into default case, but instead
// of raising a panic, we use public cloud locations
// and the error can be reported when provisioning the resource.
default:
locations = azurePublicCloudLocations
}
for _, l := range locations {
if location == l {
return true
}
}
return false
}
// LocationValidator is a custom schema validator that validates a specified
// location is a real Azure region.
func LocationValidator(context, val string) error {
if !IsValidLocation(val) {
return service.NewValidationError(
context,
fmt.Sprintf(`invalid location: "%s"`, val),
)
}
return nil
}