Allow data explorer to use connect (#5564)

* wip

* handle save password; get correct profile

* ensure resolve is being called

* fix tests

* fix more tests
This commit is contained in:
Anthony Dresser
2019-05-23 11:44:18 -07:00
committed by GitHub
parent 5e8a52bcc0
commit aae1480e4f
15 changed files with 87 additions and 50 deletions

View File

@@ -57,7 +57,7 @@ export interface IConnectionResult {
export interface IConnectionCallbacks {
onConnectStart(): void;
onConnectReject(error?: string): void;
onConnectSuccess(params?: INewConnectionParams): void;
onConnectSuccess(params: INewConnectionParams, profile: IConnectionProfile): void;
onDisconnect(): void;
onConnectCanceled(): void;
}
@@ -80,7 +80,7 @@ export interface IConnectionManagementService {
/**
* Opens the connection dialog to create new connection
*/
showConnectionDialog(params?: INewConnectionParams, model?: IConnectionProfile, connectionResult?: IConnectionResult): Promise<void>;
showConnectionDialog(params?: INewConnectionParams, options?: IConnectionCompletionOptions, model?: IConnectionProfile, connectionResult?: IConnectionResult): Promise<void>;
/**
* Opens the add server group dialog
@@ -305,7 +305,7 @@ export interface IConnectableInput {
uri: string;
onConnectStart(): void;
onConnectReject(error?: string): void;
onConnectSuccess(params?: INewConnectionParams): void;
onConnectSuccess(params: INewConnectionParams, profile: IConnectionProfile): void;
onDisconnect(): void;
onConnectCanceled(): void;
}

View File

@@ -183,7 +183,7 @@ export class ConnectionManagementService extends Disposable implements IConnecti
* @param params Include the uri, type of connection
* @param model the existing connection profile to create a new one from
*/
public showConnectionDialog(params?: INewConnectionParams, model?: IConnectionProfile, connectionResult?: IConnectionResult): Promise<void> {
public showConnectionDialog(params?: INewConnectionParams, options?: IConnectionCompletionOptions, model?: IConnectionProfile, connectionResult?: IConnectionResult): Promise<void> {
let self = this;
return new Promise<void>((resolve, reject) => {
if (!params) {
@@ -192,7 +192,7 @@ export class ConnectionManagementService extends Disposable implements IConnecti
if (!model && params.input && params.input.uri) {
model = this._connectionStatusManager.getConnectionProfile(params.input.uri);
}
self._connectionDialogService.showDialog(self, params, model, connectionResult).then(() => {
self._connectionDialogService.showDialog(self, params, model, connectionResult, options).then(() => {
resolve();
}, dialogError => {
this.logService.warn('failed to open the connection dialog. error: ' + dialogError);
@@ -317,7 +317,7 @@ export class ConnectionManagementService extends Disposable implements IConnecti
runQueryOnCompletion: RunQueryOnConnectionMode.none,
showDashboard: options.showDashboard
};
this.showConnectionDialog(params, connection, connectionResult).then(() => {
this.showConnectionDialog(params, options, connection, connectionResult).then(() => {
resolve(connectionResult);
}).catch(err => {
reject(err);
@@ -455,7 +455,7 @@ export class ConnectionManagementService extends Disposable implements IConnecti
this.tryAddActiveConnection(connectionMgmtInfo, connection, options.saveTheConnection);
if (callbacks.onConnectSuccess) {
callbacks.onConnectSuccess(options.params);
callbacks.onConnectSuccess(options.params, connectionResult.connectionProfile);
}
if (options.saveTheConnection) {
this.saveToSettings(uri, connection).then(value => {
@@ -466,7 +466,13 @@ export class ConnectionManagementService extends Disposable implements IConnecti
connection.saveProfile = false;
this.doActionsAfterConnectionComplete(uri, options);
}
resolve(connectionResult);
if (connection.savePassword) {
this._connectionStore.savePassword(connection).then(() => {
resolve(connectionResult);
});
} else {
resolve(connectionResult);
}
} else if (connectionResult && connectionResult.errorMessage) {
this.handleConnectionError(connection, uri, options, callbacks, connectionResult).then(result => {
resolve(result);

View File

@@ -12,6 +12,8 @@ import { generateUuid } from 'vs/base/common/uuid';
import { ICapabilitiesService } from 'sql/platform/capabilities/common/capabilitiesService';
import { isString } from 'vs/base/common/types';
import { deepClone } from 'vs/base/common/objects';
import { ConnectionOptionSpecialType } from 'sql/workbench/api/common/sqlExtHostTypes';
import * as Constants from 'sql/platform/connection/common/constants';
// Concrete implementation of the IConnectionProfile interface
@@ -41,6 +43,14 @@ export class ConnectionProfile extends ProviderConnectionInfo implements interfa
this.saveProfile = model.saveProfile;
this._id = model.id;
this.azureTenantId = model.azureTenantId;
if (this.capabilitiesService) {
const options = this.capabilitiesService.getCapabilities(model.providerName).connection.connectionOptions;
let appNameOption = options.find(option => option.specialValueType === ConnectionOptionSpecialType.appName);
if (appNameOption) {
let appNameKey = appNameOption.name;
this.options[appNameKey] = Constants.applicationName;
}
}
} else {
//Default for a new connection
this.savePassword = false;

View File

@@ -124,6 +124,10 @@ export class ConnectionStore {
});
}
public savePassword(profile: IConnectionProfile): Promise<boolean> {
return this.saveProfilePasswordIfNeeded(profile);
}
/**
* Saves a connection profile group to the user settings.
*

View File

@@ -158,7 +158,7 @@ export class AddServerAction extends Action {
saveProfile: true,
id: element.id
};
this._connectionManagementService.showConnectionDialog(undefined, connection);
this._connectionManagementService.showConnectionDialog(undefined, undefined, connection);
return Promise.resolve(true);
}
}

View File

@@ -48,12 +48,23 @@ export class OEShimService extends Disposable implements IOEShimService {
let connProfile = new ConnectionProfile(this.capabilities, node.payload);
connProfile.saveProfile = false;
if (this.cm.providerRegistered(providerId)) {
let userProfile = await this.cd.openDialogAndWait(this.cm, { connectionType: ConnectionType.default, showDashboard: false }, connProfile, undefined, false);
if (userProfile) {
connProfile = new ConnectionProfile(this.capabilities, userProfile);
} else {
return Promise.reject('User canceled');
}
await new Promise(async (resolve, reject) => {
await this.cm.connect(connProfile, undefined,
{ showConnectionDialogOnError: true, showFirewallRuleOnError: true, saveTheConnection: false, showDashboard: false, params: undefined },
{
onConnectSuccess: async (e, profile) => {
let existingConnection = this.cm.findExistingConnection(profile);
connProfile = new ConnectionProfile(this.capabilities, await this.cm.addSavedPassword(existingConnection));
resolve();
},
onConnectCanceled: () => {
reject('User canceled');
},
onConnectReject: undefined,
onConnectStart: undefined,
onDisconnect: undefined
});
});
}
let sessionResp = await this.oe.createNewSession(providerId, connProfile);
let disp = this.oe.onUpdateObjectExplorerNodes(e => {

View File

@@ -65,6 +65,7 @@ export class ConnectionDialogService implements IConnectionDialogService {
private _connectionControllerMap: { [providerDisplayName: string]: IConnectionComponentController } = {};
private _model: ConnectionProfile;
private _params: INewConnectionParams;
private _options: IConnectionCompletionOptions;
private _inputModel: IConnectionProfile;
private _providerNameToDisplayNameMap: { [providerDisplayName: string]: string } = {};
private _providerTypes: string[] = [];
@@ -239,7 +240,7 @@ export class ConnectionDialogService implements IConnectionDialogService {
if (fromEditor && params && params.input) {
uri = params.input.uri;
}
let options: IConnectionCompletionOptions = {
let options: IConnectionCompletionOptions = this._options || {
params: params,
saveTheConnection: true,
showDashboard: params && params.showDashboard !== undefined ? params.showDashboard : !fromEditor,
@@ -393,10 +394,12 @@ export class ConnectionDialogService implements IConnectionDialogService {
connectionManagementService: IConnectionManagementService,
params?: INewConnectionParams,
model?: IConnectionProfile,
connectionResult?: IConnectionResult): Thenable<void> {
connectionResult?: IConnectionResult,
connectionOptions?: IConnectionCompletionOptions): Thenable<void> {
this._connectionManagementService = connectionManagementService;
this._options = connectionOptions;
this._params = params;
this._inputModel = model;
return new Promise<void>((resolve, reject) => {

View File

@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { INewConnectionParams, IConnectionResult, IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement';
import { INewConnectionParams, IConnectionResult, IConnectionManagementService, IConnectionCompletionOptions } from 'sql/platform/connection/common/connectionManagement';
import { IConnectionProfile } from 'sql/platform/connection/common/interfaces';
export const IConnectionDialogService = createDecorator<IConnectionDialogService>('connectionDialogService');
@@ -13,7 +13,7 @@ export interface IConnectionDialogService {
/**
* Opens the connection dialog and returns the promise for successfully opening the dialog
*/
showDialog(connectionManagementService: IConnectionManagementService, params: INewConnectionParams, model: IConnectionProfile, connectionResult?: IConnectionResult): Thenable<void>;
showDialog(connectionManagementService: IConnectionManagementService, params: INewConnectionParams, model: IConnectionProfile, connectionResult?: IConnectionResult, connectionOptions?: IConnectionCompletionOptions): Thenable<void>;
/**
* Opens the connection dialog and returns the promise when connection is made