forked from Azure/azure-powershell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AzureEnvironment.cs
302 lines (270 loc) · 16 KB
/
AzureEnvironment.cs
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Threading;
namespace Microsoft.Azure.Commands.Common.Authentication.Abstractions
{
/// <summary>
/// A record of metadata necessary to manage assets in a specific azure cloud, including necessary endpoints,
/// location fo service-specific endpoints, and information for bootstrapping authentication
/// </summary>
[Serializable]
public class AzureEnvironment : IAzureEnvironment
{
static IDictionary<string, AzureEnvironment> InitializeBuiltInEnvironments()
{
var azureCloud = new AzureEnvironment
{
Name = EnvironmentName.AzureCloud,
PublishSettingsFileUrl = AzureEnvironmentConstants.AzurePublishSettingsFileUrl,
ServiceManagementUrl = AzureEnvironmentConstants.AzureServiceEndpoint,
ResourceManagerUrl = AzureEnvironmentConstants.AzureResourceManagerEndpoint,
ManagementPortalUrl = AzureEnvironmentConstants.AzureManagementPortalUrl,
ActiveDirectoryAuthority = AzureEnvironmentConstants.AzureActiveDirectoryEndpoint,
ActiveDirectoryServiceEndpointResourceId = AzureEnvironmentConstants.AzureServiceEndpoint,
StorageEndpointSuffix = AzureEnvironmentConstants.AzureStorageEndpointSuffix,
GalleryUrl = AzureEnvironmentConstants.GalleryEndpoint,
SqlDatabaseDnsSuffix = AzureEnvironmentConstants.AzureSqlDatabaseDnsSuffix,
GraphUrl = AzureEnvironmentConstants.AzureGraphEndpoint,
TrafficManagerDnsSuffix = AzureEnvironmentConstants.AzureTrafficManagerDnsSuffix,
AzureKeyVaultDnsSuffix = AzureEnvironmentConstants.AzureKeyVaultDnsSuffix,
AzureKeyVaultServiceEndpointResourceId = AzureEnvironmentConstants.AzureKeyVaultServiceEndpointResourceId,
AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix = AzureEnvironmentConstants.AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix,
AzureDataLakeStoreFileSystemEndpointSuffix = AzureEnvironmentConstants.AzureDataLakeStoreFileSystemEndpointSuffix,
GraphEndpointResourceId = AzureEnvironmentConstants.AzureGraphEndpoint,
DataLakeEndpointResourceId = AzureEnvironmentConstants.AzureDataLakeServiceEndpointResourceId,
BatchEndpointResourceId = AzureEnvironmentConstants.BatchEndpointResourceId,
AdTenant = "Common"
};
azureCloud.SetProperty(ExtendedEndpoint.OperationalInsightsEndpoint, AzureEnvironmentConstants.AzureOperationalInsightsEndpoint);
azureCloud.SetProperty(ExtendedEndpoint.OperationalInsightsEndpointResourceId, AzureEnvironmentConstants.AzureOperationalInsightsEndpointResourceId);
var azureChina = new AzureEnvironment
{
Name = EnvironmentName.AzureChinaCloud,
PublishSettingsFileUrl = AzureEnvironmentConstants.ChinaPublishSettingsFileUrl,
ServiceManagementUrl = AzureEnvironmentConstants.ChinaServiceEndpoint,
ResourceManagerUrl = AzureEnvironmentConstants.ChinaResourceManagerEndpoint,
ManagementPortalUrl = AzureEnvironmentConstants.ChinaManagementPortalUrl,
ActiveDirectoryAuthority = AzureEnvironmentConstants.ChinaActiveDirectoryEndpoint,
ActiveDirectoryServiceEndpointResourceId = AzureEnvironmentConstants.ChinaServiceEndpoint,
StorageEndpointSuffix = AzureEnvironmentConstants.ChinaStorageEndpointSuffix,
GalleryUrl = AzureEnvironmentConstants.GalleryEndpoint,
SqlDatabaseDnsSuffix = AzureEnvironmentConstants.ChinaSqlDatabaseDnsSuffix,
GraphUrl = AzureEnvironmentConstants.ChinaGraphEndpoint,
TrafficManagerDnsSuffix = AzureEnvironmentConstants.ChinaTrafficManagerDnsSuffix,
AzureKeyVaultDnsSuffix = AzureEnvironmentConstants.ChinaKeyVaultDnsSuffix,
AzureKeyVaultServiceEndpointResourceId = AzureEnvironmentConstants.ChinaKeyVaultServiceEndpointResourceId,
AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix = null,
AzureDataLakeStoreFileSystemEndpointSuffix = null,
DataLakeEndpointResourceId = null,
GraphEndpointResourceId = AzureEnvironmentConstants.ChinaGraphEndpoint,
BatchEndpointResourceId = AzureEnvironmentConstants.ChinaBatchEndpointResourceId,
AdTenant = "Common"
};
var azureUSGovernment = new AzureEnvironment
{
Name = EnvironmentName.AzureUSGovernment,
PublishSettingsFileUrl = AzureEnvironmentConstants.USGovernmentPublishSettingsFileUrl,
ServiceManagementUrl = AzureEnvironmentConstants.USGovernmentServiceEndpoint,
ResourceManagerUrl = AzureEnvironmentConstants.USGovernmentResourceManagerEndpoint,
ManagementPortalUrl = AzureEnvironmentConstants.USGovernmentManagementPortalUrl,
ActiveDirectoryAuthority = AzureEnvironmentConstants.USGovernmentActiveDirectoryEndpoint,
ActiveDirectoryServiceEndpointResourceId = AzureEnvironmentConstants.USGovernmentServiceEndpoint,
StorageEndpointSuffix = AzureEnvironmentConstants.USGovernmentStorageEndpointSuffix,
GalleryUrl = AzureEnvironmentConstants.GalleryEndpoint,
SqlDatabaseDnsSuffix = AzureEnvironmentConstants.USGovernmentSqlDatabaseDnsSuffix,
GraphUrl = AzureEnvironmentConstants.USGovernmentGraphEndpoint,
TrafficManagerDnsSuffix = AzureEnvironmentConstants.USGovernmentTrafficManagerDnsSuffix,
AzureKeyVaultDnsSuffix = AzureEnvironmentConstants.USGovernmentKeyVaultDnsSuffix,
AzureKeyVaultServiceEndpointResourceId = AzureEnvironmentConstants.USGovernmentKeyVaultServiceEndpointResourceId,
AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix = null,
AzureDataLakeStoreFileSystemEndpointSuffix = null,
DataLakeEndpointResourceId = null,
GraphEndpointResourceId = AzureEnvironmentConstants.USGovernmentGraphEndpoint,
BatchEndpointResourceId = AzureEnvironmentConstants.USGovernmentBatchEndpointResourceId,
AdTenant = "Common"
};
azureUSGovernment.SetProperty(ExtendedEndpoint.OperationalInsightsEndpoint, AzureEnvironmentConstants.USGovernmentOperationalInsightsEndpoint);
azureUSGovernment.SetProperty(ExtendedEndpoint.OperationalInsightsEndpointResourceId, AzureEnvironmentConstants.USGovernmentOperationalInsightsEndpointResourceId);
var azureGermany = new AzureEnvironment
{
Name = EnvironmentName.AzureGermanCloud,
PublishSettingsFileUrl = AzureEnvironmentConstants.GermanPublishSettingsFileUrl,
ServiceManagementUrl = AzureEnvironmentConstants.GermanServiceEndpoint,
ResourceManagerUrl = AzureEnvironmentConstants.GermanResourceManagerEndpoint,
ManagementPortalUrl = AzureEnvironmentConstants.GermanManagementPortalUrl,
ActiveDirectoryAuthority = AzureEnvironmentConstants.GermanActiveDirectoryEndpoint,
ActiveDirectoryServiceEndpointResourceId = AzureEnvironmentConstants.GermanServiceEndpoint,
StorageEndpointSuffix = AzureEnvironmentConstants.GermanStorageEndpointSuffix,
GalleryUrl = AzureEnvironmentConstants.GalleryEndpoint,
SqlDatabaseDnsSuffix = AzureEnvironmentConstants.GermanSqlDatabaseDnsSuffix,
GraphUrl = AzureEnvironmentConstants.GermanGraphEndpoint,
TrafficManagerDnsSuffix = AzureEnvironmentConstants.GermanTrafficManagerDnsSuffix,
AzureKeyVaultDnsSuffix = AzureEnvironmentConstants.GermanKeyVaultDnsSuffix,
AzureKeyVaultServiceEndpointResourceId = AzureEnvironmentConstants.GermanAzureKeyVaultServiceEndpointResourceId,
AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix = null,
AzureDataLakeStoreFileSystemEndpointSuffix = null,
DataLakeEndpointResourceId = null,
GraphEndpointResourceId = AzureEnvironmentConstants.GermanGraphEndpoint,
BatchEndpointResourceId = AzureEnvironmentConstants.GermanBatchEndpointResourceId,
AdTenant = "Common"
};
var result = new ConcurrentDictionary<string, AzureEnvironment>(StringComparer.InvariantCultureIgnoreCase);
result[EnvironmentName.AzureCloud] = azureCloud;
result[EnvironmentName.AzureChinaCloud] = azureChina;
result[EnvironmentName.AzureUSGovernment] = azureUSGovernment;
result[EnvironmentName.AzureGermanCloud] = azureGermany;
return result;
}
/// <summary>
/// Predefined Microsoft Azure environments
/// </summary>
public static IDictionary<string, AzureEnvironment> PublicEnvironments { get; } = InitializeBuiltInEnvironments();
public AzureEnvironment()
{
}
/// <summary>
/// Copy constructor
/// </summary>
/// <param name="other"></param>
public AzureEnvironment(IAzureEnvironment other)
{
this.CopyFrom(other);
}
/// <summary>
/// The name of the environment
/// </summary>
public string Name { get; set; }
/// <summary>
/// Whether the environment uses AAD (false) or ADFS (true) authentication
/// </summary>
public bool OnPremise { get; set; }
/// <summary>
/// The RDFE endpoint
/// </summary>
public string ServiceManagementUrl { get; set; }
/// <summary>
/// The Azure Resource Manager endpoint
/// </summary>
public string ResourceManagerUrl { get; set; }
/// <summary>
/// The location fo the AUX portal
/// </summary>
public string ManagementPortalUrl { get; set; }
/// <summary>
/// The location of the publishsettings fiel download web applciation
/// </summary>
public string PublishSettingsFileUrl { get; set; }
/// <summary>
/// The authentication endpoint
/// </summary>
public string ActiveDirectoryAuthority { get; set; }
/// <summary>
/// The uri of the template gallery
/// </summary>
public string GalleryUrl { get; set; }
/// <summary>
/// The URI of the Azure Active Directory Graph endpoint
/// </summary>
public string GraphUrl { get; set; }
/// <summary>
/// The token audience need for tokens that target RDFE or ARM endpoints
/// </summary>
public string ActiveDirectoryServiceEndpointResourceId { get; set; }
/// <summary>
/// The domain name suffix for storage services created in this environment
/// </summary>
public string StorageEndpointSuffix { get; set; }
/// <summary>
/// The domain name suffix for Sql server created in this environment
/// </summary>
public string SqlDatabaseDnsSuffix { get; set; }
/// <summary>
/// The domain name suffix for traffic manager endpoints created in this ebvironment
/// </summary>
public string TrafficManagerDnsSuffix { get; set; }
/// <summary>
/// The domain name suffix for Aure KeyVault vaults created in this environment
/// </summary>
public string AzureKeyVaultDnsSuffix { get; set; }
/// <summary>
/// The token audience required for communicating with the Azure KeyVault service in this environment
/// </summary>
public string AzureKeyVaultServiceEndpointResourceId { get; set; }
/// <summary>
/// The token audience required for communicating with the Azure Active Directory Graph service in this environment
/// </summary>
public string GraphEndpointResourceId { get; set; }
/// <summary>
/// The token audience required for communicating with the Azure Active Directory Data Lake service in this environment
/// </summary>
public string DataLakeEndpointResourceId { get; set; }
/// <summary>
/// The token audience required for communicating with the Batch service in this enviornment
/// </summary>
public string BatchEndpointResourceId { get; set; }
/// <summary>
/// The domain name suffix for Azure DataLake Catalog and Job services created in this environment
/// </summary>
public string AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix { get; set; }
/// <summary>
/// The domain name suffix for Azure DataLake file systems created in this environment
/// </summary>
public string AzureDataLakeStoreFileSystemEndpointSuffix { get; set; }
/// <summary>
/// The name of the default AdTenant in this environment
/// </summary>
public string AdTenant { get; set; }
/// <summary>
/// The set of Azure Version Profiles supported in this environment
/// </summary>
public IList<string> VersionProfiles { get; } = new List<string>();
/// <summary>
/// Additional environment-specific metadata
/// </summary>
public IDictionary<string, string> ExtendedProperties { get; } = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
/// <summary>
/// A set of string constants for each of the known environment values - allows users to specify a particular kind of endpoint by name
/// </summary>
public static class Endpoint
{
public const string AdTenant = "AdTenant",
ActiveDirectoryServiceEndpointResourceId = "ActiveDirectoryServiceEndpointResourceId",
GraphEndpointResourceId = "GraphEndpointResourceId",
AzureKeyVaultServiceEndpointResourceId = "AzureKeyVaultServiceEndpointResourceId",
AzureKeyVaultDnsSuffix = "AzureKeyVaultDnsSuffix",
TrafficManagerDnsSuffix = "TrafficManagerDnsSuffix",
SqlDatabaseDnsSuffix = "SqlDatabaseDnsSuffix",
StorageEndpointSuffix = "StorageEndpointSuffix",
Graph = "Graph",
Gallery = "Gallery",
ActiveDirectory = "ActiveDirectory",
ServiceManagement = "ServiceManagement",
ResourceManager = "ResourceManager",
PublishSettingsFileUrl = "PublishSettingsFileUrl",
ManagementPortalUrl = "ManagementPortalUrl",
AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix = "AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix",
AzureDataLakeStoreFileSystemEndpointSuffix = "AzureDataLakeStoreFileSystemEndpointSuffix",
DataLakeEndpointResourceId = "DataLakeEndpointResourceId",
BatchEndpointResourceId = "BatchEndpointResourceId";
}
public static class ExtendedEndpoint
{
public const string OperationalInsightsEndpointResourceId = "OperationalInsightsEndpointResourceId",
OperationalInsightsEndpoint = "OperationalInsightsEndpoint";
}
}
}