Skip to content

Commit b734c60

Browse files
authored
Keep listing all subscriptions if needs to select from list (#24930)
* Keep listing all subscriptions if needs to select from list * populate all contexts
1 parent cadbf19 commit b734c60

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

src/Accounts/Accounts/Models/RMProfileClient.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,6 @@ public AzureRmProfile Login(
269269
subscriptions, _queriedTenants, tenantIdOrName, tenantName, lastUsedSubscription,
270270
Prompt, WriteInformationMessage,
271271
ref defaultSubscription, ref defaultTenant);
272-
var defaultContext = new AzureContext(defaultSubscription, account, environment, defaultTenant);
273-
_profile.TrySetDefaultContext(defaultContext);
274-
_profile.TryRemoveContext("Default");
275272
}
276273
}
277274
}
@@ -325,12 +322,12 @@ public AzureRmProfile Login(
325322
}
326323

327324
if (token != null &&
328-
defaultTenant == null &&
325+
(defaultTenant == null || selectSubscriptionFromList) &&
329326
TryGetTenantSubscription(token, account, environment, subscriptionId, subscriptionName, false, out tempSubscription, out tempTenant, out tempSubscriptions, isInteractiveAuthenticationFlow))
330327
{
331328
// If no subscription found for the given token/tenant,discard tempTenant value.
332329
// Continue to look for matched subscripitons until one subscription retrived by its home tenant is found.
333-
if (tempSubscription != null)
330+
if (defaultTenant == null && tempSubscription != null)
334331
{
335332
defaultSubscription = tempSubscription;
336333
if (tempSubscription.GetTenant() == tempSubscription.GetHomeTenant())
@@ -355,14 +352,12 @@ public AzureRmProfile Login(
355352
subscriptions, _queriedTenants, tenantIdOrName, tenantName, lastUsedSubscription,
356353
Prompt, WriteInformationMessage,
357354
ref defaultSubscription, ref defaultTenant);
358-
var defaultContext = new AzureContext(defaultSubscription, account, environment, defaultTenant);
359-
_profile.TrySetDefaultContext(defaultContext);
360-
_profile.TryRemoveContext("Default");
361355
}
362356
}
363357
}
364358

365359
shouldPopulateContextList &= _profile.DefaultContext?.Account == null;
360+
366361
if (defaultSubscription == null)
367362
{
368363
if (subscriptionId != null)
@@ -383,7 +378,7 @@ public AzureRmProfile Login(
383378
}
384379
else
385380
{
386-
defaultTenant = InteractiveSubscriptionSelectionHelper.GetDetailedTenantFromQueryHistory(_queriedTenants, defaultTenant?.Id) ?? defaultTenant; ;
381+
defaultTenant = InteractiveSubscriptionSelectionHelper.GetDetailedTenantFromQueryHistory(_queriedTenants, defaultTenant?.Id) ?? defaultTenant;
387382
var defaultContext = new AzureContext(defaultSubscription, account, environment, defaultTenant);
388383
if (!_profile.TrySetDefaultContext(name, defaultContext))
389384
{

src/Accounts/Accounts/Utilities/InteractiveSubscriptionSelectionHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ internal static void SelectSubscriptionFromList(IEnumerable<IAzureSubscription>
3333
Func<string, string> prompt, Action<string> outputAction,
3434
ref IAzureSubscription defaultSubscription, ref IAzureTenant defaultTenant)
3535
{
36-
subscriptions = subscriptions?.OrderBy(s => GetDetailedTenantFromQueryHistory(queriedTenants, s.GetProperty(AzureSubscription.Property.Tenants)))?.ThenBy(s => s.Name)?.ToList();
36+
subscriptions = subscriptions?.OrderBy(s => GetDetailedTenantFromQueryHistory(queriedTenants, s.GetProperty(AzureSubscription.Property.Tenants))?.GetProperty(AzureTenant.Property.DisplayName))?.ThenBy(s => s.Name)?.ToList();
3737

3838
var markDefaultSubscription = lastUsedSubscription != null;
3939

0 commit comments

Comments
 (0)