Add acquireLoginSession API for Azdata (#13985)

* wip

* fix tests

* add tests

* PR comments
This commit is contained in:
Charles Gagnon
2021-01-20 10:35:26 -08:00
committed by GitHub
parent 9e9fac2991
commit 04dff9cdf2
16 changed files with 488 additions and 188 deletions

View File

@@ -129,13 +129,16 @@ export class MiaaComputeAndStoragePage extends DashboardPage {
cancellable: false
},
async (_progress, _token): Promise<void> => {
let session: azdataExt.AzdataSession | undefined = undefined;
try {
await this._miaaModel.controllerModel.azdataLogin();
session = await this._miaaModel.controllerModel.acquireAzdataSession();
await this._azdataApi.azdata.arc.sql.mi.edit(
this._miaaModel.info.name, this.saveArgs);
this._miaaModel.info.name, this.saveArgs, this._miaaModel.controllerModel.azdataAdditionalEnvVars, session);
} catch (err) {
this.saveButton!.enabled = true;
throw err;
} finally {
session?.dispose();
}
await this._miaaModel.refresh();

View File

@@ -206,8 +206,13 @@ export class MiaaDashboardOverviewPage extends DashboardPage {
cancellable: false
},
async (_progress, _token) => {
await this._controllerModel.azdataLogin();
return await this._azdataApi.azdata.arc.sql.mi.delete(this._miaaModel.info.name);
const session = await this._controllerModel.acquireAzdataSession();
try {
return await this._azdataApi.azdata.arc.sql.mi.delete(this._miaaModel.info.name, this._controllerModel.azdataAdditionalEnvVars, session);
} finally {
session.dispose();
}
}
);
await this._controllerModel.refreshTreeNode();

View File

@@ -155,18 +155,23 @@ export class PostgresComputeAndStoragePage extends DashboardPage {
cancellable: false
},
async (_progress, _token): Promise<void> => {
let session: azdataExt.AzdataSession | undefined = undefined;
try {
await this._postgresModel.controllerModel.azdataLogin();
session = await this._postgresModel.controllerModel.acquireAzdataSession();
await this._azdataApi.azdata.arc.postgres.server.edit(
this._postgresModel.info.name,
this.saveArgs,
this._postgresModel.engineVersion
this._postgresModel.engineVersion,
this._postgresModel.controllerModel.azdataAdditionalEnvVars,
session
);
} catch (err) {
// If an error occurs while editing the instance then re-enable the save button since
// the edit wasn't successfully applied
this.saveButton!.enabled = true;
throw err;
} finally {
session?.dispose();
}
await this._postgresModel.refresh();
}

View File

@@ -151,16 +151,21 @@ export class PostgresOverviewPage extends DashboardPage {
try {
const password = await promptAndConfirmPassword(input => !input ? loc.enterANonEmptyPassword : '');
if (password) {
await this._postgresModel.controllerModel.azdataLogin();
await this._azdataApi.azdata.arc.postgres.server.edit(
this._postgresModel.info.name,
{
adminPassword: true,
noWait: true
},
this._postgresModel.engineVersion,
{ 'AZDATA_PASSWORD': password }
);
const session = await this._postgresModel.controllerModel.acquireAzdataSession();
try {
await this._azdataApi.azdata.arc.postgres.server.edit(
this._postgresModel.info.name,
{
adminPassword: true,
noWait: true
},
this._postgresModel.engineVersion,
Object.assign({ 'AZDATA_PASSWORD': password }, this._controllerModel.azdataAdditionalEnvVars),
session
);
} finally {
session.dispose();
}
vscode.window.showInformationMessage(loc.passwordReset);
}
} catch (error) {
@@ -188,8 +193,13 @@ export class PostgresOverviewPage extends DashboardPage {
cancellable: false
},
async (_progress, _token) => {
await this._postgresModel.controllerModel.azdataLogin();
return await this._azdataApi.azdata.arc.postgres.server.delete(this._postgresModel.info.name);
const session = await this._postgresModel.controllerModel.acquireAzdataSession();
try {
return await this._azdataApi.azdata.arc.postgres.server.delete(this._postgresModel.info.name, this._controllerModel.azdataAdditionalEnvVars, session);
} finally {
session.dispose();
}
}
);
await this._controllerModel.refreshTreeNode();

View File

@@ -172,8 +172,14 @@ export class PostgresParametersPage extends DashboardPage {
this.engineSettingUpdates!.forEach((value: string) => {
this.engineSettings += value + ', ';
});
await this._azdataApi.azdata.arc.postgres.server.edit(
this._postgresModel.info.name, { engineSettings: this.engineSettings + `'` });
const session = await this._postgresModel.controllerModel.acquireAzdataSession();
try {
await this._azdataApi.azdata.arc.postgres.server.edit(
this._postgresModel.info.name, { engineSettings: this.engineSettings + `'` });
} finally {
session.dispose();
}
} catch (err) {
// If an error occurs while editing the instance then re-enable the save button since
// the edit wasn't successfully applied
@@ -237,7 +243,9 @@ export class PostgresParametersPage extends DashboardPage {
async (_progress, _token): Promise<void> => {
//all
// azdata arc postgres server edit -n <server group name> -e '' -re
let session: azdataExt.AzdataSession | undefined = undefined;
try {
session = await this._postgresModel.controllerModel.acquireAzdataSession();
await this._azdataApi.azdata.arc.postgres.server.edit(
this._postgresModel.info.name, { engineSettings: `'' -re` });
} catch (err) {
@@ -245,6 +253,8 @@ export class PostgresParametersPage extends DashboardPage {
// the edit wasn't successfully applied
this.resetButton!.enabled = true;
throw err;
} finally {
session?.dispose();
}
await this._postgresModel.refresh();
}
@@ -463,9 +473,14 @@ export class PostgresParametersPage extends DashboardPage {
title: loc.updatingInstance(this._postgresModel.info.name),
cancellable: false
},
(_progress, _token) => {
return this._azdataApi.azdata.arc.postgres.server.edit(
this._postgresModel.info.name, { engineSettings: name + '=' });
async (_progress, _token) => {
const session = await this._postgresModel.controllerModel.acquireAzdataSession();
try {
this._azdataApi.azdata.arc.postgres.server.edit(
this._postgresModel.info.name, { engineSettings: name + '=' });
} finally {
session.dispose();
}
}
);