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

@@ -29,3 +29,5 @@ export enum AzureResourceServiceNames {
tenantService = 'AzureResourceTenantService',
terminalService = 'AzureTerminalService',
}
export const mssqlProvider = 'MSSQL';

View File

@@ -3,12 +3,12 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { TreeItem, ExtensionNodeType } from 'azdata';
import { connection, TreeItem, ExtensionNodeType } from 'azdata';
import * as vscode from 'vscode';
import * as nls from 'vscode-nls';
const localize = nls.loadMessageBundle();
import { AzureResourceItemType } from '../../../azureResource/constants';
import { AzureResourceItemType, mssqlProvider } from '../../../azureResource/constants';
import { generateGuid } from '../../utils';
import { IAzureResourceService } from '../../interfaces';
import { ResourceTreeDataProviderBase } from '../resourceTreeDataProviderBase';
@@ -42,11 +42,11 @@ export class AzureResourceDatabaseTreeDataProvider extends ResourceTreeDataProvi
databaseName: database.name,
userName: database.loginName,
password: '',
authenticationType: '',
authenticationType: connection.AuthenticationType.AzureMFA,
savePassword: true,
groupFullName: '',
groupId: '',
providerName: 'MSSQL',
providerName: mssqlProvider,
saveProfile: false,
options: {},
azureAccount: account.key.accountId,
@@ -54,7 +54,7 @@ export class AzureResourceDatabaseTreeDataProvider extends ResourceTreeDataProvi
azureTenantId: database.tenant,
azurePortalEndpoint: account.properties.providerSettings.settings.portalEndpoint
},
childProvider: 'MSSQL',
childProvider: mssqlProvider,
type: ExtensionNodeType.Database
};
}

View File

@@ -3,12 +3,12 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { ExtensionNodeType, TreeItem } from 'azdata';
import { connection, ExtensionNodeType, TreeItem } from 'azdata';
import * as vscode from 'vscode';
import * as nls from 'vscode-nls';
const localize = nls.loadMessageBundle();
import { AzureResourceItemType } from '../../../azureResource/constants';
import { AzureResourceItemType, mssqlProvider } from '../../../azureResource/constants';
import { generateGuid } from '../../utils';
import { IAzureResourceService } from '../../interfaces';
import { ResourceTreeDataProviderBase } from '../resourceTreeDataProviderBase';
@@ -43,11 +43,11 @@ export class AzureResourceDatabaseServerTreeDataProvider extends ResourceTreeDat
databaseName: databaseServer.defaultDatabaseName,
userName: databaseServer.loginName,
password: '',
authenticationType: '',
authenticationType: connection.AuthenticationType.AzureMFA,
savePassword: true,
groupFullName: '',
groupId: '',
providerName: 'MSSQL',
providerName: mssqlProvider,
saveProfile: false,
options: {},
azureAccount: account.key.accountId,
@@ -55,7 +55,7 @@ export class AzureResourceDatabaseServerTreeDataProvider extends ResourceTreeDat
azureResourceId: databaseServer.id,
azurePortalEndpoint: account.properties.providerSettings.settings.portalEndpoint
},
childProvider: 'MSSQL',
childProvider: mssqlProvider,
type: ExtensionNodeType.Server
};
}

View File

@@ -8,7 +8,7 @@ import { TreeItemCollapsibleState, ExtensionContext } from 'vscode';
import * as nls from 'vscode-nls';
const localize = nls.loadMessageBundle();
import { AzureResourceItemType } from '../../constants';
import { AzureResourceItemType, mssqlProvider } from '../../constants';
import { generateGuid } from '../../utils';
import { IAzureResourceService } from '../../interfaces';
import { ResourceTreeDataProviderBase } from '../resourceTreeDataProviderBase';
@@ -47,7 +47,7 @@ export class SqlInstanceTreeDataProvider extends ResourceTreeDataProviderBase<az
savePassword: true,
groupFullName: '',
groupId: '',
providerName: 'MSSQL',
providerName: mssqlProvider,
saveProfile: false,
options: {},
azureAccount: account.key.accountId,
@@ -55,7 +55,7 @@ export class SqlInstanceTreeDataProvider extends ResourceTreeDataProviderBase<az
azureResourceId: databaseServer.id,
azurePortalEndpoint: account.properties.providerSettings.settings.portalEndpoint
},
childProvider: 'MSSQL',
childProvider: mssqlProvider,
type: ExtensionNodeType.Server
};
}

View File

@@ -8,7 +8,7 @@ import { TreeItemCollapsibleState, ExtensionContext } from 'vscode';
import * as nls from 'vscode-nls';
const localize = nls.loadMessageBundle();
import { AzureResourceItemType } from '../../constants';
import { AzureResourceItemType, mssqlProvider } from '../../constants';
import { generateGuid } from '../../utils';
import { IAzureResourceService } from '../../interfaces';
import { ResourceTreeDataProviderBase } from '../resourceTreeDataProviderBase';
@@ -48,7 +48,7 @@ export class SqlInstanceArcTreeDataProvider extends ResourceTreeDataProviderBase
savePassword: true,
groupFullName: '',
groupId: '',
providerName: 'MSSQL',
providerName: mssqlProvider,
saveProfile: false,
options: {},
azureAccount: account.key.accountId,
@@ -56,7 +56,7 @@ export class SqlInstanceArcTreeDataProvider extends ResourceTreeDataProviderBase
azureResourceId: databaseServer.id,
azurePortalEndpoint: account.properties.providerSettings.settings.portalEndpoint
},
childProvider: 'MSSQL',
childProvider: mssqlProvider,
type: ExtensionNodeType.Server
};
}

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;