mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-17 02:51:36 -05:00
Fix getUriForConnection API returning wrong URIs (#2202)
* Fix connection URI api to return working URI * run tsfmt * Keep using hand-built connection string for now in import * Use connection ID instead of URI to get connection string
This commit is contained in:
committed by
Karl Burtram
parent
efa3658ced
commit
3001640eec
@@ -159,7 +159,8 @@ export class GetCurrentConnectionStringAction extends Action {
|
|||||||
if (activeInput && (activeInput instanceof QueryInput || activeInput instanceof EditDataInput || activeInput instanceof DashboardInput)
|
if (activeInput && (activeInput instanceof QueryInput || activeInput instanceof EditDataInput || activeInput instanceof DashboardInput)
|
||||||
&& this._connectionManagementService.isConnected(activeInput.uri)) {
|
&& this._connectionManagementService.isConnected(activeInput.uri)) {
|
||||||
let includePassword = false;
|
let includePassword = false;
|
||||||
this._connectionManagementService.getConnectionString(activeInput.uri, includePassword).then(result => {
|
let connectionProfile = this._connectionManagementService.getConnectionProfile(activeInput.uri);
|
||||||
|
this._connectionManagementService.getConnectionString(connectionProfile.id, includePassword).then(result => {
|
||||||
let message = result
|
let message = result
|
||||||
? result
|
? result
|
||||||
: nls.localize('connectionAction.connectionString', "Connection string not available");
|
: nls.localize('connectionAction.connectionString', "Connection string not available");
|
||||||
|
|||||||
@@ -263,9 +263,9 @@ export interface IConnectionManagementService {
|
|||||||
getActiveConnectionCredentials(profileId: string): { [name: string]: string };
|
getActiveConnectionCredentials(profileId: string): { [name: string]: string };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the connection string for the provided connection profile
|
* Get the connection string for the provided connection ID
|
||||||
*/
|
*/
|
||||||
getConnectionString(ownerUri: string, includePassword: boolean): Thenable<string>;
|
getConnectionString(connectionId: string, includePassword: boolean): Thenable<string>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Serialize connection string with optional provider
|
* Serialize connection string with optional provider
|
||||||
|
|||||||
@@ -649,9 +649,9 @@ export class ConnectionManagementService extends Disposable implements IConnecti
|
|||||||
}
|
}
|
||||||
|
|
||||||
public getConnectionUriFromId(connectionId: string): string {
|
public getConnectionUriFromId(connectionId: string): string {
|
||||||
let connection = this.getActiveConnections().find(connection => connection.id === connectionId);
|
let connectionInfo = this._connectionStatusManager.findConnectionByProfileId(connectionId);
|
||||||
if (connection) {
|
if (connectionInfo) {
|
||||||
return this.getConnectionUri(connection);
|
return connectionInfo.ownerUri;
|
||||||
} else {
|
} else {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
@@ -1348,9 +1348,11 @@ export class ConnectionManagementService extends Disposable implements IConnecti
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the connection string for the provided connection profile
|
* Get the connection string for the provided connection ID
|
||||||
*/
|
*/
|
||||||
public getConnectionString(ownerUri: string, includePassword: boolean = false): Thenable<string> {
|
public getConnectionString(connectionId: string, includePassword: boolean = false): Thenable<string> {
|
||||||
|
let ownerUri = this.getConnectionUriFromId(connectionId);
|
||||||
|
|
||||||
if (!ownerUri) {
|
if (!ownerUri) {
|
||||||
return Promise.resolve(undefined);
|
return Promise.resolve(undefined);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,14 +22,18 @@ export class ConnectionStatusManager {
|
|||||||
this._providerCapabilitiesMap = {};
|
this._providerCapabilitiesMap = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
public findConnection(id: string): ConnectionManagementInfo {
|
public findConnection(uri: string): ConnectionManagementInfo {
|
||||||
if (id in this._connections) {
|
if (uri in this._connections) {
|
||||||
return this._connections[id];
|
return this._connections[uri];
|
||||||
} else {
|
} else {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public findConnectionByProfileId(profileId: string): ConnectionManagementInfo {
|
||||||
|
return Object.values(this._connections).find((connection: ConnectionManagementInfo) => connection.connectionProfile.id === profileId);
|
||||||
|
}
|
||||||
|
|
||||||
public findConnectionProfile(connectionProfile: IConnectionProfile): ConnectionManagementInfo {
|
public findConnectionProfile(connectionProfile: IConnectionProfile): ConnectionManagementInfo {
|
||||||
let id = Utils.generateUri(connectionProfile);
|
let id = Utils.generateUri(connectionProfile);
|
||||||
return this.findConnection(id);
|
return this.findConnection(id);
|
||||||
|
|||||||
@@ -61,15 +61,13 @@ export class MainThreadConnectionManagement implements MainThreadConnectionManag
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async $listDatabases(connectionId: string): Promise<string[]> {
|
public async $listDatabases(connectionId: string): Promise<string[]> {
|
||||||
let connection = this._connectionManagementService.getActiveConnections().find(profile => profile.id === connectionId);
|
let connectionUri = await this.$getUriForConnection(connectionId);
|
||||||
let connectionUri = this._connectionManagementService.getConnectionUri(connection);
|
|
||||||
let result = await this._connectionManagementService.listDatabases(connectionUri);
|
let result = await this._connectionManagementService.listDatabases(connectionUri);
|
||||||
return result.databaseNames;
|
return result.databaseNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async $getConnectionString(connectionId: string, includePassword: boolean): Promise<string> {
|
public async $getConnectionString(connectionId: string, includePassword: boolean): Promise<string> {
|
||||||
let connection = this._connectionManagementService.getActiveConnections().find(profile => profile.id === connectionId);
|
return this._connectionManagementService.getConnectionString(connectionId, includePassword);
|
||||||
return await this._connectionManagementService.getConnectionString(connectionId, includePassword);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public $getUriForConnection(connectionId: string): Thenable<string> {
|
public $getUriForConnection(connectionId: string): Thenable<string> {
|
||||||
|
|||||||
@@ -816,8 +816,8 @@ suite('SQL ConnectionManagementService tests', () => {
|
|||||||
// If I call getConnectionUriFromId on the given connection
|
// If I call getConnectionUriFromId on the given connection
|
||||||
let foundUri = connectionManagementService.getConnectionUriFromId(profile.id);
|
let foundUri = connectionManagementService.getConnectionUriFromId(profile.id);
|
||||||
|
|
||||||
// Then the returned URI matches the connection's
|
// Then the returned URI matches the connection's original URI
|
||||||
assert.equal(foundUri, Utils.generateUri(new ConnectionProfile(capabilitiesService, profile)));
|
assert.equal(foundUri, uri);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('getConectionUriFromId returns undefined if the given connection is not active', () => {
|
test('getConectionUriFromId returns undefined if the given connection is not active', () => {
|
||||||
|
|||||||
@@ -254,7 +254,7 @@ export class TestConnectionManagementService implements IConnectionManagementSer
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
getConnectionString(ownerUri: string): Thenable<string> {
|
getConnectionString(connectionId: string): Thenable<string> {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user