mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
Fix BDC remember password and reprompting connection (#7957)
* Fix remember password and reprompting connection * comment * Fix to remember password for session * Fix floating promises
This commit is contained in:
@@ -6,11 +6,14 @@
|
||||
'use strict';
|
||||
|
||||
import * as azdata from 'azdata';
|
||||
import * as vscode from 'vscode';
|
||||
import * as nls from 'vscode-nls';
|
||||
import { ClusterController, ControllerError } from '../controller/clusterControllerApi';
|
||||
import { ControllerTreeDataProvider } from '../tree/controllerTreeDataProvider';
|
||||
import { TreeNode } from '../tree/treeNode';
|
||||
import { AuthType } from '../constants';
|
||||
import { ManageControllerCommand } from '../../extension';
|
||||
import { BdcDashboardOptions } from './bdcDashboardModel';
|
||||
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
@@ -73,7 +76,8 @@ export class AddControllerDialogModel {
|
||||
if (this._canceled) {
|
||||
return;
|
||||
}
|
||||
this.treeDataProvider.addController(url, auth, username, password, rememberPassword);
|
||||
this.treeDataProvider.addOrUpdateController(url, auth, username, password, rememberPassword);
|
||||
vscode.commands.executeCommand(ManageControllerCommand, <BdcDashboardOptions>{ url: url, auth: auth, username: username, password: password });
|
||||
await this.treeDataProvider.saveControllers();
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
@@ -13,7 +13,8 @@ import { IconPathHelper, cssStyles } from '../constants';
|
||||
import { BdcServiceStatusPage } from './bdcServiceStatusPage';
|
||||
import { BdcDashboardOverviewPage } from './bdcDashboardOverviewPage';
|
||||
import { BdcStatusModel, ServiceStatusModel } from '../controller/apiGenerated';
|
||||
import { getHealthStatusDot, getServiceNameDisplayText } from '../utils';
|
||||
import { getHealthStatusDot, getServiceNameDisplayText, showErrorMessage } from '../utils';
|
||||
import { HdfsDialogCancelledError } from './hdfsDialogBase';
|
||||
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
@@ -43,6 +44,7 @@ export class BdcDashboard {
|
||||
|
||||
constructor(private title: string, private model: BdcDashboardModel) {
|
||||
this.model.onDidUpdateBdcStatus(bdcStatus => this.handleBdcStatusUpdate(bdcStatus));
|
||||
this.model.onError(error => this.handleError(error));
|
||||
}
|
||||
|
||||
public showDashboard(): void {
|
||||
@@ -165,6 +167,14 @@ export class BdcDashboard {
|
||||
this.updateServiceNavTabs(bdcStatus.services);
|
||||
}
|
||||
|
||||
private handleError(error: Error): void {
|
||||
// We don't want to show an error for the connection dialog being
|
||||
// canceled since that's a normal case.
|
||||
if (!(error instanceof HdfsDialogCancelledError)) {
|
||||
showErrorMessage(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
private async doRefresh(): Promise<void> {
|
||||
try {
|
||||
this.refreshButton.enabled = false;
|
||||
|
||||
@@ -7,8 +7,10 @@ import * as azdata from 'azdata';
|
||||
import * as vscode from 'vscode';
|
||||
import { ClusterController } from '../controller/clusterControllerApi';
|
||||
import { EndpointModel, BdcStatusModel } from '../controller/apiGenerated';
|
||||
import { showErrorMessage, Endpoint, Service } from '../utils';
|
||||
import { Endpoint, Service } from '../utils';
|
||||
import { AuthType } from '../constants';
|
||||
import { ConnectControllerDialog, ConnectControllerModel } from './connectControllerDialog';
|
||||
import { ControllerTreeDataProvider } from '../tree/controllerTreeDataProvider';
|
||||
|
||||
export type BdcDashboardOptions = { url: string, auth: AuthType, username: string, password: string };
|
||||
|
||||
@@ -21,12 +23,23 @@ export class BdcDashboardModel {
|
||||
private _endpointsLastUpdated: Date;
|
||||
private readonly _onDidUpdateEndpoints = new vscode.EventEmitter<EndpointModel[]>();
|
||||
private readonly _onDidUpdateBdcStatus = new vscode.EventEmitter<BdcStatusModel>();
|
||||
private readonly _onError = new vscode.EventEmitter<Error>();
|
||||
public onDidUpdateEndpoints = this._onDidUpdateEndpoints.event;
|
||||
public onDidUpdateBdcStatus = this._onDidUpdateBdcStatus.event;
|
||||
public onError = this._onError.event;
|
||||
|
||||
constructor(private options: BdcDashboardOptions, ignoreSslVerification = true) {
|
||||
this._clusterController = new ClusterController(options.url, options.auth, options.username, options.password, ignoreSslVerification);
|
||||
this.refresh();
|
||||
constructor(private _options: BdcDashboardOptions, private _treeDataProvider: ControllerTreeDataProvider, ignoreSslVerification = true) {
|
||||
try {
|
||||
this._clusterController = new ClusterController(_options.url, _options.auth, _options.username, _options.password, ignoreSslVerification);
|
||||
// tslint:disable-next-line:no-floating-promises
|
||||
this.refresh();
|
||||
} catch {
|
||||
this.promptReconnect().then(async () => {
|
||||
await this.refresh();
|
||||
}).catch(error => {
|
||||
this._onError.fire(error);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public get bdcStatus(): BdcStatusModel | undefined {
|
||||
@@ -46,21 +59,28 @@ export class BdcDashboardModel {
|
||||
}
|
||||
|
||||
public async refresh(): Promise<void> {
|
||||
await Promise.all([
|
||||
this._clusterController.getBdcStatus(true).then(response => {
|
||||
this._bdcStatus = response.bdcStatus;
|
||||
this._bdcStatusLastUpdated = new Date();
|
||||
this._onDidUpdateBdcStatus.fire(this.bdcStatus);
|
||||
}),
|
||||
this._clusterController.getEndPoints(true).then(response => {
|
||||
this._endpoints = response.endPoints || [];
|
||||
fixEndpoints(this._endpoints);
|
||||
this._endpointsLastUpdated = new Date();
|
||||
this._onDidUpdateEndpoints.fire(this.serviceEndpoints);
|
||||
})
|
||||
]).catch(error => {
|
||||
showErrorMessage(error);
|
||||
});
|
||||
try {
|
||||
if (!this._clusterController) {
|
||||
// If this succeeds without error we know we have a clusterController at this point
|
||||
await this.promptReconnect();
|
||||
}
|
||||
|
||||
await Promise.all([
|
||||
this._clusterController.getBdcStatus(true).then(response => {
|
||||
this._bdcStatus = response.bdcStatus;
|
||||
this._bdcStatusLastUpdated = new Date();
|
||||
this._onDidUpdateBdcStatus.fire(this.bdcStatus);
|
||||
}),
|
||||
this._clusterController.getEndPoints(true).then(response => {
|
||||
this._endpoints = response.endPoints || [];
|
||||
fixEndpoints(this._endpoints);
|
||||
this._endpointsLastUpdated = new Date();
|
||||
this._onDidUpdateEndpoints.fire(this.serviceEndpoints);
|
||||
})
|
||||
]);
|
||||
} catch (error) {
|
||||
this._onError.fire(error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,7 +101,7 @@ export class BdcDashboardModel {
|
||||
serverName: sqlServerMasterEndpoint.endpoint,
|
||||
databaseName: undefined,
|
||||
userName: 'sa',
|
||||
password: this.options.password,
|
||||
password: this._options.password,
|
||||
authenticationType: '',
|
||||
savePassword: true,
|
||||
groupFullName: undefined,
|
||||
@@ -92,6 +112,19 @@ export class BdcDashboardModel {
|
||||
options: {}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens up a dialog prompting the user to re-enter credentials for the controller
|
||||
*/
|
||||
private async promptReconnect(): Promise<void> {
|
||||
this._clusterController = await new ConnectControllerDialog(new ConnectControllerModel(this._options)).showDialog();
|
||||
this._treeDataProvider.addOrUpdateController(
|
||||
this._clusterController.url,
|
||||
this._clusterController.authType,
|
||||
this._clusterController.username,
|
||||
this._clusterController.password,
|
||||
/* Remember password */false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -28,6 +28,12 @@ export interface HdfsDialogProperties {
|
||||
password?: string;
|
||||
}
|
||||
|
||||
export class HdfsDialogCancelledError extends Error {
|
||||
constructor(message: string = 'Dialog cancelled') {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
export abstract class HdfsDialogModelBase<T extends HdfsDialogProperties, R> {
|
||||
protected _canceled = false;
|
||||
private _authTypes: azdata.CategoryValue[];
|
||||
@@ -87,7 +93,7 @@ export abstract class HdfsDialogModelBase<T extends HdfsDialogProperties, R> {
|
||||
throw new Error(localize('mount.hdfs.loginerror1', "Login to controller failed"));
|
||||
}
|
||||
} catch (err) {
|
||||
throw new Error(localize('mount.hdfs.loginerror2', "Login to controller failed: {0}", err.message));
|
||||
throw new Error(localize('mount.hdfs.loginerror2', "Login to controller failed: {0}", err.statusMessage || err.message));
|
||||
}
|
||||
return controller;
|
||||
}
|
||||
@@ -224,7 +230,7 @@ export abstract class HdfsDialogBase<T extends HdfsDialogProperties, R> {
|
||||
if (this.model && this.model.onCancel) {
|
||||
await this.model.onCancel();
|
||||
}
|
||||
this.returnPromise.reject(new Error('Dialog cancelled'));
|
||||
this.returnPromise.reject(new HdfsDialogCancelledError());
|
||||
}
|
||||
|
||||
protected async reportError(error: any): Promise<void> {
|
||||
|
||||
Reference in New Issue
Block a user