Skip to content

Commit 0016cc2

Browse files
committed
login-subscriptions
1 parent 7765639 commit 0016cc2

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

  • src/azure-cli/azure/cli/command_modules/profile

src/azure-cli/azure/cli/command_modules/profile/custom.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,17 @@ def login(cmd, username=None, password=None, tenant=None, scopes=None, allow_no_
205205

206206
# Launch interactive account selection. No JSON output.
207207
if select_subscription:
208-
from ._subscription_selector import SubscriptionSelector
209-
from azure.cli.core._profile import _SUBSCRIPTION_ID
210-
211-
selected = SubscriptionSelector(subscriptions)()
212-
profile.set_active_subscription(selected[_SUBSCRIPTION_ID])
213-
208+
if subscriptions:
209+
from ._subscription_selector import SubscriptionSelector
210+
from azure.cli.core._profile import _SUBSCRIPTION_ID
211+
selected = SubscriptionSelector(subscriptions)()
212+
profile.set_active_subscription(selected[_SUBSCRIPTION_ID])
213+
else:
214+
# By default, if the account has no access to any subscription, CLI will fail earlier in _profile.py.
215+
# When --allow-no-subscriptions is specified, and the account
216+
# - has access to tenant, but no subscription, `subscriptions` will be the tenant account
217+
# - has access to no tenant, `subscriptions` will be []. This line will be hit.
218+
print("\nNo accessible tenant. Make sure your account has access to at least one tenant.\n")
214219
print(LOGIN_ANNOUNCEMENT)
215220
logger.warning(LOGIN_OUTPUT_WARNING)
216221
return

0 commit comments

Comments
 (0)