Skip to content

Commit cbe447e

Browse files
author
Hovsep Mkrtchyan
committed
fixed[#111792922] Add-AzureRmAccount :: Incorrect credentials aren't throwing an exception
1 parent 91e1858 commit cbe447e

File tree

3 files changed

+29
-11
lines changed

3 files changed

+29
-11
lines changed

src/ResourceManager/Profile/Commands.Profile/Models/RMProfileClient.cs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -386,9 +386,10 @@ public IEnumerable<AzureSubscription> ListSubscriptions()
386386
}
387387
catch (AadAuthenticationException)
388388
{
389-
WriteWarningMessage(string.Format("Could not authenticate user account {0} with tenant {1}. " +
390-
"Subscriptions in this tenant will not be listed. Please login again using Login-AzureRmAccount " +
391-
"to view the subscriptions in this tenant.", _profile.Context.Account, tenant));
389+
WriteWarningMessage(string.Format(
390+
Microsoft.Azure.Commands.Profile.Properties.Resources.UnableToLogin,
391+
_profile.Context.Account,
392+
tenant));
392393
}
393394

394395
}
@@ -576,11 +577,12 @@ private List<AzureTenant> ListAccountTenants(AzureAccount account, AzureEnvironm
576577
{
577578
result =
578579
account.GetPropertyAsArray(AzureAccount.Property.Tenants)
579-
.Select( ti => {
580+
.Select(ti =>
581+
{
580582
var tenant = new AzureTenant();
581-
583+
582584
Guid guid;
583-
if(Guid.TryParse(ti, out guid))
585+
if (Guid.TryParse(ti, out guid))
584586
{
585587
tenant.Id = guid;
586588
tenant.Domain = AccessTokenExtensions.GetDomain(account.Id);
@@ -593,8 +595,12 @@ private List<AzureTenant> ListAccountTenants(AzureAccount account, AzureEnvironm
593595
return tenant;
594596
}).ToList();
595597
}
596-
597-
}
598+
if(!result.Any())
599+
{
600+
throw;
601+
}
602+
603+
}
598604

599605
return result;
600606
}
@@ -640,7 +646,7 @@ private void WriteWarningMessage(string message)
640646
WarningLog(message);
641647
}
642648
}
643-
649+
644650
private static AzureTenant CreateTenantFromString(string tenantOrDomain, string accessTokenTenantId)
645651
{
646652
AzureTenant result = new AzureTenant();

src/ResourceManager/Profile/Commands.Profile/Properties/Resources.Designer.cs

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ResourceManager/Profile/Commands.Profile/Properties/Resources.resx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,10 @@
168168
<data name="UnableToAqcuireToken" xml:space="preserve">
169169
<value>Unable to acquire token for tenant '{0}'</value>
170170
</data>
171+
<data name="UnableToLogin" xml:space="preserve">
172+
<value>Could not authenticate user account '{0}' with tenant '{1}'. Subscriptions in this tenant will not be listed. Please login again using Login-AzureRmAccount to view the subscriptions in this tenant.</value>
173+
</data>
171174
<data name="UnknownEnvironment" xml:space="preserve">
172175
<value>Unable to find environment with name '{0}'</value>
173176
</data>
174-
</root>
177+
</root>

0 commit comments

Comments
 (0)