diff --git a/extensions/azurecore/src/azureResource/constants.ts b/extensions/azurecore/src/azureResource/constants.ts index 96c151029e..505ef25642 100644 --- a/extensions/azurecore/src/azureResource/constants.ts +++ b/extensions/azurecore/src/azureResource/constants.ts @@ -29,3 +29,5 @@ export enum AzureResourceServiceNames { tenantService = 'AzureResourceTenantService', terminalService = 'AzureTerminalService', } + +export const mssqlProvider = 'MSSQL'; diff --git a/extensions/azurecore/src/azureResource/providers/database/databaseTreeDataProvider.ts b/extensions/azurecore/src/azureResource/providers/database/databaseTreeDataProvider.ts index 58a8c0de16..48793cfaf1 100644 --- a/extensions/azurecore/src/azureResource/providers/database/databaseTreeDataProvider.ts +++ b/extensions/azurecore/src/azureResource/providers/database/databaseTreeDataProvider.ts @@ -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 }; } diff --git a/extensions/azurecore/src/azureResource/providers/databaseServer/databaseServerTreeDataProvider.ts b/extensions/azurecore/src/azureResource/providers/databaseServer/databaseServerTreeDataProvider.ts index d0323a4786..3464d1d592 100644 --- a/extensions/azurecore/src/azureResource/providers/databaseServer/databaseServerTreeDataProvider.ts +++ b/extensions/azurecore/src/azureResource/providers/databaseServer/databaseServerTreeDataProvider.ts @@ -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 }; } diff --git a/extensions/azurecore/src/azureResource/providers/sqlinstance/sqlInstanceTreeDataProvider.ts b/extensions/azurecore/src/azureResource/providers/sqlinstance/sqlInstanceTreeDataProvider.ts index 1f03b807ab..2f8c98f8ad 100644 --- a/extensions/azurecore/src/azureResource/providers/sqlinstance/sqlInstanceTreeDataProvider.ts +++ b/extensions/azurecore/src/azureResource/providers/sqlinstance/sqlInstanceTreeDataProvider.ts @@ -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 { + 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;