public SetSubscriptionAsDefault ( System.Guid id, string accountName ) : |
||
id | System.Guid | |
accountName | string | |
return |
private void SetupAzureEnvironmentFromEnvironmentVariables(AzureModule mode) { TestEnvironment currentEnvironment = null; if (mode == AzureModule.AzureResourceManager) { currentEnvironment = new CSMTestEnvironmentFactory().GetTestEnvironment(); } else { currentEnvironment = new RDFETestEnvironmentFactory().GetTestEnvironment(); } if (currentEnvironment.UserName == null) { currentEnvironment.UserName = "******"; } SetAuthenticationFactory(mode, currentEnvironment); AzureEnvironment environment = new AzureEnvironment { Name = testEnvironmentName }; Debug.Assert(currentEnvironment != null); environment.Endpoints[AzureEnvironment.Endpoint.ActiveDirectory] = currentEnvironment.Endpoints.AADAuthUri.AbsoluteUri; environment.Endpoints[AzureEnvironment.Endpoint.Gallery] = currentEnvironment.Endpoints.GalleryUri.AbsoluteUri; environment.Endpoints[AzureEnvironment.Endpoint.ServiceManagement] = currentEnvironment.BaseUri.AbsoluteUri; environment.Endpoints[AzureEnvironment.Endpoint.ResourceManager] = currentEnvironment.Endpoints.ResourceManagementUri.AbsoluteUri; environment.Endpoints[AzureEnvironment.Endpoint.Graph] = currentEnvironment.Endpoints.GraphUri.AbsoluteUri; environment.Endpoints[AzureEnvironment.Endpoint.AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix] = currentEnvironment.Endpoints.DataLakeAnalyticsJobAndCatalogServiceUri.OriginalString.Replace("https://", ""); // because it is just a sufix environment.Endpoints[AzureEnvironment.Endpoint.AzureDataLakeStoreFileSystemEndpointSuffix] = currentEnvironment.Endpoints.DataLakeStoreServiceUri.OriginalString.Replace("https://", ""); // because it is just a sufix if (!ProfileClient.Profile.Environments.ContainsKey(testEnvironmentName)) { ProfileClient.AddOrSetEnvironment(environment); } if (!AzureRmProfileProvider.Instance.Profile.Environments.ContainsKey(testEnvironmentName)) { AzureRmProfileProvider.Instance.Profile.Environments[testEnvironmentName] = environment; } if (currentEnvironment.SubscriptionId != null) { testSubscription = new AzureSubscription() { Id = new Guid(currentEnvironment.SubscriptionId), Name = testSubscriptionName, Environment = testEnvironmentName, Account = currentEnvironment.UserName, Properties = new Dictionary <AzureSubscription.Property, string> { { AzureSubscription.Property.Default, "True" }, { AzureSubscription.Property.StorageAccount, Environment.GetEnvironmentVariable("AZURE_STORAGE_ACCOUNT") }, } }; testAccount = new AzureAccount() { Id = currentEnvironment.UserName, Type = AzureAccount.AccountType.User, Properties = new Dictionary <AzureAccount.Property, string> { { AzureAccount.Property.Subscriptions, currentEnvironment.SubscriptionId }, } }; ProfileClient.Profile.Subscriptions[testSubscription.Id] = testSubscription; ProfileClient.Profile.Accounts[testAccount.Id] = testAccount; ProfileClient.SetSubscriptionAsDefault(testSubscription.Name, testSubscription.Account); var testTenant = new AzureTenant() { Id = Guid.NewGuid() }; if (!string.IsNullOrEmpty(currentEnvironment.Tenant)) { Guid tenant; if (Guid.TryParse(currentEnvironment.Tenant, out tenant)) { testTenant.Id = tenant; } } AzureRmProfileProvider.Instance.Profile.Context = new AzureContext(testSubscription, testAccount, environment, testTenant); } }
private void SetupAzureEnvironmentFromEnvironmentVariables(AzureModule mode) { TestEnvironment currentEnvironment = null; if (mode == AzureModule.AzureResourceManager) { #if !NETSTANDARD currentEnvironment = new CSMTestEnvironmentFactory().GetTestEnvironment(); #else currentEnvironment = TestEnvironmentFactory.GetTestEnvironment(); #endif } else { #if !NETSTANDARD currentEnvironment = new RDFETestEnvironmentFactory().GetTestEnvironment(); #else throw new NotSupportedException("RDFE environment is not supported in .Net Core"); #endif } if (currentEnvironment.UserName == null) { currentEnvironment.UserName = "******"; } SetAuthenticationFactory(mode, currentEnvironment); AzureEnvironment environment = new AzureEnvironment { Name = testEnvironmentName }; Debug.Assert(currentEnvironment != null); environment.ActiveDirectoryAuthority = currentEnvironment.Endpoints.AADAuthUri.AbsoluteUri; environment.GalleryUrl = currentEnvironment.Endpoints.GalleryUri.AbsoluteUri; environment.ServiceManagementUrl = currentEnvironment.BaseUri.AbsoluteUri; environment.ResourceManagerUrl = currentEnvironment.Endpoints.ResourceManagementUri.AbsoluteUri; environment.GraphUrl = currentEnvironment.Endpoints.GraphUri.AbsoluteUri; environment.AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix = currentEnvironment.Endpoints.DataLakeAnalyticsJobAndCatalogServiceUri.OriginalString.Replace("https://", ""); // because it is just a sufix environment.AzureDataLakeStoreFileSystemEndpointSuffix = currentEnvironment.Endpoints.DataLakeStoreServiceUri.OriginalString.Replace("https://", ""); // because it is just a sufix #if !NETSTANDARD if (!ProfileClient.Profile.EnvironmentTable.ContainsKey(testEnvironmentName)) { ProfileClient.AddOrSetEnvironment(environment); } #endif if (!AzureRmProfileProvider.Instance.GetProfile <AzureRmProfile>().EnvironmentTable.ContainsKey(testEnvironmentName)) { AzureRmProfileProvider.Instance.GetProfile <AzureRmProfile>().EnvironmentTable[testEnvironmentName] = environment; } if (currentEnvironment.SubscriptionId != null) { testSubscription = new AzureSubscription() { Id = currentEnvironment.SubscriptionId, Name = testSubscriptionName, }; testSubscription.SetEnvironment(testEnvironmentName); testSubscription.SetAccount(currentEnvironment.UserName); testSubscription.SetDefault(); testSubscription.SetStorageAccount(Environment.GetEnvironmentVariable("AZURE_STORAGE_ACCOUNT")); testAccount = new AzureAccount() { Id = currentEnvironment.UserName, Type = AzureAccount.AccountType.User, }; testAccount.SetSubscriptions(currentEnvironment.SubscriptionId); #if !NETSTANDARD ProfileClient.Profile.SubscriptionTable[testSubscription.GetId()] = testSubscription; ProfileClient.Profile.AccountTable[testAccount.Id] = testAccount; ProfileClient.SetSubscriptionAsDefault(testSubscription.Name, testSubscription.GetAccount()); #endif var testTenant = new AzureTenant() { Id = Guid.NewGuid().ToString() }; if (!string.IsNullOrEmpty(currentEnvironment.Tenant)) { Guid tenant; if (Guid.TryParse(currentEnvironment.Tenant, out tenant)) { testTenant.Id = currentEnvironment.Tenant; } } AzureRmProfileProvider.Instance.Profile.DefaultContext = new AzureContext(testSubscription, testAccount, environment, testTenant); } }