in src/tree/azureAccountTreeItem.ts [76:188]
public async loadMoreChildrenImpl(): Promise<AzExtTreeItem[]> {
const existingSubscriptionTreeItems: AzExtTreeItem[] = this.subscriptionTreeItems || [];
this.subscriptionTreeItems = [];
switch (this.sessionProvider.signInStatus) {
case "Initializing":
return [
new GenericTreeItem(this, {
label: "Loading...",
contextValue: "azureCommand",
id: "aksAccountLoading",
iconPath: new ThemeIcon("loading~spin"),
}),
];
case "SignedOut":
return [
new GenericTreeItem(this, {
label: "Sign in to Azure...",
commandId: "aks.signInToAzure",
contextValue: "azureCommand",
id: "aksAccountSignIn",
iconPath: new ThemeIcon("sign-in"),
includeInTreeItemPicker: true,
}),
];
case "SigningIn":
return [
new GenericTreeItem(this, {
label: "Waiting for Azure sign-in...",
contextValue: "azureCommand",
id: "aksAccountSigningIn",
iconPath: new ThemeIcon("loading~spin"),
}),
];
}
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...",
commandId: "aks.selectTenant",
contextValue: "azureCommand",
id: "aksAccountSelectTenant",
iconPath: new ThemeIcon("account"),
includeInTreeItemPicker: true,
}),
];
}
// 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 [
new GenericTreeItem(this, {
label: "Error authenticating",
contextValue: "azureCommand",
id: "aksAccountError",
iconPath: new ThemeIcon("error"),
}),
];
}
const subscriptions = await getSubscriptions(this.sessionProvider, SelectionType.AllIfNoFilters);
if (failed(subscriptions)) {
return [
new GenericTreeItem(this, {
label: "Error loading subscriptions",
contextValue: "azureCommand",
id: "aksAccountError",
iconPath: new ThemeIcon("error"),
description: subscriptions.error,
}),
];
}
if (subscriptions.result.length === 0) {
return [
new GenericTreeItem(this, {
label: "No subscriptions found",
contextValue: "azureCommand",
id: "aksAccountNoSubs",
iconPath: new ThemeIcon("info"),
}),
];
}
// We've confirmed above that the provider is ready.
const readySessionProvider: ReadyAzureSessionProvider = this.sessionProvider;
this.subscriptionTreeItems = await Promise.all(
subscriptions.result.map(async (subscription) => {
const existingTreeItem: AzExtTreeItem | undefined = existingSubscriptionTreeItems.find(
(ti) => ti.id === subscription.subscriptionId,
);
if (existingTreeItem) {
// Return existing treeItem (which might have many 'cached' tree items underneath it) rather than creating a brand new tree item every time
return existingTreeItem;
} else {
const subscriptionContext = getSubscriptionContext(
readySessionProvider,
session.result,
subscription,
);
return await createSubscriptionTreeItem(this, readySessionProvider, subscriptionContext);
}
}),
);
return this.subscriptionTreeItems;
}