Fix Browse azure tab not populating right tenant (#21276)

This commit is contained in:
Cheena Malhotra
2022-11-19 00:49:56 -08:00
committed by GitHub
parent 0bc5f68d29
commit dec3c020c5
6 changed files with 33 additions and 20 deletions

View File

@@ -20,6 +20,7 @@ import { AzureAccount, azureResource } from 'azurecore';
import { AzureResourceService } from '../resourceService';
import { AzureResourceResourceTreeNode } from '../resourceTreeNode';
import { AzureResourceErrorMessageUtil } from '../utils';
import { Logger } from '../../utils/Logger';
export class FlatAccountTreeNode extends AzureResourceContainerTreeNodeBase {
public constructor(
@@ -178,14 +179,24 @@ class FlatAccountTreeNodeLoader {
}
}, 500);
try {
// Authenticate to tenants to filter out subscriptions that are not accessible.
let tenants = this._account.properties.tenants;
// Filter out tenants that we can't authenticate to.
tenants = tenants.filter(async tenant => {
const token = await azdata.accounts.getAccountSecurityToken(this._account, tenant.id, azdata.AzureResource.ResourceManagement);
return token !== undefined;
});
let subscriptions: azureResource.AzureResourceSubscription[] = (await getSubscriptionInfo(this._account, this._subscriptionService, this._subscriptionFilterService)).subscriptions;
if (subscriptions.length !== 0) {
// Filter out everything that we can't authenticate to.
// Filter out subscriptions that don't belong to the tenants we filtered above.
subscriptions = subscriptions.filter(async s => {
const token = await azdata.accounts.getAccountSecurityToken(this._account, s.tenant!, azdata.AzureResource.ResourceManagement);
if (!token) {
console.info(`Account does not have permissions to view subscription ${JSON.stringify(s)}.`);
const tenant = tenants.find(t => t.id === s.tenant);
if (!tenant) {
Logger.info(`Account does not have permissions to view subscription ${JSON.stringify(s)}.`);
return false;
}
return true;