// Gets the customer's Azure account and subscription information private static AzureProfile GetAzureProfile() { AzureProfile profile = new AzureProfile(); ProfileClient profileClient = new ProfileClient(profile); AzureAccount azureAccount = new AzureAccount() {Type = AzureAccount.AccountType.User}; // Prompts the user for their credentials and retrieves their account/subscription info profileClient.AddAccountAndLoadSubscriptions(azureAccount, profile.Environments[EnvironmentName.AzureCloud], null); // By default, the first subscription is chosen if (profileClient.Profile.Subscriptions.Count > 1) { SelectSubscription(profileClient.Profile); } return profileClient.Profile; }
public void AddAzureAccountIsCaseInsensitive() { SetMocks(new[] { rdfeSubscription1, guestRdfeSubscription }.ToList(), new List<Microsoft.Azure.Subscriptions.Csm.Models.Subscription>(), new[] { commonTenant, guestTenant }.ToList(), (userAccount, environment, tenant) => { var token = new MockAccessToken { UserId = tenant == commonTenant.TenantId ? userAccount.Id : "USERA", AccessToken = "def", LoginType = LoginType.OrgId }; userAccount.Id = token.UserId; return token; }); MemoryDataStore dataStore = new MemoryDataStore(); dataStore.VirtualStore[oldProfileDataPath] = oldProfileData; AzureSession.DataStore = dataStore; currentProfile = new AzureProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile)); ProfileClient client = new ProfileClient(currentProfile); var account = client.AddAccountAndLoadSubscriptions(new AzureAccount { Id = "UserA", Type = AzureAccount.AccountType.User }, AzureEnvironment.PublicEnvironments[EnvironmentName.AzureCloud], null); var userA = client.GetAccount("UserA"); var secondUserA = client.GetAccount("USERA"); Assert.NotNull(userA); Assert.NotNull(secondUserA); Assert.Equal(userA.Id, secondUserA.Id); }
public void AddAzureAccountWithImpersonatedGuestWithSubscriptions() { SetMocks(new[] { rdfeSubscription1, guestRdfeSubscription }.ToList(), new List<Microsoft.Azure.Subscriptions.Csm.Models.Subscription>(), new[] { commonTenant, guestTenant }.ToList(), (userAccount, environment, tenant) => { var token = new MockAccessToken { UserId = tenant == commonTenant.TenantId ? userAccount.Id : "UserB", AccessToken = "def", LoginType = LoginType.OrgId }; userAccount.Id = token.UserId; return token; }); MemoryDataStore dataStore = new MemoryDataStore(); dataStore.VirtualStore[oldProfileDataPath] = oldProfileData; AzureSession.DataStore = dataStore; currentProfile = new AzureProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile)); ProfileClient client = new ProfileClient(currentProfile); var account = client.AddAccountAndLoadSubscriptions(new AzureAccount { Id = "UserA", Type = AzureAccount.AccountType.User }, AzureEnvironment.PublicEnvironments[EnvironmentName.AzureCloud], null); Assert.Equal("UserA", account.Id); Assert.Equal(1, account.GetSubscriptions(client.Profile).Count); var subrdfe1 = account.GetSubscriptions(client.Profile).FirstOrDefault(s => s.Id == new Guid(rdfeSubscription1.SubscriptionId)); var userA = client.GetAccount("UserA"); var userB = client.GetAccount("UserB"); var subGuest = userB.GetSubscriptions(client.Profile).FirstOrDefault(s => s.Id == new Guid(guestRdfeSubscription.SubscriptionId)); Assert.NotNull(userA); Assert.NotNull(userB); Assert.Contains<string>(rdfeSubscription1.SubscriptionId, userA.GetPropertyAsArray(AzureAccount.Property.Subscriptions), StringComparer.OrdinalIgnoreCase); Assert.Contains<string>(guestRdfeSubscription.SubscriptionId, userB.GetPropertyAsArray(AzureAccount.Property.Subscriptions), StringComparer.OrdinalIgnoreCase); Assert.NotNull(subrdfe1); Assert.NotNull(subGuest); Assert.Equal("UserA", subrdfe1.Account); Assert.Equal("UserB", subGuest.Account); }
public void AddAzureAccountReturnsAccountWithAllSubscriptionsInCsmMode() { SetMocks(new[] { rdfeSubscription1, rdfeSubscription2 }.ToList(), new[] { csmSubscription1 }.ToList()); MemoryDataStore dataStore = new MemoryDataStore(); dataStore.VirtualStore[oldProfileDataPath] = oldProfileData; AzureSession.DataStore = dataStore; currentProfile = new AzureProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile)); ProfileClient client = new ProfileClient(currentProfile); var account = client.AddAccountAndLoadSubscriptions( new AzureAccount { Id = "test", Type = AzureAccount.AccountType.User }, AzureEnvironment.PublicEnvironments[EnvironmentName.AzureCloud], null); Assert.Equal("test", account.Id); Assert.Equal(3, account.GetSubscriptions(client.Profile).Count); Assert.True(account.GetSubscriptions(client.Profile).Any(s => s.Id == new Guid(rdfeSubscription1.SubscriptionId))); Assert.True(account.GetSubscriptions(client.Profile).Any(s => s.Id == new Guid(rdfeSubscription2.SubscriptionId))); Assert.True(account.GetSubscriptions(client.Profile).Any(s => s.Id == new Guid(csmSubscription1.SubscriptionId))); }