From c93270e923c3765463b0f6a8f5ff5f623f671367 Mon Sep 17 00:00:00 2001 From: alexweininger Date: Fri, 4 Oct 2024 17:18:00 -0400 Subject: [PATCH 1/5] Fixes for multi account --- package-lock.json | 78 +++++++++++++++---- package.json | 2 +- .../tenants/TenantResourceTreeDataProvider.ts | 2 +- 3 files changed, 64 insertions(+), 18 deletions(-) diff --git a/package-lock.json b/package-lock.json index 20739c7d..f2da8a2f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,7 @@ "@azure/arm-resources": "^5.2.0", "@azure/arm-resources-profile-2020-09-01-hybrid": "^2.1.0", "@azure/ms-rest-js": "^2.7.0", - "@microsoft/vscode-azext-azureauth": "file:../vscode-azuretools/auth/microsoft-vscode-azext-azureauth-2.5.0.tgz", + "@microsoft/vscode-azext-azureauth": "file:../vscode-azuretools/auth", "@microsoft/vscode-azext-azureutils": "^3.1.1", "@microsoft/vscode-azext-utils": "^2.5.7", "buffer": "^6.0.3", @@ -60,6 +60,39 @@ "vscode": "^1.82.0" } }, + "../vscode-azuretools/auth": { + "name": "@microsoft/vscode-azext-azureauth", + "version": "3.0.0", + "license": "MIT", + "dependencies": { + "@azure/arm-resources-subscriptions": "^2.1.0", + "@azure/core-client": "^1.9.2", + "@azure/core-rest-pipeline": "^1.16.0", + "@azure/ms-rest-azure-env": "^2.0.0" + }, + "devDependencies": { + "@azure/core-auth": "^1.4.0", + "@azure/identity": "^4.2.0", + "@microsoft/eslint-config-azuretools": "^0.2.1", + "@types/glob": "^8.1.0", + "@types/html-to-text": "^8.1.0", + "@types/mocha": "^7.0.2", + "@types/node": "^18.18.7", + "@types/node-fetch": "2.6.7", + "@types/semver": "^7.3.9", + "@types/uuid": "^9.0.1", + "@types/vscode": "1.93.0", + "@typescript-eslint/eslint-plugin": "^5.53.0", + "@vscode/test-electron": "^2.3.8", + "eslint": "^8.34.0", + "eslint-plugin-import": "^2.22.1", + "glob": "^7.1.6", + "mocha": "^9.1.3", + "mocha-junit-reporter": "^2.0.2", + "mocha-multi-reporters": "^1.1.7", + "typescript": "^4.9.4" + } + }, "node_modules/@azure/abort-controller": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/@azure/abort-controller/-/abort-controller-1.0.4.tgz", @@ -524,7 +557,8 @@ "node_modules/@azure/ms-rest-azure-env": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/@azure/ms-rest-azure-env/-/ms-rest-azure-env-2.0.0.tgz", - "integrity": "sha512-dG76W7ElfLi+fbTjnZVGj+M9e0BIEJmRxU6fHaUQ12bZBe8EJKYb2GV50YWNaP2uJiVQ5+7nXEVj1VN1UQtaEw==" + "integrity": "sha512-dG76W7ElfLi+fbTjnZVGj+M9e0BIEJmRxU6fHaUQ12bZBe8EJKYb2GV50YWNaP2uJiVQ5+7nXEVj1VN1UQtaEw==", + "peer": true }, "node_modules/@azure/ms-rest-js": { "version": "2.7.0", @@ -1033,16 +1067,8 @@ } }, "node_modules/@microsoft/vscode-azext-azureauth": { - "version": "2.5.0", - "resolved": "file:../vscode-azuretools/auth/microsoft-vscode-azext-azureauth-2.5.0.tgz", - "integrity": "sha512-7J8yDiPU/GVVEw0LAkj1Ci5+MPnS8w9h5gcycxCkNo3TPMb1AHoqa+E7WBFSlJgTDA7PJzWTyMGWQ7+xUE7XSw==", - "license": "MIT", - "dependencies": { - "@azure/arm-resources-subscriptions": "^2.1.0", - "@azure/core-client": "^1.9.2", - "@azure/core-rest-pipeline": "^1.16.0", - "@azure/ms-rest-azure-env": "^2.0.0" - } + "resolved": "../vscode-azuretools/auth", + "link": true }, "node_modules/@microsoft/vscode-azext-azureutils": { "version": "3.1.1", @@ -10619,7 +10645,8 @@ "@azure/ms-rest-azure-env": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/@azure/ms-rest-azure-env/-/ms-rest-azure-env-2.0.0.tgz", - "integrity": "sha512-dG76W7ElfLi+fbTjnZVGj+M9e0BIEJmRxU6fHaUQ12bZBe8EJKYb2GV50YWNaP2uJiVQ5+7nXEVj1VN1UQtaEw==" + "integrity": "sha512-dG76W7ElfLi+fbTjnZVGj+M9e0BIEJmRxU6fHaUQ12bZBe8EJKYb2GV50YWNaP2uJiVQ5+7nXEVj1VN1UQtaEw==", + "peer": true }, "@azure/ms-rest-js": { "version": "2.7.0", @@ -11027,13 +11054,32 @@ } }, "@microsoft/vscode-azext-azureauth": { - "version": "file:..\\vscode-azuretools\\auth\\microsoft-vscode-azext-azureauth-2.5.0.tgz", - "integrity": "sha512-7J8yDiPU/GVVEw0LAkj1Ci5+MPnS8w9h5gcycxCkNo3TPMb1AHoqa+E7WBFSlJgTDA7PJzWTyMGWQ7+xUE7XSw==", + "version": "file:../vscode-azuretools/auth", "requires": { "@azure/arm-resources-subscriptions": "^2.1.0", + "@azure/core-auth": "^1.4.0", "@azure/core-client": "^1.9.2", "@azure/core-rest-pipeline": "^1.16.0", - "@azure/ms-rest-azure-env": "^2.0.0" + "@azure/identity": "^4.2.0", + "@azure/ms-rest-azure-env": "^2.0.0", + "@microsoft/eslint-config-azuretools": "^0.2.1", + "@types/glob": "^8.1.0", + "@types/html-to-text": "^8.1.0", + "@types/mocha": "^7.0.2", + "@types/node": "^18.18.7", + "@types/node-fetch": "2.6.7", + "@types/semver": "^7.3.9", + "@types/uuid": "^9.0.1", + "@types/vscode": "1.93.0", + "@typescript-eslint/eslint-plugin": "^5.53.0", + "@vscode/test-electron": "^2.3.8", + "eslint": "^8.34.0", + "eslint-plugin-import": "^2.22.1", + "glob": "^7.1.6", + "mocha": "^9.1.3", + "mocha-junit-reporter": "^2.0.2", + "mocha-multi-reporters": "^1.1.7", + "typescript": "^4.9.4" } }, "@microsoft/vscode-azext-azureutils": { diff --git a/package.json b/package.json index 7aa30e48..b73c4217 100644 --- a/package.json +++ b/package.json @@ -713,7 +713,7 @@ "@azure/arm-resources": "^5.2.0", "@azure/arm-resources-profile-2020-09-01-hybrid": "^2.1.0", "@azure/ms-rest-js": "^2.7.0", - "@microsoft/vscode-azext-azureauth": "file:../vscode-azuretools/auth/microsoft-vscode-azext-azureauth-2.5.0.tgz", + "@microsoft/vscode-azext-azureauth": "file:../vscode-azuretools/auth", "@microsoft/vscode-azext-azureutils": "^3.1.1", "@microsoft/vscode-azext-utils": "^2.5.7", "buffer": "^6.0.3", diff --git a/src/tree/tenants/TenantResourceTreeDataProvider.ts b/src/tree/tenants/TenantResourceTreeDataProvider.ts index 6caebf02..4024c65c 100644 --- a/src/tree/tenants/TenantResourceTreeDataProvider.ts +++ b/src/tree/tenants/TenantResourceTreeDataProvider.ts @@ -55,7 +55,7 @@ export class TenantResourceTreeDataProvider extends ResourceTreeDataProviderBase const tenants = await subscriptionProvider.getTenants(account); const tenantItems: ResourceGroupsItem[] = []; for await (const tenant of tenants) { - const isSignedIn = await subscriptionProvider.isSignedIn(nonNullProp(tenant, 'tenantId')); + const isSignedIn = await subscriptionProvider.isSignedIn(nonNullProp(tenant, 'tenantId'), account); tenantItems.push(new TenantTreeItem(nonNullProp(tenant, 'displayName'), nonNullProp(tenant, 'tenantId'), nonNullProp(account, 'id'), { contextValue: isSignedIn ? 'tenantName' : 'tenantNameNotSignedIn', checkboxState: (!(isSignedIn) || this.checkUnselectedTenants(nonNullProp(tenant, 'tenantId'))) ? From 9f2a7d666f85f44804e134c8c16737703d2d45c2 Mon Sep 17 00:00:00 2001 From: alexweininger Date: Mon, 18 Nov 2024 08:33:52 -0800 Subject: [PATCH 2/5] Random fixes and changes --- src/commands/registerCommands.ts | 6 ++--- src/tree/GenericItem.ts | 15 ++++++++++++ .../tenants/TenantResourceTreeDataProvider.ts | 5 ++-- src/tree/tenants/TenantTreeItem.ts | 4 ++-- src/tree/tenants/registerTenantTree.ts | 23 +++++++++++-------- 5 files changed, 37 insertions(+), 16 deletions(-) diff --git a/src/commands/registerCommands.ts b/src/commands/registerCommands.ts index a1573c44..450899a5 100644 --- a/src/commands/registerCommands.ts +++ b/src/commands/registerCommands.ts @@ -5,7 +5,7 @@ import { signInToTenant } from '@microsoft/vscode-azext-azureauth'; import { AzExtTreeItem, IActionContext, isAzExtTreeItem, openUrl, registerCommand, registerErrorHandler, registerReportIssueCommand } from '@microsoft/vscode-azext-utils'; -import { commands } from 'vscode'; +import { AuthenticationSessionAccountInformation, commands } from 'vscode'; import { uploadFileToCloudShell } from '../cloudConsole/uploadFileToCloudShell'; import { ext } from '../extensionVariables'; import { BranchDataItemWrapper } from '../tree/BranchDataItemWrapper'; @@ -70,8 +70,8 @@ export function registerCommands(): void { ext.actions.refreshTenantTree(node); }); - registerCommand('azureTenant.signInToTenant', async (_context, node: TenantTreeItem) => { - await (await ext.subscriptionProviderFactory()).signIn(node.tenantId); + registerCommand('azureTenant.signInToTenant', async (_context, node: TenantTreeItem, account?: AuthenticationSessionAccountInformation) => { + await (await ext.subscriptionProviderFactory()).signIn(node.tenantId, account); ext.actions.refreshTenantTree(node); }); diff --git a/src/tree/GenericItem.ts b/src/tree/GenericItem.ts index 38368921..ea027a62 100644 --- a/src/tree/GenericItem.ts +++ b/src/tree/GenericItem.ts @@ -15,6 +15,20 @@ export interface GenericItemOptions { readonly iconPath?: TreeItemIconPath; readonly description?: string; readonly collapsibleState?: vscode.TreeItemCollapsibleState; + readonly checkboxState?: vscode.TreeItemCheckboxState | { + /** + * The {@link TreeItemCheckboxState} of the tree item + */ + readonly state: vscode.TreeItemCheckboxState; + /** + * A tooltip for the checkbox + */ + readonly tooltip?: string; + /** + * Accessibility information used when screen readers interact with this checkbox + */ + readonly accessibilityInformation?: vscode.AccessibilityInformation; + }; } export class GenericItem implements ResourceGroupsItem { @@ -41,6 +55,7 @@ export class GenericItem implements ResourceGroupsItem { treeItem.description = this.options?.description; treeItem.contextValue = this.options?.contextValue; treeItem.iconPath = this.options?.iconPath; + treeItem.checkboxState = this.options?.checkboxState; return treeItem; } diff --git a/src/tree/tenants/TenantResourceTreeDataProvider.ts b/src/tree/tenants/TenantResourceTreeDataProvider.ts index 4024c65c..5463aba7 100644 --- a/src/tree/tenants/TenantResourceTreeDataProvider.ts +++ b/src/tree/tenants/TenantResourceTreeDataProvider.ts @@ -56,7 +56,7 @@ export class TenantResourceTreeDataProvider extends ResourceTreeDataProviderBase const tenantItems: ResourceGroupsItem[] = []; for await (const tenant of tenants) { const isSignedIn = await subscriptionProvider.isSignedIn(nonNullProp(tenant, 'tenantId'), account); - tenantItems.push(new TenantTreeItem(nonNullProp(tenant, 'displayName'), nonNullProp(tenant, 'tenantId'), nonNullProp(account, 'id'), { + tenantItems.push(new TenantTreeItem(nonNullProp(tenant, 'displayName'), nonNullProp(tenant, 'tenantId'), account, { contextValue: isSignedIn ? 'tenantName' : 'tenantNameNotSignedIn', checkboxState: (!(isSignedIn) || this.checkUnselectedTenants(nonNullProp(tenant, 'tenantId'))) ? vscode.TreeItemCheckboxState.Unchecked : vscode.TreeItemCheckboxState.Checked, // Make sure tenants which are not signed in are unchecked @@ -68,7 +68,8 @@ export class TenantResourceTreeDataProvider extends ResourceTreeDataProviderBase children: tenantItems, iconPath: new vscode.ThemeIcon('account'), contextValue: 'accountName', - collapsibleState: vscode.TreeItemCollapsibleState.Expanded + collapsibleState: vscode.TreeItemCollapsibleState.Expanded, + checkboxState: vscode.TreeItemCheckboxState.Checked, })); } } diff --git a/src/tree/tenants/TenantTreeItem.ts b/src/tree/tenants/TenantTreeItem.ts index fa5459fd..19417899 100644 --- a/src/tree/tenants/TenantTreeItem.ts +++ b/src/tree/tenants/TenantTreeItem.ts @@ -12,11 +12,11 @@ export interface TenantItemOptions extends GenericItemOptions { } export class TenantTreeItem implements ResourceGroupsItem { - constructor(public readonly label: string, public tenantId: string, public account: string, private readonly options?: TenantItemOptions) { + constructor(public readonly label: string, public tenantId: string, public readonly account: vscode.AuthenticationSessionAccountInformation, private readonly options?: TenantItemOptions) { } readonly id: string = this.tenantId; - readonly accountId: string = this.account + readonly accountId = this.account.id; getChildren(): vscode.ProviderResult { return this.options?.children; diff --git a/src/tree/tenants/registerTenantTree.ts b/src/tree/tenants/registerTenantTree.ts index 75c76943..74a702f1 100644 --- a/src/tree/tenants/registerTenantTree.ts +++ b/src/tree/tenants/registerTenantTree.ts @@ -51,20 +51,25 @@ export function registerTenantTree(context: vscode.ExtensionContext, options: Re } async function updateTenantsSetting(_context: IActionContext, tenants: vscode.TreeCheckboxChangeEvent) { - const unselectedTenants = ext.context.globalState.get('unselectedTenants') || []; + const state = ext.context.globalState.get('unselectedTenants'); + const unselectedTenants = new Set(state ?? []); - for (const item of tenants.items) { - if (item[1] === vscode.TreeItemCheckboxState.Unchecked) { - unselectedTenants.push(`${item[0].id}/${item[0].accountId}`); - } else if (item[1] === vscode.TreeItemCheckboxState.Checked) { - const treeItem = await item[0].getTreeItem(); + for (const [tenantTreeItem, state] of tenants.items) { + if (state === vscode.TreeItemCheckboxState.Unchecked) { + unselectedTenants.add(getKeyForTenant(tenantTreeItem)); + } else if (state === vscode.TreeItemCheckboxState.Checked) { + const treeItem = await tenantTreeItem.getTreeItem(); if (treeItem?.contextValue === 'tenantNameNotSignedIn') { - await vscode.commands.executeCommand('azureTenant.signInToTenant', item[0]); + await vscode.commands.executeCommand('azureTenant.signInToTenant', tenantTreeItem,); ext.actions.refreshTenantTree(); } - unselectedTenants.splice(unselectedTenants.indexOf(item[0].id), 1); + unselectedTenants.delete(getKeyForTenant(tenantTreeItem)); } } - await ext.context.globalState.update('unselectedTenants', unselectedTenants); + await ext.context.globalState.update('unselectedTenants', Array.from(unselectedTenants)); +} + +export function getKeyForTenant(tenant: { id: string, accountId: string }): string { + return `${tenant.id}/${tenant.accountId}`; } From 380ded2c3fef61be0fe523b216173403793fa2a7 Mon Sep 17 00:00:00 2001 From: alexweininger Date: Wed, 20 Nov 2024 16:25:57 -0800 Subject: [PATCH 3/5] Fixup --- src/tree/tenants/TenantResourceTreeDataProvider.ts | 1 - src/tree/tenants/registerTenantTree.ts | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/tree/tenants/TenantResourceTreeDataProvider.ts b/src/tree/tenants/TenantResourceTreeDataProvider.ts index 5463aba7..289cfdc0 100644 --- a/src/tree/tenants/TenantResourceTreeDataProvider.ts +++ b/src/tree/tenants/TenantResourceTreeDataProvider.ts @@ -69,7 +69,6 @@ export class TenantResourceTreeDataProvider extends ResourceTreeDataProviderBase iconPath: new vscode.ThemeIcon('account'), contextValue: 'accountName', collapsibleState: vscode.TreeItemCollapsibleState.Expanded, - checkboxState: vscode.TreeItemCheckboxState.Checked, })); } } diff --git a/src/tree/tenants/registerTenantTree.ts b/src/tree/tenants/registerTenantTree.ts index 74a702f1..c8a5e5b4 100644 --- a/src/tree/tenants/registerTenantTree.ts +++ b/src/tree/tenants/registerTenantTree.ts @@ -60,7 +60,7 @@ async function updateTenantsSetting(_context: IActionContext, tenants: vscode.Tr } else if (state === vscode.TreeItemCheckboxState.Checked) { const treeItem = await tenantTreeItem.getTreeItem(); if (treeItem?.contextValue === 'tenantNameNotSignedIn') { - await vscode.commands.executeCommand('azureTenant.signInToTenant', tenantTreeItem,); + await vscode.commands.executeCommand('azureTenant.signInToTenant', tenantTreeItem, tenantTreeItem.account); ext.actions.refreshTenantTree(); } unselectedTenants.delete(getKeyForTenant(tenantTreeItem)); From 37e696ff84828d6e3fdb0b3d77c49ff0b3d8f500 Mon Sep 17 00:00:00 2001 From: Alex Weininger Date: Tue, 26 Nov 2024 13:16:23 -0800 Subject: [PATCH 4/5] Fixup unselected tenant logic (#963) --- src/commands/accounts/selectSubscriptions.ts | 12 ++--- .../tenants/TenantResourceTreeDataProvider.ts | 18 ++----- src/tree/tenants/registerTenantTree.ts | 53 ++++++++++++++++--- 3 files changed, 53 insertions(+), 30 deletions(-) diff --git a/src/commands/accounts/selectSubscriptions.ts b/src/commands/accounts/selectSubscriptions.ts index 3af153d4..68299b92 100644 --- a/src/commands/accounts/selectSubscriptions.ts +++ b/src/commands/accounts/selectSubscriptions.ts @@ -7,6 +7,7 @@ import { AzureSubscription } from "@microsoft/vscode-azext-azureauth"; import { IActionContext, IAzureQuickPickItem } from "@microsoft/vscode-azext-utils"; import * as vscode from "vscode"; import { ext } from "../../extensionVariables"; +import { isTenantFilteredOut } from "../../tree/tenants/registerTenantTree"; import { localize } from "../../utils/localize"; import { settingUtils } from "../../utils/settingUtils"; @@ -89,15 +90,8 @@ async function setSelectedTenantAndSubscriptionIds(tenantAndSubscriptionIds: str // This function is also used to filter subscription tree items in AzureResourceTreeDataProvider export function getTenantFilteredSubscriptions(allSubscriptions: AzureSubscription[]): AzureSubscription[] | undefined { - const tenants = ext.context.globalState.get('unselectedTenants'); - if (tenants && tenants.length > 0) { - allSubscriptions = allSubscriptions.filter(subscription => !tenants.includes(`${subscription.tenantId}/${subscription.account?.id}`)); - if (allSubscriptions.length > 0) { - return allSubscriptions; - } - } - - return undefined; + const filteredSubscriptions = allSubscriptions.filter(subscription => !isTenantFilteredOut(subscription.tenantId, subscription.account.id)); + return filteredSubscriptions.length > 0 ? filteredSubscriptions : allSubscriptions; } export function getDuplicateSubscriptions(subscriptions: AzureSubscription[]): AzureSubscription[] { diff --git a/src/tree/tenants/TenantResourceTreeDataProvider.ts b/src/tree/tenants/TenantResourceTreeDataProvider.ts index 289cfdc0..a79c9649 100644 --- a/src/tree/tenants/TenantResourceTreeDataProvider.ts +++ b/src/tree/tenants/TenantResourceTreeDataProvider.ts @@ -8,7 +8,6 @@ import { nonNullProp, nonNullValueAndProp } from '@microsoft/vscode-azext-utils' import { ResourceModelBase } from 'api/src'; import * as vscode from 'vscode'; import { TenantResourceProviderManager } from '../../api/ResourceProviderManagers'; -import { ext } from '../../extensionVariables'; import { BranchDataItemCache } from '../BranchDataItemCache'; import { GenericItem } from '../GenericItem'; import { getAzureSubscriptionProvider, OnGetChildrenBase } from '../OnGetChildrenBase'; @@ -16,6 +15,7 @@ import { ResourceGroupsItem } from '../ResourceGroupsItem'; import { ResourceTreeDataProviderBase } from "../ResourceTreeDataProviderBase"; import { TenantResourceBranchDataProviderManager } from "./TenantResourceBranchDataProviderManager"; import { TenantTreeItem } from './TenantTreeItem'; +import { isTenantFilteredOut } from './registerTenantTree'; export class TenantResourceTreeDataProvider extends ResourceTreeDataProviderBase { public subscriptionProvider: AzureSubscriptionProvider | undefined; @@ -58,9 +58,9 @@ export class TenantResourceTreeDataProvider extends ResourceTreeDataProviderBase const isSignedIn = await subscriptionProvider.isSignedIn(nonNullProp(tenant, 'tenantId'), account); tenantItems.push(new TenantTreeItem(nonNullProp(tenant, 'displayName'), nonNullProp(tenant, 'tenantId'), account, { contextValue: isSignedIn ? 'tenantName' : 'tenantNameNotSignedIn', - checkboxState: (!(isSignedIn) || this.checkUnselectedTenants(nonNullProp(tenant, 'tenantId'))) ? - vscode.TreeItemCheckboxState.Unchecked : vscode.TreeItemCheckboxState.Checked, // Make sure tenants which are not signed in are unchecked - description: tenant.defaultDomain + checkboxState: (!isSignedIn || isTenantFilteredOut(nonNullProp(tenant, 'tenantId'), account.id)) ? + vscode.TreeItemCheckboxState.Unchecked : vscode.TreeItemCheckboxState.Checked, + description: tenant.tenantId })); } @@ -75,14 +75,4 @@ export class TenantResourceTreeDataProvider extends ResourceTreeDataProviderBase return children; } } - - private checkUnselectedTenants(tenantId: string): boolean { - const settings = ext.context.globalState.get('unselectedTenants'); - if (settings) { - if (settings.includes(tenantId)) { - return true; - } - } - return false; - } } diff --git a/src/tree/tenants/registerTenantTree.ts b/src/tree/tenants/registerTenantTree.ts index c8a5e5b4..c49b590c 100644 --- a/src/tree/tenants/registerTenantTree.ts +++ b/src/tree/tenants/registerTenantTree.ts @@ -51,25 +51,64 @@ export function registerTenantTree(context: vscode.ExtensionContext, options: Re } async function updateTenantsSetting(_context: IActionContext, tenants: vscode.TreeCheckboxChangeEvent) { - const state = ext.context.globalState.get('unselectedTenants'); - const unselectedTenants = new Set(state ?? []); + const unselectedTenants = getUnselectedTenants(); + const unselectedTenantsSet = new Set(unselectedTenants); for (const [tenantTreeItem, state] of tenants.items) { if (state === vscode.TreeItemCheckboxState.Unchecked) { - unselectedTenants.add(getKeyForTenant(tenantTreeItem)); + unselectedTenantsSet.add(getKeyForTenant(tenantTreeItem.tenantId, tenantTreeItem.account.id)); } else if (state === vscode.TreeItemCheckboxState.Checked) { const treeItem = await tenantTreeItem.getTreeItem(); if (treeItem?.contextValue === 'tenantNameNotSignedIn') { await vscode.commands.executeCommand('azureTenant.signInToTenant', tenantTreeItem, tenantTreeItem.account); ext.actions.refreshTenantTree(); } - unselectedTenants.delete(getKeyForTenant(tenantTreeItem)); + unselectedTenantsSet.delete(getKeyForTenant(tenantTreeItem.tenantId, tenantTreeItem.account.id)); } } - await ext.context.globalState.update('unselectedTenants', Array.from(unselectedTenants)); + await setUnselectedTenants(Array.from(unselectedTenantsSet)); } -export function getKeyForTenant(tenant: { id: string, accountId: string }): string { - return `${tenant.id}/${tenant.accountId}`; +function removeDuplicates(arr: string[]): string[] { + return Array.from(new Set(arr)); +} + +export async function setUnselectedTenants(tenantIds: string[]): Promise { + printTenants(tenantIds); + await ext.context.globalState.update('unselectedTenants', removeDuplicates(tenantIds)); +} + +export function getUnselectedTenants(): string[] { + const value = ext.context.globalState.get('unselectedTenants'); + + if (!value || !Array.isArray(value)) { + return []; + } + + // remove any duplicates + return removeDuplicates(value); +} + +export function isTenantFilteredOut(tenantId: string, accountId: string): boolean { + const settings = ext.context.globalState.get('unselectedTenants'); + if (settings) { + if (settings.includes(getKeyForTenant(tenantId, accountId))) { + return true; + } + } + return false; +} + +export function getKeyForTenant(tenantId: string, accountId: string): string { + return `${tenantId}/${accountId}`; +} + +function printTenants(unselectedTenants: string[]): void { + let str = ''; + str += 'Unselected tenants:\n'; + for (const tenant of unselectedTenants) { + str += `- ${tenant}\n`; + } + ext.outputChannel.appendLine(str); } From d2bc247683ade5f1b8a29957d0811823f9017c15 Mon Sep 17 00:00:00 2001 From: alexweininger Date: Tue, 26 Nov 2024 16:43:14 -0800 Subject: [PATCH 5/5] Install latest version of auth package --- package-lock.json | 78 ++++++++++------------------------------------- package.json | 2 +- 2 files changed, 17 insertions(+), 63 deletions(-) diff --git a/package-lock.json b/package-lock.json index f2da8a2f..cb343886 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,7 @@ "@azure/arm-resources": "^5.2.0", "@azure/arm-resources-profile-2020-09-01-hybrid": "^2.1.0", "@azure/ms-rest-js": "^2.7.0", - "@microsoft/vscode-azext-azureauth": "file:../vscode-azuretools/auth", + "@microsoft/vscode-azext-azureauth": "^3.1.0", "@microsoft/vscode-azext-azureutils": "^3.1.1", "@microsoft/vscode-azext-utils": "^2.5.7", "buffer": "^6.0.3", @@ -60,39 +60,6 @@ "vscode": "^1.82.0" } }, - "../vscode-azuretools/auth": { - "name": "@microsoft/vscode-azext-azureauth", - "version": "3.0.0", - "license": "MIT", - "dependencies": { - "@azure/arm-resources-subscriptions": "^2.1.0", - "@azure/core-client": "^1.9.2", - "@azure/core-rest-pipeline": "^1.16.0", - "@azure/ms-rest-azure-env": "^2.0.0" - }, - "devDependencies": { - "@azure/core-auth": "^1.4.0", - "@azure/identity": "^4.2.0", - "@microsoft/eslint-config-azuretools": "^0.2.1", - "@types/glob": "^8.1.0", - "@types/html-to-text": "^8.1.0", - "@types/mocha": "^7.0.2", - "@types/node": "^18.18.7", - "@types/node-fetch": "2.6.7", - "@types/semver": "^7.3.9", - "@types/uuid": "^9.0.1", - "@types/vscode": "1.93.0", - "@typescript-eslint/eslint-plugin": "^5.53.0", - "@vscode/test-electron": "^2.3.8", - "eslint": "^8.34.0", - "eslint-plugin-import": "^2.22.1", - "glob": "^7.1.6", - "mocha": "^9.1.3", - "mocha-junit-reporter": "^2.0.2", - "mocha-multi-reporters": "^1.1.7", - "typescript": "^4.9.4" - } - }, "node_modules/@azure/abort-controller": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/@azure/abort-controller/-/abort-controller-1.0.4.tgz", @@ -557,8 +524,7 @@ "node_modules/@azure/ms-rest-azure-env": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/@azure/ms-rest-azure-env/-/ms-rest-azure-env-2.0.0.tgz", - "integrity": "sha512-dG76W7ElfLi+fbTjnZVGj+M9e0BIEJmRxU6fHaUQ12bZBe8EJKYb2GV50YWNaP2uJiVQ5+7nXEVj1VN1UQtaEw==", - "peer": true + "integrity": "sha512-dG76W7ElfLi+fbTjnZVGj+M9e0BIEJmRxU6fHaUQ12bZBe8EJKYb2GV50YWNaP2uJiVQ5+7nXEVj1VN1UQtaEw==" }, "node_modules/@azure/ms-rest-js": { "version": "2.7.0", @@ -1067,8 +1033,15 @@ } }, "node_modules/@microsoft/vscode-azext-azureauth": { - "resolved": "../vscode-azuretools/auth", - "link": true + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@microsoft/vscode-azext-azureauth/-/vscode-azext-azureauth-3.1.0.tgz", + "integrity": "sha512-jsRbrFZV6P/EM5Gpjp1SEnaiA4XyfNdkHxIyh7K/WwwN/d1DO+Q72ws/WyohK1tqfqYaxXNSegciVOGL/uNflw==", + "dependencies": { + "@azure/arm-resources-subscriptions": "^2.1.0", + "@azure/core-client": "^1.9.2", + "@azure/core-rest-pipeline": "^1.16.0", + "@azure/ms-rest-azure-env": "^2.0.0" + } }, "node_modules/@microsoft/vscode-azext-azureutils": { "version": "3.1.1", @@ -10645,8 +10618,7 @@ "@azure/ms-rest-azure-env": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/@azure/ms-rest-azure-env/-/ms-rest-azure-env-2.0.0.tgz", - "integrity": "sha512-dG76W7ElfLi+fbTjnZVGj+M9e0BIEJmRxU6fHaUQ12bZBe8EJKYb2GV50YWNaP2uJiVQ5+7nXEVj1VN1UQtaEw==", - "peer": true + "integrity": "sha512-dG76W7ElfLi+fbTjnZVGj+M9e0BIEJmRxU6fHaUQ12bZBe8EJKYb2GV50YWNaP2uJiVQ5+7nXEVj1VN1UQtaEw==" }, "@azure/ms-rest-js": { "version": "2.7.0", @@ -11054,32 +11026,14 @@ } }, "@microsoft/vscode-azext-azureauth": { - "version": "file:../vscode-azuretools/auth", + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@microsoft/vscode-azext-azureauth/-/vscode-azext-azureauth-3.1.0.tgz", + "integrity": "sha512-jsRbrFZV6P/EM5Gpjp1SEnaiA4XyfNdkHxIyh7K/WwwN/d1DO+Q72ws/WyohK1tqfqYaxXNSegciVOGL/uNflw==", "requires": { "@azure/arm-resources-subscriptions": "^2.1.0", - "@azure/core-auth": "^1.4.0", "@azure/core-client": "^1.9.2", "@azure/core-rest-pipeline": "^1.16.0", - "@azure/identity": "^4.2.0", - "@azure/ms-rest-azure-env": "^2.0.0", - "@microsoft/eslint-config-azuretools": "^0.2.1", - "@types/glob": "^8.1.0", - "@types/html-to-text": "^8.1.0", - "@types/mocha": "^7.0.2", - "@types/node": "^18.18.7", - "@types/node-fetch": "2.6.7", - "@types/semver": "^7.3.9", - "@types/uuid": "^9.0.1", - "@types/vscode": "1.93.0", - "@typescript-eslint/eslint-plugin": "^5.53.0", - "@vscode/test-electron": "^2.3.8", - "eslint": "^8.34.0", - "eslint-plugin-import": "^2.22.1", - "glob": "^7.1.6", - "mocha": "^9.1.3", - "mocha-junit-reporter": "^2.0.2", - "mocha-multi-reporters": "^1.1.7", - "typescript": "^4.9.4" + "@azure/ms-rest-azure-env": "^2.0.0" } }, "@microsoft/vscode-azext-azureutils": { diff --git a/package.json b/package.json index b73c4217..32915767 100644 --- a/package.json +++ b/package.json @@ -713,7 +713,7 @@ "@azure/arm-resources": "^5.2.0", "@azure/arm-resources-profile-2020-09-01-hybrid": "^2.1.0", "@azure/ms-rest-js": "^2.7.0", - "@microsoft/vscode-azext-azureauth": "file:../vscode-azuretools/auth", + "@microsoft/vscode-azext-azureauth": "^3.1.0", "@microsoft/vscode-azext-azureutils": "^3.1.1", "@microsoft/vscode-azext-utils": "^2.5.7", "buffer": "^6.0.3",