Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix treeview stuck with only 'select tenant' node #681

Merged
merged 1 commit into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/commands/aksAccount/aksAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,16 @@ export async function selectTenant(): Promise<void> {
}

if (sessionProvider.availableTenants.length === 1) {
window.showInformationMessage(`Only one tenant available (${sessionProvider.availableTenants[0].name}).`);
sessionProvider.selectedTenant = sessionProvider.availableTenants[0];

// If this tenant wasn't previously selected, it was probably because it wasn't immediately
// accessible (the user's current token didn't have access to it). Calling getAuthSession
// will prompt the user to re-authenticate if necessary.
const sessionResult = await sessionProvider.getAuthSession();
if (failed(sessionResult)) {
window.showErrorMessage(sessionResult.error);
}

return;
}

Expand Down
9 changes: 5 additions & 4 deletions src/tree/azureAccountTreeItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ class AzureAccountTreeItem extends AzExtParentTreeItem {
];
}

if (this.sessionProvider.selectedTenant === null) {
// Signed in, but maybe no tenant selected
if (this.sessionProvider.selectedTenant === null && this.sessionProvider.availableTenants.length > 1) {
// Signed in, but no tenant selected, AND there is more than one tenant to choose from.
return [
new GenericTreeItem(this, {
label: "Select tenant...",
Expand All @@ -118,8 +118,9 @@ class AzureAccountTreeItem extends AzExtParentTreeItem {
];
}

// Check the session is ready and we can get an auth session
// (which will be used below for creating a subscription context).
// Either we have a selected tenant, or there is only one available tenant and it's not selected
// because it requires extra interaction. Calling `getAuthSession` will complete that process.
// We will need the returned auth session in any case for creating a subscription context.
const session = await this.sessionProvider.getAuthSession();
if (failed(session) || !isReady(this.sessionProvider)) {
return [
Expand Down
Loading