Fix connection issue with wrong resource endpoint (#19387)

* Fix connection bug accessing PBI resource

* Address CR feedback

* Fix null check
This commit is contained in:
Karl Burtram
2022-05-16 15:23:23 -07:00
committed by GitHub
parent d7ecdd89b1
commit 701f656c55
6 changed files with 69 additions and 4 deletions

6
src/sql/azdata.d.ts vendored
View File

@@ -2354,7 +2354,11 @@ declare module 'azdata' {
/**
* Kusto
*/
AzureKusto = 10
AzureKusto = 10,
/**
* Power BI
*/
PowerBi = 11
}
export interface DidChangeAccountsParams {

View File

@@ -443,7 +443,8 @@ export enum AzureResource {
MsGraph = 7,
AzureLogAnalytics = 8,
AzureStorage = 9,
AzureKusto = 10
AzureKusto = 10,
PowerBi = 11
}
export class TreeItem extends vsExtTypes.TreeItem {

View File

@@ -809,15 +809,45 @@ export class ConnectionManagementService extends Disposable implements IConnecti
* @param connection The connection to fill in or update
*/
private getAzureResourceForConnection(connection: interfaces.IConnectionProfile): azdata.AzureResource {
// check if this is a PowerBI connection which is determined based on connection domain address
if (this.isPowerBiConnection(connection)) {
return AzureResource.PowerBi;
}
// default to SQL if there are no provides or registered resources
let provider = this._providers.get(connection.providerName);
if (!provider || !provider.properties || !provider.properties.azureResource) {
this._logService.warn('Connection providers incorrectly registered. Defaulting to SQL Azure resource,');
return AzureResource.Sql;
}
// lookup the Azure resource based on the provider azureResource properties
let result = ConnectionManagementService._azureResources.find(r => AzureResource[r] === provider.properties.azureResource);
return result ? result : AzureResource.Sql;
}
/**
* Determine if a connection is to PowerBI based on the servers domain name.
* PowerBi servers will be in one of the hard-coded domains listed in this method, based on the
* Azure cloud being used. This method can be removed once the connection/AAD service is updated
* to parse the server endpoint using TDS prior to connecting. But that will need to be part of a
* larger refactoring of the connection & auth functionality.
* @param connection The connection profile that is to be checked.
*/
private isPowerBiConnection(connection: interfaces.IConnectionProfile): boolean {
if (!connection || !connection.serverName || connection.serverName.length === 0) {
return false;
}
let powerBiDomains = [
'pbidedicated.windows.net',
'pbidedicated.cloudapi.de',
'pbidedicated.usgovcloudapi.net',
'pbidedicated.chinacloudapi.cn'
];
let serverName = connection.serverName.toLowerCase();
return !!powerBiDomains.find(d => serverName.indexOf(d) >= 0);
}
/**
* Fills in the account token if it's needed for this connection and doesn't already have one
* and clears it if it isn't.