mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Introduce connection API (#598)
Including getCurrentConnection, getActiveConnections, and getCredentials
This commit is contained in:
37
src/sql/data.d.ts
vendored
37
src/sql/data.d.ts
vendored
@@ -71,6 +71,43 @@ declare module 'data' {
|
|||||||
export function registerProvider(provider: SerializationProvider): vscode.Disposable;
|
export function registerProvider(provider: SerializationProvider): vscode.Disposable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Namespace for connection management
|
||||||
|
*/
|
||||||
|
export namespace connection {
|
||||||
|
/**
|
||||||
|
* Get the current connection based on the active editor or Object Explorer selection
|
||||||
|
*/
|
||||||
|
export function getCurrentConnection(): Thenable<Connection>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all active connections
|
||||||
|
*/
|
||||||
|
export function getActiveConnections(): Thenable<Connection[]>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the credentials for an active connection
|
||||||
|
* @param {string} connectionId The id of the connection
|
||||||
|
* @returns {{ [name: string]: string}} A dictionary containing the credentials as they would be included in the connection's options dictionary
|
||||||
|
*/
|
||||||
|
export function getCredentials(connectionId: string): Thenable<{ [name: string]: string }>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface for representing a connection when working with connection APIs
|
||||||
|
*/
|
||||||
|
export interface Connection extends ConnectionInfo {
|
||||||
|
/**
|
||||||
|
* The name of the provider managing the connection (e.g. MSSQL)
|
||||||
|
*/
|
||||||
|
providerName: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A unique identifier for the connection
|
||||||
|
*/
|
||||||
|
connectionId: string;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// EXPORTED INTERFACES /////////////////////////////////////////////////
|
// EXPORTED INTERFACES /////////////////////////////////////////////////
|
||||||
export interface ConnectionInfo {
|
export interface ConnectionInfo {
|
||||||
|
|
||||||
|
|||||||
@@ -253,6 +253,21 @@ export interface IConnectionManagementService {
|
|||||||
* Refresh the IntelliSense cache for the connection with the given URI
|
* Refresh the IntelliSense cache for the connection with the given URI
|
||||||
*/
|
*/
|
||||||
rebuildIntelliSenseCache(uri: string): Thenable<void>;
|
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');
|
export const IConnectionDialogService = createDecorator<IConnectionDialogService>('connectionDialogService');
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
|
|||||||
import { IStatusbarService } from 'vs/platform/statusbar/common/statusbar';
|
import { IStatusbarService } from 'vs/platform/statusbar/common/statusbar';
|
||||||
import { ICommandService } from 'vs/platform/commands/common/commands';
|
import { ICommandService } from 'vs/platform/commands/common/commands';
|
||||||
import { Deferred } from 'sql/base/common/promise';
|
import { Deferred } from 'sql/base/common/promise';
|
||||||
|
import { ConnectionOptionSpecialType } from 'sql/workbench/api/common/sqlExtHostTypes';
|
||||||
|
|
||||||
export class ConnectionManagementService implements IConnectionManagementService {
|
export class ConnectionManagementService implements IConnectionManagementService {
|
||||||
|
|
||||||
@@ -659,7 +660,7 @@ export class ConnectionManagementService implements IConnectionManagementService
|
|||||||
}
|
}
|
||||||
|
|
||||||
public getActiveConnections(): ConnectionProfile[] {
|
public getActiveConnections(): ConnectionProfile[] {
|
||||||
return this._connectionStore.getActiveConnections();
|
return this._connectionStatusManager.getActiveConnectionProfiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
public saveProfileGroup(profile: IConnectionProfileGroup): Promise<string> {
|
public saveProfileGroup(profile: IConnectionProfileGroup): Promise<string> {
|
||||||
@@ -1351,4 +1352,26 @@ export class ConnectionManagementService implements IConnectionManagementService
|
|||||||
this._editorGroupService.refreshEditorTitles();
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -209,4 +209,13 @@ export class ConnectionStatusManager {
|
|||||||
}
|
}
|
||||||
return providerId;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -19,6 +19,7 @@ import { ConfigurationEditingService } from 'vs/workbench/services/configuration
|
|||||||
import { IWorkspaceConfigurationService } from 'vs/workbench/services/configuration/common/configuration';
|
import { IWorkspaceConfigurationService } from 'vs/workbench/services/configuration/common/configuration';
|
||||||
import { ICapabilitiesService } from 'sql/services/capabilities/capabilitiesService';
|
import { ICapabilitiesService } from 'sql/services/capabilities/capabilitiesService';
|
||||||
import * as data from 'data';
|
import * as data from 'data';
|
||||||
|
import { ConnectionOptionSpecialType } from 'sql/workbench/api/common/sqlExtHostTypes';
|
||||||
|
|
||||||
const MAX_CONNECTIONS_DEFAULT = 25;
|
const MAX_CONNECTIONS_DEFAULT = 25;
|
||||||
|
|
||||||
|
|||||||
33
src/sql/workbench/api/node/extHostConnectionManagement.ts
Normal file
33
src/sql/workbench/api/node/extHostConnectionManagement.ts
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
/*---------------------------------------------------------------------------------------------
|
||||||
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||||
|
*--------------------------------------------------------------------------------------------*/
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
import { IThreadService } from 'vs/workbench/services/thread/common/threadService';
|
||||||
|
import { ExtHostConnectionManagementShape, SqlMainContext, MainThreadConnectionManagementShape } from 'sql/workbench/api/node/sqlExtHost.protocol';
|
||||||
|
import * as data from 'data';
|
||||||
|
|
||||||
|
export class ExtHostConnectionManagement extends ExtHostConnectionManagementShape {
|
||||||
|
|
||||||
|
private _proxy: MainThreadConnectionManagementShape;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
threadService: IThreadService
|
||||||
|
) {
|
||||||
|
super();
|
||||||
|
this._proxy = threadService.get(SqlMainContext.MainThreadConnectionManagement);
|
||||||
|
}
|
||||||
|
|
||||||
|
public $getActiveConnections(): Thenable<data.connection.Connection[]> {
|
||||||
|
return this._proxy.$getActiveConnections();
|
||||||
|
}
|
||||||
|
|
||||||
|
public $getCurrentConnection(): Thenable<data.connection.Connection> {
|
||||||
|
return this._proxy.$getCurrentConnection();
|
||||||
|
}
|
||||||
|
|
||||||
|
public $getCredentials(connectionId: string): Thenable<{ [name: string]: string}> {
|
||||||
|
return this._proxy.$getCredentials(connectionId);
|
||||||
|
}
|
||||||
|
}
|
||||||
64
src/sql/workbench/api/node/mainThreadConnectionManagement.ts
Normal file
64
src/sql/workbench/api/node/mainThreadConnectionManagement.ts
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
/*---------------------------------------------------------------------------------------------
|
||||||
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||||
|
*--------------------------------------------------------------------------------------------*/
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
import { SqlExtHostContext, SqlMainContext, ExtHostConnectionManagementShape, MainThreadConnectionManagementShape } from 'sql/workbench/api/node/sqlExtHost.protocol';
|
||||||
|
import * as data from 'data';
|
||||||
|
import { IExtHostContext } from 'vs/workbench/api/node/extHost.protocol';
|
||||||
|
import { extHostNamedCustomer } from 'vs/workbench/api/electron-browser/extHostCustomers';
|
||||||
|
import { IConnectionManagementService } from 'sql/parts/connection/common/connectionManagement';
|
||||||
|
import { IObjectExplorerService } from 'sql/parts/registeredServer/common/objectExplorerService';
|
||||||
|
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
|
||||||
|
import * as TaskUtilities from 'sql/workbench/common/taskUtilities';
|
||||||
|
import { IConnectionProfile } from 'sql/parts/connection/common/interfaces';
|
||||||
|
import { dispose, IDisposable } from 'vs/base/common/lifecycle';
|
||||||
|
|
||||||
|
@extHostNamedCustomer(SqlMainContext.MainThreadConnectionManagement)
|
||||||
|
export class MainThreadConnectionManagement implements MainThreadConnectionManagementShape {
|
||||||
|
|
||||||
|
private _proxy: ExtHostConnectionManagementShape;
|
||||||
|
private _toDispose: IDisposable[];
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
extHostContext: IExtHostContext,
|
||||||
|
@IConnectionManagementService private _connectionManagementService: IConnectionManagementService,
|
||||||
|
@IObjectExplorerService private _objectExplorerService: IObjectExplorerService,
|
||||||
|
@IWorkbenchEditorService private _workbenchEditorService: IWorkbenchEditorService
|
||||||
|
) {
|
||||||
|
if (extHostContext) {
|
||||||
|
this._proxy = extHostContext.get(SqlExtHostContext.ExtHostConnectionManagement);
|
||||||
|
}
|
||||||
|
this._toDispose = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
public dispose(): void {
|
||||||
|
this._toDispose = dispose(this._toDispose);
|
||||||
|
}
|
||||||
|
|
||||||
|
public $getActiveConnections(): Thenable<data.connection.Connection[]> {
|
||||||
|
return Promise.resolve(this._connectionManagementService.getActiveConnections().map(profile => this.convertConnection(profile)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public $getCurrentConnection(): Thenable<data.connection.Connection> {
|
||||||
|
return Promise.resolve(this.convertConnection(TaskUtilities.getCurrentGlobalConnection(this._objectExplorerService, this._connectionManagementService, this._workbenchEditorService, true)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public $getCredentials(connectionId: string): Thenable<{ [name: string]: string }> {
|
||||||
|
return Promise.resolve(this._connectionManagementService.getActiveConnectionCredentials(connectionId));
|
||||||
|
}
|
||||||
|
|
||||||
|
private convertConnection(profile: IConnectionProfile): data.connection.Connection {
|
||||||
|
if (!profile) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
profile = this._connectionManagementService.removeConnectionProfileCredentials(profile);
|
||||||
|
let connection: data.connection.Connection = {
|
||||||
|
providerName: profile.providerName,
|
||||||
|
connectionId: profile.id,
|
||||||
|
options: profile.options
|
||||||
|
};
|
||||||
|
return connection;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -28,6 +28,7 @@ import { ExtHostConfiguration } from 'vs/workbench/api/node/extHostConfiguration
|
|||||||
import { ExtHostModalDialogs } from 'sql/workbench/api/node/extHostModalDialog';
|
import { ExtHostModalDialogs } from 'sql/workbench/api/node/extHostModalDialog';
|
||||||
import { ILogService } from 'vs/platform/log/common/log';
|
import { ILogService } from 'vs/platform/log/common/log';
|
||||||
import { IExtensionApiFactory } from 'vs/workbench/api/node/extHost.api.impl';
|
import { IExtensionApiFactory } from 'vs/workbench/api/node/extHost.api.impl';
|
||||||
|
import { ExtHostConnectionManagement } from 'sql/workbench/api/node/extHostConnectionManagement';
|
||||||
|
|
||||||
export interface ISqlExtensionApiFactory {
|
export interface ISqlExtensionApiFactory {
|
||||||
vsCodeFactory(extension: IExtensionDescription): typeof vscode;
|
vsCodeFactory(extension: IExtensionDescription): typeof vscode;
|
||||||
@@ -49,6 +50,7 @@ export function createApiFactory(
|
|||||||
|
|
||||||
// Addressable instances
|
// Addressable instances
|
||||||
const extHostAccountManagement = threadService.set(SqlExtHostContext.ExtHostAccountManagement, new ExtHostAccountManagement(threadService));
|
const extHostAccountManagement = threadService.set(SqlExtHostContext.ExtHostAccountManagement, new ExtHostAccountManagement(threadService));
|
||||||
|
const extHostConnectionManagement = threadService.set(SqlExtHostContext.ExtHostConnectionManagement, new ExtHostConnectionManagement(threadService));
|
||||||
const extHostCredentialManagement = threadService.set(SqlExtHostContext.ExtHostCredentialManagement, new ExtHostCredentialManagement(threadService));
|
const extHostCredentialManagement = threadService.set(SqlExtHostContext.ExtHostCredentialManagement, new ExtHostCredentialManagement(threadService));
|
||||||
const extHostDataProvider = threadService.set(SqlExtHostContext.ExtHostDataProtocol, new ExtHostDataProtocol(threadService));
|
const extHostDataProvider = threadService.set(SqlExtHostContext.ExtHostDataProtocol, new ExtHostDataProtocol(threadService));
|
||||||
const extHostSerializationProvider = threadService.set(SqlExtHostContext.ExtHostSerializationProvider, new ExtHostSerializationProvider(threadService));
|
const extHostSerializationProvider = threadService.set(SqlExtHostContext.ExtHostSerializationProvider, new ExtHostSerializationProvider(threadService));
|
||||||
@@ -74,6 +76,19 @@ export function createApiFactory(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// namespace: connection
|
||||||
|
const connection: typeof data.connection = {
|
||||||
|
getActiveConnections(): Thenable<data.connection.Connection[]> {
|
||||||
|
return extHostConnectionManagement.$getActiveConnections();
|
||||||
|
},
|
||||||
|
getCurrentConnection(): Thenable<data.connection.Connection> {
|
||||||
|
return extHostConnectionManagement.$getCurrentConnection();
|
||||||
|
},
|
||||||
|
getCredentials(connectionId: string): Thenable<{ [name: string]: string }> {
|
||||||
|
return extHostConnectionManagement.$getCredentials(connectionId);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// namespace: credentials
|
// namespace: credentials
|
||||||
const credentials: typeof data.credentials = {
|
const credentials: typeof data.credentials = {
|
||||||
registerProvider(provider: data.CredentialProvider): vscode.Disposable {
|
registerProvider(provider: data.CredentialProvider): vscode.Disposable {
|
||||||
@@ -246,6 +261,7 @@ export function createApiFactory(
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
accounts,
|
accounts,
|
||||||
|
connection,
|
||||||
credentials,
|
credentials,
|
||||||
resources,
|
resources,
|
||||||
serialization,
|
serialization,
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import { Registry } from 'vs/platform/registry/common/platform';
|
|||||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||||
|
|
||||||
// --- SQL contributions
|
// --- SQL contributions
|
||||||
|
import 'sql/workbench/api/node/mainThreadConnectionManagement';
|
||||||
import 'sql/workbench/api/node/mainThreadCredentialManagement';
|
import 'sql/workbench/api/node/mainThreadCredentialManagement';
|
||||||
import 'sql/workbench/api/node/mainThreadDataProtocol';
|
import 'sql/workbench/api/node/mainThreadDataProtocol';
|
||||||
import 'sql/workbench/api/node/mainThreadSerializationProvider';
|
import 'sql/workbench/api/node/mainThreadSerializationProvider';
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ export abstract class ExtHostAccountManagementShape {
|
|||||||
$refresh(handle: number, account: data.Account): Thenable<data.Account> { throw ni(); }
|
$refresh(handle: number, account: data.Account): Thenable<data.Account> { throw ni(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export abstract class ExtHostConnectionManagementShape { }
|
||||||
|
|
||||||
export abstract class ExtHostDataProtocolShape {
|
export abstract class ExtHostDataProtocolShape {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -389,6 +391,12 @@ export interface MainThreadDataProtocolShape extends IDisposable {
|
|||||||
$onEditSessionReady(handle: number, ownerUri: string, success: boolean, message: string);
|
$onEditSessionReady(handle: number, ownerUri: string, success: boolean, message: string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface MainThreadConnectionManagementShape extends IDisposable {
|
||||||
|
$getActiveConnections(): Thenable<data.connection.Connection[]>;
|
||||||
|
$getCurrentConnection(): Thenable<data.connection.Connection>;
|
||||||
|
$getCredentials(connectionId: string): Thenable<{ [name: string]: string }>;
|
||||||
|
}
|
||||||
|
|
||||||
export interface MainThreadCredentialManagementShape extends IDisposable {
|
export interface MainThreadCredentialManagementShape extends IDisposable {
|
||||||
$registerCredentialProvider(handle: number): TPromise<any>;
|
$registerCredentialProvider(handle: number): TPromise<any>;
|
||||||
$unregisterCredentialProvider(handle: number): TPromise<any>;
|
$unregisterCredentialProvider(handle: number): TPromise<any>;
|
||||||
@@ -406,6 +414,7 @@ function ni() { return new Error('Not implemented'); }
|
|||||||
export const SqlMainContext = {
|
export const SqlMainContext = {
|
||||||
// SQL entries
|
// SQL entries
|
||||||
MainThreadAccountManagement: createMainId<MainThreadAccountManagementShape>('MainThreadAccountManagement'),
|
MainThreadAccountManagement: createMainId<MainThreadAccountManagementShape>('MainThreadAccountManagement'),
|
||||||
|
MainThreadConnectionManagement: createMainId<MainThreadConnectionManagementShape>('MainThreadConnectionManagement'),
|
||||||
MainThreadCredentialManagement: createMainId<MainThreadCredentialManagementShape>('MainThreadCredentialManagement'),
|
MainThreadCredentialManagement: createMainId<MainThreadCredentialManagementShape>('MainThreadCredentialManagement'),
|
||||||
MainThreadDataProtocol: createMainId<MainThreadDataProtocolShape>('MainThreadDataProtocol'),
|
MainThreadDataProtocol: createMainId<MainThreadDataProtocolShape>('MainThreadDataProtocol'),
|
||||||
MainThreadSerializationProvider: createMainId<MainThreadSerializationProviderShape>('MainThreadSerializationProvider'),
|
MainThreadSerializationProvider: createMainId<MainThreadSerializationProviderShape>('MainThreadSerializationProvider'),
|
||||||
@@ -415,6 +424,7 @@ export const SqlMainContext = {
|
|||||||
|
|
||||||
export const SqlExtHostContext = {
|
export const SqlExtHostContext = {
|
||||||
ExtHostAccountManagement: createExtId<ExtHostAccountManagementShape>('ExtHostAccountManagement'),
|
ExtHostAccountManagement: createExtId<ExtHostAccountManagementShape>('ExtHostAccountManagement'),
|
||||||
|
ExtHostConnectionManagement: createExtId<ExtHostConnectionManagementShape>('ExtHostConnectionManagement'),
|
||||||
ExtHostCredentialManagement: createExtId<ExtHostCredentialManagementShape>('ExtHostCredentialManagement'),
|
ExtHostCredentialManagement: createExtId<ExtHostCredentialManagementShape>('ExtHostCredentialManagement'),
|
||||||
ExtHostDataProtocol: createExtId<ExtHostDataProtocolShape>('ExtHostDataProtocol'),
|
ExtHostDataProtocol: createExtId<ExtHostDataProtocolShape>('ExtHostDataProtocol'),
|
||||||
ExtHostSerializationProvider: createExtId<ExtHostSerializationProviderShape>('ExtHostSerializationProvider'),
|
ExtHostSerializationProvider: createExtId<ExtHostSerializationProviderShape>('ExtHostSerializationProvider'),
|
||||||
|
|||||||
@@ -348,15 +348,20 @@ export function openInsight(query: IInsightsConfig, profile: IConnectionProfile,
|
|||||||
* Get the current global connection, which is the connection from the active editor, unless OE
|
* Get the current global connection, which is the connection from the active editor, unless OE
|
||||||
* is focused or there is no such editor, in which case it comes from the OE selection. Returns
|
* is focused or there is no such editor, in which case it comes from the OE selection. Returns
|
||||||
* undefined when there is no such connection.
|
* undefined when there is no such connection.
|
||||||
|
*
|
||||||
|
* @param objectExplorerService
|
||||||
|
* @param connectionManagementService
|
||||||
|
* @param workbenchEditorService
|
||||||
|
* @param topLevelOnly If true, only return top-level (i.e. connected) Object Explorer connections instead of database connections when appropriate
|
||||||
*/
|
*/
|
||||||
export function getCurrentGlobalConnection(objectExplorerService: IObjectExplorerService, connectionManagementService: IConnectionManagementService, workbenchEditorService: IWorkbenchEditorService): IConnectionProfile {
|
export function getCurrentGlobalConnection(objectExplorerService: IObjectExplorerService, connectionManagementService: IConnectionManagementService, workbenchEditorService: IWorkbenchEditorService, topLevelOnly: boolean = false): IConnectionProfile {
|
||||||
let connection: IConnectionProfile;
|
let connection: IConnectionProfile;
|
||||||
|
|
||||||
let objectExplorerSelection = objectExplorerService.getSelectedProfileAndDatabase();
|
let objectExplorerSelection = objectExplorerService.getSelectedProfileAndDatabase();
|
||||||
if (objectExplorerSelection) {
|
if (objectExplorerSelection) {
|
||||||
let objectExplorerProfile = objectExplorerSelection.profile;
|
let objectExplorerProfile = objectExplorerSelection.profile;
|
||||||
if (connectionManagementService.isProfileConnected(objectExplorerProfile)) {
|
if (connectionManagementService.isProfileConnected(objectExplorerProfile)) {
|
||||||
if (objectExplorerSelection.databaseName) {
|
if (objectExplorerSelection.databaseName && !topLevelOnly) {
|
||||||
connection = objectExplorerProfile.cloneWithDatabase(objectExplorerSelection.databaseName);
|
connection = objectExplorerProfile.cloneWithDatabase(objectExplorerSelection.databaseName);
|
||||||
} else {
|
} else {
|
||||||
connection = objectExplorerProfile;
|
connection = objectExplorerProfile;
|
||||||
|
|||||||
@@ -790,4 +790,14 @@ suite('SQL ConnectionManagementService tests', () => {
|
|||||||
}
|
}
|
||||||
}, err => done(err));
|
}, err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('getActiveConnectionCredentials returns the credentials dictionary for a connection profile', () => {
|
||||||
|
let profile = Object.assign({}, connectionProfile);
|
||||||
|
profile.options = {password: profile.password};
|
||||||
|
profile.id = 'test_id';
|
||||||
|
connectionStatusManager.addConnection(profile, 'test_uri');
|
||||||
|
(connectionManagementService as any)._connectionStatusManager = connectionStatusManager;
|
||||||
|
let credentials = connectionManagementService.getActiveConnectionCredentials(profile.id);
|
||||||
|
assert.equal(credentials['password'], profile.options['password']);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
@@ -236,4 +236,19 @@ suite('SQL ConnectionStatusManager tests', () => {
|
|||||||
let connectionStatus = connections.getOriginalOwnerUri(connection2Id);
|
let connectionStatus = connections.getOriginalOwnerUri(connection2Id);
|
||||||
assert.equal(connectionStatus, connection2Id);
|
assert.equal(connectionStatus, connection2Id);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('getActiveConnectionProfiles should return a list of all the unique connections that the status manager knows about', () => {
|
||||||
|
// Add duplicate connections
|
||||||
|
let newConnection = Object.assign({}, connectionProfile);
|
||||||
|
newConnection.id = 'test_id';
|
||||||
|
newConnection.serverName = 'new_server_name';
|
||||||
|
newConnection.options['databaseDisplayName'] = newConnection.databaseName;
|
||||||
|
connections.addConnection(newConnection, 'test_uri_1');
|
||||||
|
connections.addConnection(newConnection, 'test_uri_2');
|
||||||
|
|
||||||
|
// Get the connections and verify that the duplicate is only returned once
|
||||||
|
let activeConnections = connections.getActiveConnectionProfiles();
|
||||||
|
assert.equal(activeConnections.length, 4);
|
||||||
|
assert.equal(activeConnections.filter(connection => connection.matches(newConnection)).length, 1, 'Did not find newConnection in active connections');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
@@ -492,4 +492,18 @@ suite('SQL ConnectionStore tests', () => {
|
|||||||
actualGroup = connectionStore.getGroupFromId(childGroupId);
|
actualGroup = connectionStore.getGroupFromId(childGroupId);
|
||||||
assert.equal(actualGroup.id, childGroupId, 'Did not get the child group when looking it up with its ID');
|
assert.equal(actualGroup.id, childGroupId, 'Did not get the child group when looking it up with its ID');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('getProfileWithoutPassword can return the profile without credentials in the password property or options dictionary', () => {
|
||||||
|
let connectionStore = new ConnectionStore(storageServiceMock.object, context.object, undefined, workspaceConfigurationServiceMock.object,
|
||||||
|
credentialStore.object, capabilitiesService.object, connectionConfig.object);
|
||||||
|
let profile = Object.assign({}, defaultNamedProfile);
|
||||||
|
profile.options['password'] = profile.password;
|
||||||
|
profile.id = 'testId';
|
||||||
|
let expectedProfile = Object.assign({}, profile);
|
||||||
|
expectedProfile.password = '';
|
||||||
|
expectedProfile.options['password'] = '';
|
||||||
|
expectedProfile = ConnectionProfile.convertToConnectionProfile(msSQLCapabilities, expectedProfile).toIConnectionProfile();
|
||||||
|
let profileWithoutCredentials = connectionStore.getProfileWithoutPassword(profile);
|
||||||
|
assert.deepEqual(profileWithoutCredentials.toIConnectionProfile(), expectedProfile);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
@@ -241,4 +241,12 @@ export class TestConnectionManagementService implements IConnectionManagementSer
|
|||||||
getTabColorForUri(uri: string): string {
|
getTabColorForUri(uri: string): string {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
removeConnectionProfileCredentials(profile: IConnectionProfile): IConnectionProfile {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
getActiveConnectionCredentials(profileId: string): { [name: string]: string } {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user