Add persistence and connect dialog to Arc view (#11014)

* Add controller persistence and info prompting

* more stuff

* clean up

* Add arc tests to scripts
This commit is contained in:
Charles Gagnon
2020-06-19 14:35:11 -07:00
committed by GitHub
parent c879d77b62
commit f278e2a7a2
17 changed files with 576 additions and 176 deletions

View File

@@ -4,10 +4,18 @@
*--------------------------------------------------------------------------------------------*/
import * as vscode from 'vscode';
import { Authentication } from '../controller/auth';
import { Authentication, BasicAuth } from '../controller/auth';
import { EndpointsRouterApi, EndpointModel, RegistrationRouterApi, RegistrationResponse, TokenRouterApi, SqlInstanceRouterApi } from '../controller/generated/v1/api';
import { parseEndpoint, parseInstanceName } from '../common/utils';
import { ResourceType } from '../constants';
import { ConnectToControllerDialog } from '../ui/dialogs/connectControllerDialog';
import { AzureArcTreeDataProvider } from '../ui/tree/azureArcTreeDataProvider';
export type ControllerInfo = {
url: string,
username: string,
rememberPassword: boolean
};
export interface Registration extends RegistrationResponse {
externalIp?: string;
@@ -23,6 +31,7 @@ export class ControllerModel {
private _namespace: string = '';
private _registrations: Registration[] = [];
private _controllerRegistration: Registration | undefined = undefined;
private _auth: Authentication | undefined = undefined;
private readonly _onEndpointsUpdated = new vscode.EventEmitter<EndpointModel[]>();
private readonly _onRegistrationsUpdated = new vscode.EventEmitter<Registration[]>();
@@ -30,22 +39,42 @@ export class ControllerModel {
public onRegistrationsUpdated = this._onRegistrationsUpdated.event;
public endpointsLastUpdated?: Date;
public registrationsLastUpdated?: Date;
public get auth(): Authentication | undefined {
return this._auth;
}
constructor(public readonly controllerUrl: string, public readonly auth: Authentication) {
this._endpointsRouter = new EndpointsRouterApi(controllerUrl);
this._endpointsRouter.setDefaultAuthentication(auth);
this._tokenRouter = new TokenRouterApi(controllerUrl);
this._tokenRouter.setDefaultAuthentication(auth);
this._registrationRouter = new RegistrationRouterApi(controllerUrl);
this._registrationRouter.setDefaultAuthentication(auth);
this._sqlInstanceRouter = new SqlInstanceRouterApi(controllerUrl);
this._sqlInstanceRouter.setDefaultAuthentication(auth);
constructor(private _treeDataProvider: AzureArcTreeDataProvider, public info: ControllerInfo, password?: string) {
this._endpointsRouter = new EndpointsRouterApi(this.info.url);
this._tokenRouter = new TokenRouterApi(this.info.url);
this._registrationRouter = new RegistrationRouterApi(this.info.url);
this._sqlInstanceRouter = new SqlInstanceRouterApi(this.info.url);
if (password) {
this.setAuthentication(new BasicAuth(this.info.username, password));
}
}
public async refresh(): Promise<void> {
// We haven't gotten our password yet, fetch it now
if (!this._auth) {
let password = '';
if (this.info.rememberPassword) {
// It should be in the credentials store, get it from there
password = await this._treeDataProvider.getPassword(this.info);
}
if (password) {
this.setAuthentication(new BasicAuth(this.info.username, password));
} else {
// No password yet so prompt for it from the user
const dialog = new ConnectToControllerDialog(this._treeDataProvider);
dialog.showDialog(this.info);
const model = await dialog.waitForClose();
if (model) {
this._treeDataProvider.addOrUpdateController(model.controllerModel, model.password, false);
this.setAuthentication(new BasicAuth(this.info.username, model.password));
}
}
}
await Promise.all([
this._endpointsRouter.apiV1BdcEndpointsGet().then(response => {
this._endpoints = response.body;
@@ -88,9 +117,31 @@ export class ControllerModel {
});
}
/**
* Deletes the specified MIAA resource from the controller
* @param namespace The namespace of the resource
* @param name The name of the resource
*/
public async miaaDelete(namespace: string, name: string): Promise<void> {
await this._sqlInstanceRouter.apiV1HybridSqlNsNameDelete(namespace, name);
}
/**
* Tests whether this model is for the same controller as another
* @param other The other instance to test
*/
public equals(other: ControllerModel): boolean {
return this.info.url === other.info.url &&
this.info.username === other.info.username;
}
private setAuthentication(auth: Authentication): void {
this._auth = auth;
this._endpointsRouter.setDefaultAuthentication(auth);
this._tokenRouter.setDefaultAuthentication(auth);
this._registrationRouter.setDefaultAuthentication(auth);
this._sqlInstanceRouter.setDefaultAuthentication(auth);
}
}
/**