Introduce connection API (#598)

Including getCurrentConnection, getActiveConnections, and getCredentials
This commit is contained in:
Matt Irvine
2018-02-06 15:56:49 -08:00
committed by GitHub
parent f5aa49ebb9
commit 3df522536f
15 changed files with 264 additions and 3 deletions

View File

@@ -253,6 +253,21 @@ export interface IConnectionManagementService {
* Refresh the IntelliSense cache for the connection with the given URI
*/
rebuildIntelliSenseCache(uri: string): Thenable<void>;
/**
* Get a copy of the connection profile with its passwords removed
* @param {IConnectionProfile} profile The connection profile to remove passwords from
* @returns {IConnectionProfile} A copy of the connection profile with passwords removed
*/
removeConnectionProfileCredentials(profile: IConnectionProfile): IConnectionProfile;
/**
* Get the credentials for a connected connection profile, as they would appear in the options dictionary
* @param {string} profileId The id of the connection profile to get the password for
* @returns {{ [name: string]: string }} A dictionary containing the credentials as they would be included
* in the connection profile's options dictionary, or undefined if the profile is not connected
*/
getActiveConnectionCredentials(profileId: string): { [name: string]: string };
}
export const IConnectionDialogService = createDecorator<IConnectionDialogService>('connectionDialogService');

View File

@@ -56,6 +56,7 @@ import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
import { IStatusbarService } from 'vs/platform/statusbar/common/statusbar';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { Deferred } from 'sql/base/common/promise';
import { ConnectionOptionSpecialType } from 'sql/workbench/api/common/sqlExtHostTypes';
export class ConnectionManagementService implements IConnectionManagementService {
@@ -659,7 +660,7 @@ export class ConnectionManagementService implements IConnectionManagementService
}
public getActiveConnections(): ConnectionProfile[] {
return this._connectionStore.getActiveConnections();
return this._connectionStatusManager.getActiveConnectionProfiles();
}
public saveProfileGroup(profile: IConnectionProfileGroup): Promise<string> {
@@ -1351,4 +1352,26 @@ export class ConnectionManagementService implements IConnectionManagementService
this._editorGroupService.refreshEditorTitles();
}
}
public removeConnectionProfileCredentials(originalProfile: IConnectionProfile): IConnectionProfile {
return this._connectionStore.getProfileWithoutPassword(originalProfile);
}
public getActiveConnectionCredentials(profileId: string): { [name: string]: string } {
let profile = this.getActiveConnections().find(connectionProfile => connectionProfile.id === profileId);
if (!profile) {
return undefined;
}
// Find the password option for the connection provider
let passwordOption = this._capabilitiesService.getCapabilities().find(capability => capability.providerName === profile.providerName).connectionProvider.options.find(
option => option.specialValueType === ConnectionOptionSpecialType.password);
if (!passwordOption) {
return undefined;
}
let credentials = {};
credentials[passwordOption.name] = profile.options[passwordOption.name];
return credentials;
}
}

View File

@@ -209,4 +209,13 @@ export class ConnectionStatusManager {
}
return providerId;
}
/**
* Get a list of the active connection profiles managed by the status manager
*/
public getActiveConnectionProfiles(): ConnectionProfile[] {
let profiles = Object.values(this._connections).map((connectionInfo: ConnectionManagementInfo) => connectionInfo.connectionProfile);
// Remove duplicate profiles that may be listed multiple times under different URIs by filtering for profiles that don't have the same ID as an earlier profile in the list
return profiles.filter((profile, index) => profiles.findIndex(otherProfile => otherProfile.id === profile.id) === index);
}
}

View File

@@ -19,6 +19,7 @@ import { ConfigurationEditingService } from 'vs/workbench/services/configuration
import { IWorkspaceConfigurationService } from 'vs/workbench/services/configuration/common/configuration';
import { ICapabilitiesService } from 'sql/services/capabilities/capabilitiesService';
import * as data from 'data';
import { ConnectionOptionSpecialType } from 'sql/workbench/api/common/sqlExtHostTypes';
const MAX_CONNECTIONS_DEFAULT = 25;