mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-17 11:01:37 -05:00
Fix Browse azure tab not populating right tenant (#21276)
This commit is contained in:
@@ -29,3 +29,5 @@ export enum AzureResourceServiceNames {
|
|||||||
tenantService = 'AzureResourceTenantService',
|
tenantService = 'AzureResourceTenantService',
|
||||||
terminalService = 'AzureTerminalService',
|
terminalService = 'AzureTerminalService',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const mssqlProvider = 'MSSQL';
|
||||||
|
|||||||
@@ -3,12 +3,12 @@
|
|||||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
* 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 vscode from 'vscode';
|
||||||
import * as nls from 'vscode-nls';
|
import * as nls from 'vscode-nls';
|
||||||
const localize = nls.loadMessageBundle();
|
const localize = nls.loadMessageBundle();
|
||||||
|
|
||||||
import { AzureResourceItemType } from '../../../azureResource/constants';
|
import { AzureResourceItemType, mssqlProvider } from '../../../azureResource/constants';
|
||||||
import { generateGuid } from '../../utils';
|
import { generateGuid } from '../../utils';
|
||||||
import { IAzureResourceService } from '../../interfaces';
|
import { IAzureResourceService } from '../../interfaces';
|
||||||
import { ResourceTreeDataProviderBase } from '../resourceTreeDataProviderBase';
|
import { ResourceTreeDataProviderBase } from '../resourceTreeDataProviderBase';
|
||||||
@@ -42,11 +42,11 @@ export class AzureResourceDatabaseTreeDataProvider extends ResourceTreeDataProvi
|
|||||||
databaseName: database.name,
|
databaseName: database.name,
|
||||||
userName: database.loginName,
|
userName: database.loginName,
|
||||||
password: '',
|
password: '',
|
||||||
authenticationType: '',
|
authenticationType: connection.AuthenticationType.AzureMFA,
|
||||||
savePassword: true,
|
savePassword: true,
|
||||||
groupFullName: '',
|
groupFullName: '',
|
||||||
groupId: '',
|
groupId: '',
|
||||||
providerName: 'MSSQL',
|
providerName: mssqlProvider,
|
||||||
saveProfile: false,
|
saveProfile: false,
|
||||||
options: {},
|
options: {},
|
||||||
azureAccount: account.key.accountId,
|
azureAccount: account.key.accountId,
|
||||||
@@ -54,7 +54,7 @@ export class AzureResourceDatabaseTreeDataProvider extends ResourceTreeDataProvi
|
|||||||
azureTenantId: database.tenant,
|
azureTenantId: database.tenant,
|
||||||
azurePortalEndpoint: account.properties.providerSettings.settings.portalEndpoint
|
azurePortalEndpoint: account.properties.providerSettings.settings.portalEndpoint
|
||||||
},
|
},
|
||||||
childProvider: 'MSSQL',
|
childProvider: mssqlProvider,
|
||||||
type: ExtensionNodeType.Database
|
type: ExtensionNodeType.Database
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,12 +3,12 @@
|
|||||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
* 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 vscode from 'vscode';
|
||||||
import * as nls from 'vscode-nls';
|
import * as nls from 'vscode-nls';
|
||||||
const localize = nls.loadMessageBundle();
|
const localize = nls.loadMessageBundle();
|
||||||
|
|
||||||
import { AzureResourceItemType } from '../../../azureResource/constants';
|
import { AzureResourceItemType, mssqlProvider } from '../../../azureResource/constants';
|
||||||
import { generateGuid } from '../../utils';
|
import { generateGuid } from '../../utils';
|
||||||
import { IAzureResourceService } from '../../interfaces';
|
import { IAzureResourceService } from '../../interfaces';
|
||||||
import { ResourceTreeDataProviderBase } from '../resourceTreeDataProviderBase';
|
import { ResourceTreeDataProviderBase } from '../resourceTreeDataProviderBase';
|
||||||
@@ -43,11 +43,11 @@ export class AzureResourceDatabaseServerTreeDataProvider extends ResourceTreeDat
|
|||||||
databaseName: databaseServer.defaultDatabaseName,
|
databaseName: databaseServer.defaultDatabaseName,
|
||||||
userName: databaseServer.loginName,
|
userName: databaseServer.loginName,
|
||||||
password: '',
|
password: '',
|
||||||
authenticationType: '',
|
authenticationType: connection.AuthenticationType.AzureMFA,
|
||||||
savePassword: true,
|
savePassword: true,
|
||||||
groupFullName: '',
|
groupFullName: '',
|
||||||
groupId: '',
|
groupId: '',
|
||||||
providerName: 'MSSQL',
|
providerName: mssqlProvider,
|
||||||
saveProfile: false,
|
saveProfile: false,
|
||||||
options: {},
|
options: {},
|
||||||
azureAccount: account.key.accountId,
|
azureAccount: account.key.accountId,
|
||||||
@@ -55,7 +55,7 @@ export class AzureResourceDatabaseServerTreeDataProvider extends ResourceTreeDat
|
|||||||
azureResourceId: databaseServer.id,
|
azureResourceId: databaseServer.id,
|
||||||
azurePortalEndpoint: account.properties.providerSettings.settings.portalEndpoint
|
azurePortalEndpoint: account.properties.providerSettings.settings.portalEndpoint
|
||||||
},
|
},
|
||||||
childProvider: 'MSSQL',
|
childProvider: mssqlProvider,
|
||||||
type: ExtensionNodeType.Server
|
type: ExtensionNodeType.Server
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { TreeItemCollapsibleState, ExtensionContext } from 'vscode';
|
|||||||
import * as nls from 'vscode-nls';
|
import * as nls from 'vscode-nls';
|
||||||
const localize = nls.loadMessageBundle();
|
const localize = nls.loadMessageBundle();
|
||||||
|
|
||||||
import { AzureResourceItemType } from '../../constants';
|
import { AzureResourceItemType, mssqlProvider } from '../../constants';
|
||||||
import { generateGuid } from '../../utils';
|
import { generateGuid } from '../../utils';
|
||||||
import { IAzureResourceService } from '../../interfaces';
|
import { IAzureResourceService } from '../../interfaces';
|
||||||
import { ResourceTreeDataProviderBase } from '../resourceTreeDataProviderBase';
|
import { ResourceTreeDataProviderBase } from '../resourceTreeDataProviderBase';
|
||||||
@@ -47,7 +47,7 @@ export class SqlInstanceTreeDataProvider extends ResourceTreeDataProviderBase<az
|
|||||||
savePassword: true,
|
savePassword: true,
|
||||||
groupFullName: '',
|
groupFullName: '',
|
||||||
groupId: '',
|
groupId: '',
|
||||||
providerName: 'MSSQL',
|
providerName: mssqlProvider,
|
||||||
saveProfile: false,
|
saveProfile: false,
|
||||||
options: {},
|
options: {},
|
||||||
azureAccount: account.key.accountId,
|
azureAccount: account.key.accountId,
|
||||||
@@ -55,7 +55,7 @@ export class SqlInstanceTreeDataProvider extends ResourceTreeDataProviderBase<az
|
|||||||
azureResourceId: databaseServer.id,
|
azureResourceId: databaseServer.id,
|
||||||
azurePortalEndpoint: account.properties.providerSettings.settings.portalEndpoint
|
azurePortalEndpoint: account.properties.providerSettings.settings.portalEndpoint
|
||||||
},
|
},
|
||||||
childProvider: 'MSSQL',
|
childProvider: mssqlProvider,
|
||||||
type: ExtensionNodeType.Server
|
type: ExtensionNodeType.Server
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { TreeItemCollapsibleState, ExtensionContext } from 'vscode';
|
|||||||
import * as nls from 'vscode-nls';
|
import * as nls from 'vscode-nls';
|
||||||
const localize = nls.loadMessageBundle();
|
const localize = nls.loadMessageBundle();
|
||||||
|
|
||||||
import { AzureResourceItemType } from '../../constants';
|
import { AzureResourceItemType, mssqlProvider } from '../../constants';
|
||||||
import { generateGuid } from '../../utils';
|
import { generateGuid } from '../../utils';
|
||||||
import { IAzureResourceService } from '../../interfaces';
|
import { IAzureResourceService } from '../../interfaces';
|
||||||
import { ResourceTreeDataProviderBase } from '../resourceTreeDataProviderBase';
|
import { ResourceTreeDataProviderBase } from '../resourceTreeDataProviderBase';
|
||||||
@@ -48,7 +48,7 @@ export class SqlInstanceArcTreeDataProvider extends ResourceTreeDataProviderBase
|
|||||||
savePassword: true,
|
savePassword: true,
|
||||||
groupFullName: '',
|
groupFullName: '',
|
||||||
groupId: '',
|
groupId: '',
|
||||||
providerName: 'MSSQL',
|
providerName: mssqlProvider,
|
||||||
saveProfile: false,
|
saveProfile: false,
|
||||||
options: {},
|
options: {},
|
||||||
azureAccount: account.key.accountId,
|
azureAccount: account.key.accountId,
|
||||||
@@ -56,7 +56,7 @@ export class SqlInstanceArcTreeDataProvider extends ResourceTreeDataProviderBase
|
|||||||
azureResourceId: databaseServer.id,
|
azureResourceId: databaseServer.id,
|
||||||
azurePortalEndpoint: account.properties.providerSettings.settings.portalEndpoint
|
azurePortalEndpoint: account.properties.providerSettings.settings.portalEndpoint
|
||||||
},
|
},
|
||||||
childProvider: 'MSSQL',
|
childProvider: mssqlProvider,
|
||||||
type: ExtensionNodeType.Server
|
type: ExtensionNodeType.Server
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import { AzureAccount, azureResource } from 'azurecore';
|
|||||||
import { AzureResourceService } from '../resourceService';
|
import { AzureResourceService } from '../resourceService';
|
||||||
import { AzureResourceResourceTreeNode } from '../resourceTreeNode';
|
import { AzureResourceResourceTreeNode } from '../resourceTreeNode';
|
||||||
import { AzureResourceErrorMessageUtil } from '../utils';
|
import { AzureResourceErrorMessageUtil } from '../utils';
|
||||||
|
import { Logger } from '../../utils/Logger';
|
||||||
|
|
||||||
export class FlatAccountTreeNode extends AzureResourceContainerTreeNodeBase {
|
export class FlatAccountTreeNode extends AzureResourceContainerTreeNodeBase {
|
||||||
public constructor(
|
public constructor(
|
||||||
@@ -178,14 +179,24 @@ class FlatAccountTreeNodeLoader {
|
|||||||
}
|
}
|
||||||
}, 500);
|
}, 500);
|
||||||
try {
|
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;
|
let subscriptions: azureResource.AzureResourceSubscription[] = (await getSubscriptionInfo(this._account, this._subscriptionService, this._subscriptionFilterService)).subscriptions;
|
||||||
|
|
||||||
if (subscriptions.length !== 0) {
|
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 => {
|
subscriptions = subscriptions.filter(async s => {
|
||||||
const token = await azdata.accounts.getAccountSecurityToken(this._account, s.tenant!, azdata.AzureResource.ResourceManagement);
|
const tenant = tenants.find(t => t.id === s.tenant);
|
||||||
if (!token) {
|
if (!tenant) {
|
||||||
console.info(`Account does not have permissions to view subscription ${JSON.stringify(s)}.`);
|
Logger.info(`Account does not have permissions to view subscription ${JSON.stringify(s)}.`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user