environments.go raw
1 package azure
2
3 // Copyright 2017 Microsoft Corporation
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16
17 import (
18 "encoding/json"
19 "fmt"
20 "os"
21 "strings"
22 )
23
24 const (
25 // EnvironmentFilepathName captures the name of the environment variable containing the path to the file
26 // to be used while populating the Azure Environment.
27 EnvironmentFilepathName = "AZURE_ENVIRONMENT_FILEPATH"
28
29 // NotAvailable is used for endpoints and resource IDs that are not available for a given cloud.
30 NotAvailable = "N/A"
31 )
32
33 var environments = map[string]Environment{
34 "AZURECHINACLOUD": ChinaCloud,
35 "AZUREGERMANCLOUD": GermanCloud,
36 "AZURECLOUD": PublicCloud,
37 "AZUREPUBLICCLOUD": PublicCloud,
38 "AZUREUSGOVERNMENT": USGovernmentCloud,
39 "AZUREUSGOVERNMENTCLOUD": USGovernmentCloud, //TODO: deprecate
40 }
41
42 // ResourceIdentifier contains a set of Azure resource IDs.
43 type ResourceIdentifier struct {
44 Graph string `json:"graph"`
45 KeyVault string `json:"keyVault"`
46 Datalake string `json:"datalake"`
47 Batch string `json:"batch"`
48 OperationalInsights string `json:"operationalInsights"`
49 OSSRDBMS string `json:"ossRDBMS"`
50 Storage string `json:"storage"`
51 Synapse string `json:"synapse"`
52 ServiceBus string `json:"serviceBus"`
53 SQLDatabase string `json:"sqlDatabase"`
54 CosmosDB string `json:"cosmosDB"`
55 ManagedHSM string `json:"managedHSM"`
56 MicrosoftGraph string `json:"microsoftGraph"`
57 }
58
59 // Environment represents a set of endpoints for each of Azure's Clouds.
60 type Environment struct {
61 Name string `json:"name"`
62 ManagementPortalURL string `json:"managementPortalURL"`
63 PublishSettingsURL string `json:"publishSettingsURL"`
64 ServiceManagementEndpoint string `json:"serviceManagementEndpoint"`
65 ResourceManagerEndpoint string `json:"resourceManagerEndpoint"`
66 ActiveDirectoryEndpoint string `json:"activeDirectoryEndpoint"`
67 GalleryEndpoint string `json:"galleryEndpoint"`
68 KeyVaultEndpoint string `json:"keyVaultEndpoint"`
69 ManagedHSMEndpoint string `json:"managedHSMEndpoint"`
70 GraphEndpoint string `json:"graphEndpoint"`
71 ServiceBusEndpoint string `json:"serviceBusEndpoint"`
72 BatchManagementEndpoint string `json:"batchManagementEndpoint"`
73 MicrosoftGraphEndpoint string `json:"microsoftGraphEndpoint"`
74 StorageEndpointSuffix string `json:"storageEndpointSuffix"`
75 CosmosDBDNSSuffix string `json:"cosmosDBDNSSuffix"`
76 MariaDBDNSSuffix string `json:"mariaDBDNSSuffix"`
77 MySQLDatabaseDNSSuffix string `json:"mySqlDatabaseDNSSuffix"`
78 PostgresqlDatabaseDNSSuffix string `json:"postgresqlDatabaseDNSSuffix"`
79 SQLDatabaseDNSSuffix string `json:"sqlDatabaseDNSSuffix"`
80 TrafficManagerDNSSuffix string `json:"trafficManagerDNSSuffix"`
81 KeyVaultDNSSuffix string `json:"keyVaultDNSSuffix"`
82 ManagedHSMDNSSuffix string `json:"managedHSMDNSSuffix"`
83 ServiceBusEndpointSuffix string `json:"serviceBusEndpointSuffix"`
84 ServiceManagementVMDNSSuffix string `json:"serviceManagementVMDNSSuffix"`
85 ResourceManagerVMDNSSuffix string `json:"resourceManagerVMDNSSuffix"`
86 ContainerRegistryDNSSuffix string `json:"containerRegistryDNSSuffix"`
87 TokenAudience string `json:"tokenAudience"`
88 APIManagementHostNameSuffix string `json:"apiManagementHostNameSuffix"`
89 SynapseEndpointSuffix string `json:"synapseEndpointSuffix"`
90 DatalakeSuffix string `json:"datalakeSuffix"`
91 ResourceIdentifiers ResourceIdentifier `json:"resourceIdentifiers"`
92 }
93
94 var (
95 // PublicCloud is the default public Azure cloud environment
96 PublicCloud = Environment{
97 Name: "AzurePublicCloud",
98 ManagementPortalURL: "https://manage.windowsazure.com/",
99 PublishSettingsURL: "https://manage.windowsazure.com/publishsettings/index",
100 ServiceManagementEndpoint: "https://management.core.windows.net/",
101 ResourceManagerEndpoint: "https://management.azure.com/",
102 ActiveDirectoryEndpoint: "https://login.microsoftonline.com/",
103 GalleryEndpoint: "https://gallery.azure.com/",
104 KeyVaultEndpoint: "https://vault.azure.net/",
105 ManagedHSMEndpoint: "https://managedhsm.azure.net/",
106 GraphEndpoint: "https://graph.windows.net/",
107 ServiceBusEndpoint: "https://servicebus.windows.net/",
108 BatchManagementEndpoint: "https://batch.core.windows.net/",
109 MicrosoftGraphEndpoint: "https://graph.microsoft.com/",
110 StorageEndpointSuffix: "core.windows.net",
111 CosmosDBDNSSuffix: "documents.azure.com",
112 MariaDBDNSSuffix: "mariadb.database.azure.com",
113 MySQLDatabaseDNSSuffix: "mysql.database.azure.com",
114 PostgresqlDatabaseDNSSuffix: "postgres.database.azure.com",
115 SQLDatabaseDNSSuffix: "database.windows.net",
116 TrafficManagerDNSSuffix: "trafficmanager.net",
117 KeyVaultDNSSuffix: "vault.azure.net",
118 ManagedHSMDNSSuffix: "managedhsm.azure.net",
119 ServiceBusEndpointSuffix: "servicebus.windows.net",
120 ServiceManagementVMDNSSuffix: "cloudapp.net",
121 ResourceManagerVMDNSSuffix: "cloudapp.azure.com",
122 ContainerRegistryDNSSuffix: "azurecr.io",
123 TokenAudience: "https://management.azure.com/",
124 APIManagementHostNameSuffix: "azure-api.net",
125 SynapseEndpointSuffix: "dev.azuresynapse.net",
126 DatalakeSuffix: "azuredatalakestore.net",
127 ResourceIdentifiers: ResourceIdentifier{
128 Graph: "https://graph.windows.net/",
129 KeyVault: "https://vault.azure.net",
130 Datalake: "https://datalake.azure.net/",
131 Batch: "https://batch.core.windows.net/",
132 OperationalInsights: "https://api.loganalytics.io",
133 OSSRDBMS: "https://ossrdbms-aad.database.windows.net",
134 Storage: "https://storage.azure.com/",
135 Synapse: "https://dev.azuresynapse.net",
136 ServiceBus: "https://servicebus.azure.net/",
137 SQLDatabase: "https://database.windows.net/",
138 CosmosDB: "https://cosmos.azure.com",
139 ManagedHSM: "https://managedhsm.azure.net",
140 MicrosoftGraph: "https://graph.microsoft.com/",
141 },
142 }
143
144 // USGovernmentCloud is the cloud environment for the US Government
145 USGovernmentCloud = Environment{
146 Name: "AzureUSGovernmentCloud",
147 ManagementPortalURL: "https://manage.windowsazure.us/",
148 PublishSettingsURL: "https://manage.windowsazure.us/publishsettings/index",
149 ServiceManagementEndpoint: "https://management.core.usgovcloudapi.net/",
150 ResourceManagerEndpoint: "https://management.usgovcloudapi.net/",
151 ActiveDirectoryEndpoint: "https://login.microsoftonline.us/",
152 GalleryEndpoint: "https://gallery.usgovcloudapi.net/",
153 KeyVaultEndpoint: "https://vault.usgovcloudapi.net/",
154 ManagedHSMEndpoint: NotAvailable,
155 GraphEndpoint: "https://graph.windows.net/",
156 ServiceBusEndpoint: "https://servicebus.usgovcloudapi.net/",
157 BatchManagementEndpoint: "https://batch.core.usgovcloudapi.net/",
158 MicrosoftGraphEndpoint: "https://graph.microsoft.us/",
159 StorageEndpointSuffix: "core.usgovcloudapi.net",
160 CosmosDBDNSSuffix: "documents.azure.us",
161 MariaDBDNSSuffix: "mariadb.database.usgovcloudapi.net",
162 MySQLDatabaseDNSSuffix: "mysql.database.usgovcloudapi.net",
163 PostgresqlDatabaseDNSSuffix: "postgres.database.usgovcloudapi.net",
164 SQLDatabaseDNSSuffix: "database.usgovcloudapi.net",
165 TrafficManagerDNSSuffix: "usgovtrafficmanager.net",
166 KeyVaultDNSSuffix: "vault.usgovcloudapi.net",
167 ManagedHSMDNSSuffix: NotAvailable,
168 ServiceBusEndpointSuffix: "servicebus.usgovcloudapi.net",
169 ServiceManagementVMDNSSuffix: "usgovcloudapp.net",
170 ResourceManagerVMDNSSuffix: "cloudapp.usgovcloudapi.net",
171 ContainerRegistryDNSSuffix: "azurecr.us",
172 TokenAudience: "https://management.usgovcloudapi.net/",
173 APIManagementHostNameSuffix: "azure-api.us",
174 SynapseEndpointSuffix: "dev.azuresynapse.usgovcloudapi.net",
175 DatalakeSuffix: NotAvailable,
176 ResourceIdentifiers: ResourceIdentifier{
177 Graph: "https://graph.windows.net/",
178 KeyVault: "https://vault.usgovcloudapi.net",
179 Datalake: NotAvailable,
180 Batch: "https://batch.core.usgovcloudapi.net/",
181 OperationalInsights: "https://api.loganalytics.us",
182 OSSRDBMS: "https://ossrdbms-aad.database.usgovcloudapi.net",
183 Storage: "https://storage.azure.com/",
184 Synapse: "https://dev.azuresynapse.usgovcloudapi.net",
185 ServiceBus: "https://servicebus.azure.net/",
186 SQLDatabase: "https://database.usgovcloudapi.net/",
187 CosmosDB: "https://cosmos.azure.com",
188 ManagedHSM: NotAvailable,
189 MicrosoftGraph: "https://graph.microsoft.us/",
190 },
191 }
192
193 // ChinaCloud is the cloud environment operated in China
194 ChinaCloud = Environment{
195 Name: "AzureChinaCloud",
196 ManagementPortalURL: "https://manage.chinacloudapi.com/",
197 PublishSettingsURL: "https://manage.chinacloudapi.com/publishsettings/index",
198 ServiceManagementEndpoint: "https://management.core.chinacloudapi.cn/",
199 ResourceManagerEndpoint: "https://management.chinacloudapi.cn/",
200 ActiveDirectoryEndpoint: "https://login.chinacloudapi.cn/",
201 GalleryEndpoint: "https://gallery.chinacloudapi.cn/",
202 KeyVaultEndpoint: "https://vault.azure.cn/",
203 ManagedHSMEndpoint: NotAvailable,
204 GraphEndpoint: "https://graph.chinacloudapi.cn/",
205 ServiceBusEndpoint: "https://servicebus.chinacloudapi.cn/",
206 BatchManagementEndpoint: "https://batch.chinacloudapi.cn/",
207 MicrosoftGraphEndpoint: "https://microsoftgraph.chinacloudapi.cn/",
208 StorageEndpointSuffix: "core.chinacloudapi.cn",
209 CosmosDBDNSSuffix: "documents.azure.cn",
210 MariaDBDNSSuffix: "mariadb.database.chinacloudapi.cn",
211 MySQLDatabaseDNSSuffix: "mysql.database.chinacloudapi.cn",
212 PostgresqlDatabaseDNSSuffix: "postgres.database.chinacloudapi.cn",
213 SQLDatabaseDNSSuffix: "database.chinacloudapi.cn",
214 TrafficManagerDNSSuffix: "trafficmanager.cn",
215 KeyVaultDNSSuffix: "vault.azure.cn",
216 ManagedHSMDNSSuffix: NotAvailable,
217 ServiceBusEndpointSuffix: "servicebus.chinacloudapi.cn",
218 ServiceManagementVMDNSSuffix: "chinacloudapp.cn",
219 ResourceManagerVMDNSSuffix: "cloudapp.chinacloudapi.cn",
220 ContainerRegistryDNSSuffix: "azurecr.cn",
221 TokenAudience: "https://management.chinacloudapi.cn/",
222 APIManagementHostNameSuffix: "azure-api.cn",
223 SynapseEndpointSuffix: "dev.azuresynapse.azure.cn",
224 DatalakeSuffix: NotAvailable,
225 ResourceIdentifiers: ResourceIdentifier{
226 Graph: "https://graph.chinacloudapi.cn/",
227 KeyVault: "https://vault.azure.cn",
228 Datalake: NotAvailable,
229 Batch: "https://batch.chinacloudapi.cn/",
230 OperationalInsights: NotAvailable,
231 OSSRDBMS: "https://ossrdbms-aad.database.chinacloudapi.cn",
232 Storage: "https://storage.azure.com/",
233 Synapse: "https://dev.azuresynapse.net",
234 ServiceBus: "https://servicebus.azure.net/",
235 SQLDatabase: "https://database.chinacloudapi.cn/",
236 CosmosDB: "https://cosmos.azure.com",
237 ManagedHSM: NotAvailable,
238 MicrosoftGraph: "https://microsoftgraph.chinacloudapi.cn",
239 },
240 }
241
242 // GermanCloud is the cloud environment operated in Germany
243 GermanCloud = Environment{
244 Name: "AzureGermanCloud",
245 ManagementPortalURL: "http://portal.microsoftazure.de/",
246 PublishSettingsURL: "https://manage.microsoftazure.de/publishsettings/index",
247 ServiceManagementEndpoint: "https://management.core.cloudapi.de/",
248 ResourceManagerEndpoint: "https://management.microsoftazure.de/",
249 ActiveDirectoryEndpoint: "https://login.microsoftonline.de/",
250 GalleryEndpoint: "https://gallery.cloudapi.de/",
251 KeyVaultEndpoint: "https://vault.microsoftazure.de/",
252 ManagedHSMEndpoint: NotAvailable,
253 GraphEndpoint: "https://graph.cloudapi.de/",
254 ServiceBusEndpoint: "https://servicebus.cloudapi.de/",
255 BatchManagementEndpoint: "https://batch.cloudapi.de/",
256 MicrosoftGraphEndpoint: NotAvailable,
257 StorageEndpointSuffix: "core.cloudapi.de",
258 CosmosDBDNSSuffix: "documents.microsoftazure.de",
259 MariaDBDNSSuffix: "mariadb.database.cloudapi.de",
260 MySQLDatabaseDNSSuffix: "mysql.database.cloudapi.de",
261 PostgresqlDatabaseDNSSuffix: "postgres.database.cloudapi.de",
262 SQLDatabaseDNSSuffix: "database.cloudapi.de",
263 TrafficManagerDNSSuffix: "azuretrafficmanager.de",
264 KeyVaultDNSSuffix: "vault.microsoftazure.de",
265 ManagedHSMDNSSuffix: NotAvailable,
266 ServiceBusEndpointSuffix: "servicebus.cloudapi.de",
267 ServiceManagementVMDNSSuffix: "azurecloudapp.de",
268 ResourceManagerVMDNSSuffix: "cloudapp.microsoftazure.de",
269 ContainerRegistryDNSSuffix: NotAvailable,
270 TokenAudience: "https://management.microsoftazure.de/",
271 APIManagementHostNameSuffix: NotAvailable,
272 SynapseEndpointSuffix: NotAvailable,
273 DatalakeSuffix: NotAvailable,
274 ResourceIdentifiers: ResourceIdentifier{
275 Graph: "https://graph.cloudapi.de/",
276 KeyVault: "https://vault.microsoftazure.de",
277 Datalake: NotAvailable,
278 Batch: "https://batch.cloudapi.de/",
279 OperationalInsights: NotAvailable,
280 OSSRDBMS: "https://ossrdbms-aad.database.cloudapi.de",
281 Storage: "https://storage.azure.com/",
282 Synapse: NotAvailable,
283 ServiceBus: "https://servicebus.azure.net/",
284 SQLDatabase: "https://database.cloudapi.de/",
285 CosmosDB: "https://cosmos.azure.com",
286 ManagedHSM: NotAvailable,
287 MicrosoftGraph: NotAvailable,
288 },
289 }
290 )
291
292 // EnvironmentFromName returns an Environment based on the common name specified.
293 func EnvironmentFromName(name string) (Environment, error) {
294 // IMPORTANT
295 // As per @radhikagupta5:
296 // This is technical debt, fundamentally here because Kubernetes is not currently accepting
297 // contributions to the providers. Once that is an option, the provider should be updated to
298 // directly call `EnvironmentFromFile`. Until then, we rely on dispatching Azure Stack environment creation
299 // from this method based on the name that is provided to us.
300 if strings.EqualFold(name, "AZURESTACKCLOUD") {
301 return EnvironmentFromFile(os.Getenv(EnvironmentFilepathName))
302 }
303
304 name = strings.ToUpper(name)
305 env, ok := environments[name]
306 if !ok {
307 return env, fmt.Errorf("autorest/azure: There is no cloud environment matching the name %q", name)
308 }
309
310 return env, nil
311 }
312
313 // EnvironmentFromFile loads an Environment from a configuration file available on disk.
314 // This function is particularly useful in the Hybrid Cloud model, where one must define their own
315 // endpoints.
316 func EnvironmentFromFile(location string) (unmarshaled Environment, err error) {
317 fileContents, err := os.ReadFile(location)
318 if err != nil {
319 return
320 }
321
322 err = json.Unmarshal(fileContents, &unmarshaled)
323
324 return
325 }
326
327 // SetEnvironment updates the environment map with the specified values.
328 func SetEnvironment(name string, env Environment) {
329 environments[strings.ToUpper(name)] = env
330 }
331