azureEnvironment.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. // Copyright (c) Microsoft Corporation. All rights reserved.
  2. // Licensed under the MIT License. See License.txt in the project root for license information.
  3. export interface EnvironmentParameters {
  4. /**
  5. * The Environment name.
  6. */
  7. readonly name: string;
  8. /**
  9. * The management portal URL.
  10. */
  11. readonly portalUrl: string;
  12. /**
  13. * The management service endpoint.
  14. */
  15. readonly managementEndpointUrl: string;
  16. /**
  17. * The resource management endpoint.
  18. */
  19. readonly resourceManagerEndpointUrl: string;
  20. /**
  21. * The Active Directory login endpoint.
  22. */
  23. readonly activeDirectoryEndpointUrl: string;
  24. /**
  25. * The resource ID to obtain AD tokens for (token audience).
  26. */
  27. readonly activeDirectoryResourceId: string;
  28. /**
  29. * The publish settings file URL.
  30. */
  31. readonly publishingProfileUrl?: string;
  32. /**
  33. * The sql server management endpoint for mobile commands.
  34. */
  35. readonly sqlManagementEndpointUrl?: string;
  36. /**
  37. * The dns suffix for sql servers.
  38. */
  39. readonly sqlServerHostnameSuffix?: string;
  40. /**
  41. * The template gallery endpoint.
  42. */
  43. readonly galleryEndpointUrl?: string;
  44. /**
  45. * The Active Directory resource ID.
  46. */
  47. readonly activeDirectoryGraphResourceId?: string;
  48. /**
  49. * The batch resource ID.
  50. */
  51. readonly batchResourceId?: string;
  52. /**
  53. * The Active Directory api version.
  54. */
  55. readonly activeDirectoryGraphApiVersion?: string;
  56. /**
  57. * The endpoint suffix for storage accounts.
  58. */
  59. readonly storageEndpointSuffix?: string;
  60. /**
  61. * The keyvault service dns suffix.
  62. */
  63. readonly keyVaultDnsSuffix?: string;
  64. /**
  65. * The data lake store filesystem service dns suffix.
  66. */
  67. readonly azureDataLakeStoreFileSystemEndpointSuffix?: string;
  68. /**
  69. * The data lake analytics job and catalog service dns suffix.
  70. */
  71. readonly azureDataLakeAnalyticsCatalogAndJobEndpointSuffix?: string;
  72. /**
  73. * Determines whether the authentication endpoint should be validated with Azure AD. Default value is true.
  74. */
  75. readonly validateAuthority?: boolean;
  76. }
  77. export class Environment {
  78. /**
  79. * The Environment name.
  80. */
  81. readonly name: string;
  82. /**
  83. * The management portal URL.
  84. */
  85. readonly portalUrl: string;
  86. /**
  87. * The management service endpoint.
  88. */
  89. readonly managementEndpointUrl: string;
  90. /**
  91. * The resource management endpoint.
  92. */
  93. readonly resourceManagerEndpointUrl: string;
  94. /**
  95. * The Active Directory login endpoint.
  96. */
  97. readonly activeDirectoryEndpointUrl: string;
  98. /**
  99. * The resource ID to obtain AD tokens for (token audience).
  100. */
  101. readonly activeDirectoryResourceId: string;
  102. /**
  103. * The publish settings file URL.
  104. */
  105. readonly publishingProfileUrl?: string;
  106. /**
  107. * The sql server management endpoint for mobile commands.
  108. */
  109. readonly sqlManagementEndpointUrl?: string;
  110. /**
  111. * The dns suffix for sql servers.
  112. */
  113. readonly sqlServerHostnameSuffix?: string;
  114. /**
  115. * The template gallery endpoint.
  116. */
  117. readonly galleryEndpointUrl?: string;
  118. /**
  119. * The batch resource ID.
  120. */
  121. readonly batchResourceId?: string;
  122. /**
  123. * The Active Directory resource ID.
  124. */
  125. readonly activeDirectoryGraphResourceId?: string;
  126. /**
  127. * The Active Directory api version.
  128. */
  129. readonly activeDirectoryGraphApiVersion?: string;
  130. /**
  131. * The endpoint suffix for storage accounts.
  132. */
  133. readonly storageEndpointSuffix?: string;
  134. /**
  135. * The keyvault service dns suffix.
  136. */
  137. readonly keyVaultDnsSuffix?: string;
  138. /**
  139. * The data lake store filesystem service dns suffix.
  140. */
  141. readonly azureDataLakeStoreFileSystemEndpointSuffix?: string;
  142. /**
  143. * The data lake analytics job and catalog service dns suffix.
  144. */
  145. readonly azureDataLakeAnalyticsCatalogAndJobEndpointSuffix?: string;
  146. /**
  147. * Determines whether the authentication endpoint should be validated with Azure AD. Default value is true.
  148. */
  149. readonly validateAuthority: boolean = true;
  150. constructor(parameters: EnvironmentParameters) {
  151. if (!parameters || typeof parameters !== "object") {
  152. throw new Error("'parameters' is a required parameter and must be of type 'object'.");
  153. }
  154. // Validate required parameters
  155. const requiredParams = ["name", "portalUrl", "managementEndpointUrl", "resourceManagerEndpointUrl",
  156. "activeDirectoryEndpointUrl", "activeDirectoryResourceId"];
  157. requiredParams.forEach(function (param) {
  158. if (!(<any>parameters)[param] || typeof (<any>parameters)[param].valueOf() !== "string") {
  159. throw new Error(`Please provide "${param}" for the environment and it must be of type "string".`);
  160. }
  161. });
  162. this.name = parameters.name;
  163. this.portalUrl = parameters.portalUrl;
  164. this.managementEndpointUrl = parameters.managementEndpointUrl;
  165. this.resourceManagerEndpointUrl = parameters.resourceManagerEndpointUrl;
  166. this.activeDirectoryEndpointUrl = parameters.activeDirectoryEndpointUrl;
  167. this.activeDirectoryResourceId = parameters.activeDirectoryResourceId;
  168. if (this.activeDirectoryGraphApiVersion) {
  169. this.activeDirectoryGraphApiVersion = parameters.activeDirectoryGraphApiVersion;
  170. }
  171. if (this.activeDirectoryGraphResourceId) {
  172. this.activeDirectoryGraphResourceId = parameters.activeDirectoryGraphResourceId;
  173. }
  174. if (this.azureDataLakeAnalyticsCatalogAndJobEndpointSuffix) {
  175. this.azureDataLakeAnalyticsCatalogAndJobEndpointSuffix = parameters.azureDataLakeAnalyticsCatalogAndJobEndpointSuffix;
  176. }
  177. if (this.azureDataLakeStoreFileSystemEndpointSuffix) {
  178. this.azureDataLakeStoreFileSystemEndpointSuffix = parameters.azureDataLakeStoreFileSystemEndpointSuffix;
  179. }
  180. if (this.batchResourceId) {
  181. this.batchResourceId = parameters.batchResourceId;
  182. }
  183. if (this.galleryEndpointUrl) {
  184. this.galleryEndpointUrl = parameters.galleryEndpointUrl;
  185. }
  186. if (this.keyVaultDnsSuffix) {
  187. this.keyVaultDnsSuffix = parameters.keyVaultDnsSuffix;
  188. }
  189. if (this.publishingProfileUrl) {
  190. this.publishingProfileUrl = parameters.publishingProfileUrl;
  191. }
  192. if (this.sqlManagementEndpointUrl) {
  193. this.sqlManagementEndpointUrl = parameters.sqlManagementEndpointUrl;
  194. }
  195. if (this.sqlServerHostnameSuffix) {
  196. this.sqlServerHostnameSuffix = parameters.sqlServerHostnameSuffix;
  197. }
  198. if (this.storageEndpointSuffix) {
  199. this.storageEndpointSuffix = parameters.storageEndpointSuffix;
  200. }
  201. }
  202. static add(parameters: EnvironmentParameters): void {
  203. const envContainer: { [name: string]: Environment } = {};
  204. const envObj = new Environment(parameters);
  205. envContainer[parameters.name] = envObj;
  206. Object.assign(Environment, envContainer);
  207. return;
  208. }
  209. static get(name: string): Environment {
  210. if (!name) {
  211. throw new TypeError("name cannot be null or undefined and must be of type string.");
  212. }
  213. return (Environment as any)[name];
  214. }
  215. static readonly AzureCloud = {
  216. name: "AzureCloud",
  217. portalUrl: "https://portal.azure.com",
  218. publishingProfileUrl: "https://go.microsoft.com/fwlink/?LinkId=254432",
  219. managementEndpointUrl: "https://management.core.windows.net",
  220. resourceManagerEndpointUrl: "https://management.azure.com/",
  221. sqlManagementEndpointUrl: "https://management.core.windows.net:8443/",
  222. sqlServerHostnameSuffix: ".database.windows.net",
  223. galleryEndpointUrl: "https://gallery.azure.com/",
  224. activeDirectoryEndpointUrl: "https://login.microsoftonline.com/",
  225. activeDirectoryResourceId: "https://management.core.windows.net/",
  226. activeDirectoryGraphResourceId: "https://graph.windows.net/",
  227. batchResourceId: "https://batch.core.windows.net/",
  228. activeDirectoryGraphApiVersion: "2013-04-05",
  229. storageEndpointSuffix: ".core.windows.net",
  230. keyVaultDnsSuffix: ".vault.azure.net",
  231. azureDataLakeStoreFileSystemEndpointSuffix: "azuredatalakestore.net",
  232. azureDataLakeAnalyticsCatalogAndJobEndpointSuffix: "azuredatalakeanalytics.net",
  233. validateAuthority: true
  234. };
  235. static readonly ChinaCloud = {
  236. name: "AzureChinaCloud",
  237. portalUrl: "https://portal.azure.cn",
  238. publishingProfileUrl: "https://go.microsoft.com/fwlink/?LinkID=301774",
  239. managementEndpointUrl: "https://management.core.chinacloudapi.cn",
  240. resourceManagerEndpointUrl: "https://management.chinacloudapi.cn",
  241. sqlManagementEndpointUrl: "https://management.core.chinacloudapi.cn:8443/",
  242. sqlServerHostnameSuffix: ".database.chinacloudapi.cn",
  243. galleryEndpointUrl: "https://gallery.chinacloudapi.cn/",
  244. activeDirectoryEndpointUrl: "https://login.chinacloudapi.cn/",
  245. activeDirectoryResourceId: "https://management.core.chinacloudapi.cn/",
  246. activeDirectoryGraphResourceId: "https://graph.chinacloudapi.cn/",
  247. activeDirectoryGraphApiVersion: "2013-04-05",
  248. batchResourceId: "https://batch.chinacloudapi.cn/",
  249. storageEndpointSuffix: ".core.chinacloudapi.cn",
  250. keyVaultDnsSuffix: ".vault.azure.cn",
  251. // TODO: add dns suffixes for the china cloud for datalake store and datalake analytics once they are defined.
  252. azureDataLakeStoreFileSystemEndpointSuffix: "N/A",
  253. azureDataLakeAnalyticsCatalogAndJobEndpointSuffix: "N/A",
  254. validateAuthority: true
  255. };
  256. static readonly USGovernment = {
  257. name: "AzureUSGovernment",
  258. portalUrl: "https://portal.azure.us",
  259. publishingProfileUrl: "https://manage.windowsazure.us/publishsettings/index",
  260. managementEndpointUrl: "https://management.core.usgovcloudapi.net",
  261. resourceManagerEndpointUrl: "https://management.usgovcloudapi.net",
  262. sqlManagementEndpointUrl: "https://management.core.usgovcloudapi.net:8443/",
  263. sqlServerHostnameSuffix: ".database.usgovcloudapi.net",
  264. galleryEndpointUrl: "https://gallery.usgovcloudapi.net/",
  265. activeDirectoryEndpointUrl: "https://login.microsoftonline.us/",
  266. activeDirectoryResourceId: "https://management.core.usgovcloudapi.net/",
  267. activeDirectoryGraphResourceId: "https://graph.windows.net/",
  268. batchResourceId: "https://batch.core.usgovcloudapi.net/",
  269. activeDirectoryGraphApiVersion: "2013-04-05",
  270. storageEndpointSuffix: ".core.usgovcloudapi.net",
  271. keyVaultDnsSuffix: ".vault.usgovcloudapi.net",
  272. azureDataLakeStoreFileSystemEndpointSuffix: "N/A",
  273. azureDataLakeAnalyticsCatalogAndJobEndpointSuffix: "N/A",
  274. validateAuthority: true
  275. };
  276. static readonly GermanCloud = {
  277. name: "AzureGermanCloud",
  278. portalUrl: "https://portal.microsoftazure.de/",
  279. publishingProfileUrl: "https://manage.microsoftazure.de/publishsettings/index",
  280. managementEndpointUrl: "https://management.core.cloudapi.de",
  281. resourceManagerEndpointUrl: "https://management.microsoftazure.de",
  282. sqlManagementEndpointUrl: "https://management.core.cloudapi.de:8443/",
  283. sqlServerHostnameSuffix: ".database.cloudapi.de",
  284. galleryEndpointUrl: "https://gallery.cloudapi.de/",
  285. activeDirectoryEndpointUrl: "https://login.microsoftonline.de/",
  286. activeDirectoryResourceId: "https://management.core.cloudapi.de/",
  287. activeDirectoryGraphResourceId: "https://graph.cloudapi.de/",
  288. batchResourceId: "https://batch.microsoftazure.de/",
  289. activeDirectoryGraphApiVersion: "2013-04-05",
  290. storageEndpointSuffix: ".core.cloudapi.de",
  291. keyVaultDnsSuffix: ".vault.microsoftazure.de",
  292. azureDataLakeStoreFileSystemEndpointSuffix: "N/A",
  293. azureDataLakeAnalyticsCatalogAndJobEndpointSuffix: "N/A",
  294. validateAuthority: true
  295. };
  296. }