View Javadoc
1   // Copyright (c) Microsoft Corporation. All rights reserved.
2   // Licensed under the MIT License.
3   
4   package com.azure.core;
5   
6   import java.util.Arrays;
7   import java.util.HashMap;
8   import java.util.List;
9   import java.util.Map;
10  
11  /**
12   * An instance of this class describes an environment in Azure.
13   */
14  public final class AzureEnvironment {
15      /** the map of all endpoints. */
16      private final Map<String, String> endpoints;
17  
18      /**
19       * Initializes an instance of AzureEnvironment class.
20       *
21       * @param endpoints a map storing all the endpoint info
22       */
23      public AzureEnvironment(Map<String, String> endpoints) {
24          this.endpoints = endpoints;
25      }
26  
27      /**
28       * Provides the settings for authentication with Azure.
29       */
30      public static final AzureEnvironmentreEnvironment">AzureEnvironment AZURE = new AzureEnvironment(new HashMap<String, String>() {{
31              put("portalUrl", "http://go.microsoft.com/fwlink/?LinkId=254433");
32              put("publishingProfileUrl", "http://go.microsoft.com/fwlink/?LinkId=254432");
33              put("managementEndpointUrl", "https://management.core.windows.net/");
34              put("resourceManagerEndpointUrl", "https://management.azure.com/");
35              put("sqlManagementEndpointUrl", "https://management.core.windows.net:8443/");
36              put("sqlServerHostnameSuffix", ".database.windows.net");
37              put("galleryEndpointUrl", "https://gallery.azure.com/");
38              put("activeDirectoryEndpointUrl", "https://login.microsoftonline.com/");
39              put("activeDirectoryResourceId", "https://management.core.windows.net/");
40              put("activeDirectoryGraphResourceId", "https://graph.windows.net/");
41              put("dataLakeEndpointResourceId", "https://datalake.azure.net/");
42              put("activeDirectoryGraphApiVersion", "2013-04-05");
43              put("storageEndpointSuffix", ".core.windows.net");
44              put("keyVaultDnsSuffix", ".vault.azure.net");
45              put("azureDataLakeStoreFileSystemEndpointSuffix", "azuredatalakestore.net");
46              put("azureDataLakeAnalyticsCatalogAndJobEndpointSuffix", "azuredatalakeanalytics.net");
47              put("azureLogAnalyticsResourceId", "https://api.loganalytics.io/");
48              put("azureApplicationInsightsResourceId", "https://api.applicationinsights.io/");
49          }});
50  
51      /**
52       * Provides the settings for authentication with Azure China.
53       */
54      public static final AzureEnvironmentronment">AzureEnvironment AZURE_CHINA = new AzureEnvironment(new HashMap<String, String>() {{
55              put("portalUrl", "http://go.microsoft.com/fwlink/?LinkId=301902");
56              put("publishingProfileUrl", "http://go.microsoft.com/fwlink/?LinkID=301774");
57              put("managementEndpointUrl", "https://management.core.chinacloudapi.cn/");
58              put("resourceManagerEndpointUrl", "https://management.chinacloudapi.cn/");
59              put("sqlManagementEndpointUrl", "https://management.core.chinacloudapi.cn:8443/");
60              put("sqlServerHostnameSuffix", ".database.chinacloudapi.cn");
61              put("galleryEndpointUrl", "https://gallery.chinacloudapi.cn/");
62              put("activeDirectoryEndpointUrl", "https://login.chinacloudapi.cn/");
63              put("activeDirectoryResourceId", "https://management.core.chinacloudapi.cn/");
64              put("activeDirectoryGraphResourceId", "https://graph.chinacloudapi.cn/");
65              // TODO: add resource id for the china cloud for datalake once it is defined.
66              put("dataLakeEndpointResourceId", "N/A");
67              put("activeDirectoryGraphApiVersion", "2013-04-05");
68              put("storageEndpointSuffix", ".core.chinacloudapi.cn");
69              put("keyVaultDnsSuffix", ".vault.azure.cn");
70              // TODO: add dns suffixes for the china cloud for datalake store and datalake analytics once they are defined.
71              put("azureDataLakeStoreFileSystemEndpointSuffix", "N/A");
72              put("azureDataLakeAnalyticsCatalogAndJobEndpointSuffix", "N/A");
73              put("azureLogAnalyticsResourceId", "N/A");
74              put("azureApplicationInsightsResourceId", "N/A");
75          }});
76  
77      /**
78       * Provides the settings for authentication with Azure US Government.
79       */
80      public static final AzureEnvironment>AzureEnvironment AZURE_US_GOVERNMENT = new AzureEnvironment(new HashMap<String, String>() {{
81              put("portalUrl", "https://manage.windowsazure.us");
82              put("publishingProfileUrl", "https://manage.windowsazure.us/publishsettings/index");
83              put("managementEndpointUrl", "https://management.core.usgovcloudapi.net/");
84              put("resourceManagerEndpointUrl", "https://management.usgovcloudapi.net/");
85              put("sqlManagementEndpointUrl", "https://management.core.usgovcloudapi.net:8443/");
86              put("sqlServerHostnameSuffix", ".database.usgovcloudapi.net");
87              put("galleryEndpointUrl", "https://gallery.usgovcloudapi.net/");
88              put("activeDirectoryEndpointUrl", "https://login.microsoftonline.us/");
89              put("activeDirectoryResourceId", "https://management.core.usgovcloudapi.net/");
90              put("activeDirectoryGraphResourceId", "https://graph.windows.net/");
91              // TODO: add resource id for the US government for datalake once it is defined.
92              put("dataLakeEndpointResourceId", "N/A");
93              put("activeDirectoryGraphApiVersion", "2013-04-05");
94              put("storageEndpointSuffix", ".core.usgovcloudapi.net");
95              put("keyVaultDnsSuffix", ".vault.usgovcloudapi.net");
96              // TODO: add dns suffixes for the US government for datalake store and datalake analytics once they are defined.
97              put("azureDataLakeStoreFileSystemEndpointSuffix", "N/A");
98              put("azureDataLakeAnalyticsCatalogAndJobEndpointSuffix", "N/A");
99              put("azureLogAnalyticsResourceId", "https://api.loganalytics.us/");
100             put("azureApplicationInsightsResourceId", "N/A");
101         }});
102 
103     /**
104      * Provides the settings for authentication with Azure Germany.
105      */
106     public static final AzureEnvironmentnment">AzureEnvironment AZURE_GERMANY = new AzureEnvironment(new HashMap<String, String>() {{
107             put("portalUrl", "http://portal.microsoftazure.de/");
108             put("publishingProfileUrl", "https://manage.microsoftazure.de/publishsettings/index");
109             put("managementEndpointUrl", "https://management.core.cloudapi.de/");
110             put("resourceManagerEndpointUrl", "https://management.microsoftazure.de/");
111             put("sqlManagementEndpointUrl", "https://management.core.cloudapi.de:8443/");
112             put("sqlServerHostnameSuffix", ".database.cloudapi.de");
113             put("galleryEndpointUrl", "https://gallery.cloudapi.de/");
114             put("activeDirectoryEndpointUrl", "https://login.microsoftonline.de/");
115             put("activeDirectoryResourceId", "https://management.core.cloudapi.de/");
116             put("activeDirectoryGraphResourceId", "https://graph.cloudapi.de/");
117             // TODO: add resource id for the germany cloud for datalake once it is defined.
118             put("dataLakeEndpointResourceId", "N/A");
119             put("activeDirectoryGraphApiVersion", "2013-04-05");
120             put("storageEndpointSuffix", ".core.cloudapi.de");
121             put("keyVaultDnsSuffix", ".vault.microsoftazure.de");
122             // TODO: add dns suffixes for the germany cloud for datalake store and datalake analytics once they are defined.
123             put("azureDataLakeStoreFileSystemEndpointSuffix", "N/A");
124             put("azureDataLakeAnalyticsCatalogAndJobEndpointSuffix", "N/A");
125             put("azureLogAnalyticsResourceId", "N/A");
126             put("azureApplicationInsightsResourceId", "N/A");
127         }});
128 
129     /**
130      * @return the entirety of the endpoints associated with the current environment.
131      */
132     public Map<String, String> endpoints() {
133         return endpoints;
134     }
135 
136     /**
137      * @return the array of known environments to Azure SDK.
138      */
139     public static AzureEnvironment[] knownEnvironments() {
140         List<AzureEnvironment> environments = Arrays.asList(AZURE, AZURE_CHINA, AZURE_GERMANY, AZURE_US_GOVERNMENT);
141         return environments.toArray(new AzureEnvironment[environments.size()]);
142     }
143 
144     /**
145      * @return the management portal URL.
146      */
147     public String portal() {
148         return endpoints.get("portalUrl");
149     }
150 
151     /**
152      * @return the publish settings file URL.
153      */
154     public String publishingProfile() {
155         return endpoints.get("publishingProfileUrl");
156     }
157 
158     /**
159      * @return the management service endpoint.
160      */
161     public String managementEndpoint() {
162         return endpoints.get("managementEndpointUrl");
163     }
164 
165     /**
166      * @return the resource management endpoint.
167      */
168     public String resourceManagerEndpoint() {
169         return endpoints.get("resourceManagerEndpointUrl");
170     }
171 
172     /**
173      * @return the sql server management endpoint for mobile commands.
174      */
175     public String sqlManagementEndpoint() {
176         return endpoints.get("sqlManagementEndpointUrl");
177     }
178 
179     /**
180      * @return the dns suffix for sql servers.
181      */
182     public String sqlServerHostnameSuffix() {
183         return endpoints.get("sqlServerHostnameSuffix");
184     }
185 
186     /**
187      * @return the Active Directory login endpoint.
188      */
189     public String activeDirectoryEndpoint() {
190         return endpoints.get("activeDirectoryEndpointUrl").replaceAll("/$", "") + "/";
191     }
192 
193     /**
194      * @return The resource ID to obtain AD tokens for.
195      */
196     public String activeDirectoryResourceId() {
197         return endpoints.get("activeDirectoryResourceId");
198     }
199 
200     /**
201      * @return the template gallery endpoint.
202      */
203     public String galleryEndpoint() {
204         return endpoints.get("galleryEndpointUrl");
205     }
206 
207     /**
208      * @return the Active Directory resource ID.
209      */
210     public String graphEndpoint() {
211         return endpoints.get("activeDirectoryGraphResourceId");
212     }
213 
214     /**
215      * @return the Data Lake resource ID.
216      */
217     public String dataLakeEndpointResourceId() {
218         return endpoints.get("dataLakeEndpointResourceId");
219     }
220 
221     /**
222      * @return the Active Directory api version.
223      */
224     public String activeDirectoryGraphApiVersion() {
225         return endpoints.get("activeDirectoryGraphApiVersion");
226     }
227 
228     /**
229      * @return the endpoint suffix for storage accounts.
230      */
231     public String storageEndpointSuffix() {
232         return endpoints.get("storageEndpointSuffix");
233     }
234 
235     /**
236      * @return the keyvault service dns suffix.
237      */
238     public String keyVaultDnsSuffix() {
239         return endpoints.get("keyVaultDnsSuffix");
240     }
241 
242     /**
243      * @return the data lake store filesystem service dns suffix.
244      */
245     public String azureDataLakeStoreFileSystemEndpointSuffix() {
246         return endpoints.get("azureDataLakeStoreFileSystemEndpointSuffix");
247     }
248 
249     /**
250      * @return the data lake analytics job and catalog service dns suffix.
251      */
252     public String azureDataLakeAnalyticsCatalogAndJobEndpointSuffix() {
253         return endpoints.get("azureDataLakeAnalyticsCatalogAndJobEndpointSuffix");
254     }
255 
256     /**
257      * @return the log analytics endpoint.
258      */
259     public String logAnalyticsEndpoint() {
260         return endpoints.get("azureLogAnalyticsResourceId");
261     }
262 
263     /**
264      * @return the log analytics endpoint.
265      */
266     public String applicationInsightsEndpoint() {
267         return endpoints.get("azureApplicationInsightsResourceId");
268     }
269 
270 
271     /**
272      * The enum representing available endpoints in an environment.
273      */
274     public enum Endpoint {
275         /** Azure management endpoint. */
276         MANAGEMENT("managementEndpointUrl"),
277         /** Azure Resource Manager endpoint. */
278         RESOURCE_MANAGER("resourceManagerEndpointUrl"),
279         /** Azure SQL endpoint. */
280         SQL("sqlManagementEndpointUrl"),
281         /** Azure Gallery endpoint. */
282         GALLERY("galleryEndpointUrl"),
283         /** Active Directory authentication endpoint. */
284         ACTIVE_DIRECTORY("activeDirectoryEndpointUrl"),
285         /** Azure Active Directory Graph APIs endpoint. */
286         GRAPH("activeDirectoryGraphResourceId"),
287         /** Key Vault DNS suffix. */
288         KEYVAULT("keyVaultDnsSuffix"),
289         /** Azure Data Lake Store DNS suffix. */
290         DATA_LAKE_STORE("azureDataLakeStoreFileSystemEndpointSuffix"),
291         /** Azure Data Lake Analytics DNS suffix. */
292         DATA_LAKE_ANALYTICS("azureDataLakeAnalyticsCatalogAndJobEndpointSuffix"),
293         /** Azure Log Analytics endpoint. */
294         LOG_ANALYTICS("azureLogAnalyticsResourceId"),
295         /** Azure Application Insights. */
296         APPLICATION_INSIGHTS("azureApplicationInsightsResourceId");
297 
298         private String field;
299 
300         Endpoint(String value) {
301             this.field = value;
302         }
303 
304         /**
305          * @return a unique identifier for the endpoint in the environment
306          */
307         public String identifier() {
308             return field;
309         }
310 
311         @Override
312         public String toString() {
313             return field;
314         }
315     }
316 
317     /**
318      * Get the endpoint URL for the current environment.
319      *
320      * @param endpoint the endpoint
321      * @return the URL
322      */
323     public String url(Endpoint endpoint) {
324         return endpoints.get(endpoint.identifier());
325     }
326 }