mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-02 17:23:40 -05:00
Replacing all azdata with az (#16502)
* Changed azdata to az in azcli extension and resource-deployment, and some arc. Removed user, pass, url from controller connect blade. Commented out tests. Ported over work from old branch. * Changed unit tests, all unit tests passing. Changed parameters to new ones, fixed some Controller Connect issues. * Connect data controller and create dc working. * Changed az back to azdata in necessary places in resource-deployment. * Changed notebook values and added namespace to some params. * Added some changes from PR to this branch * Changed azdata.ts to az.ts and changed subscription parameter * Brought over changes from azcli PR into this branch. * added endpoint, username, password to getIsPassword * Changed notebooks to use proper az params, hard coded in some values to verify it is working, removed some variableNames from package.json. * Changed -sc to --storage-class in notebook * Added namespace to SQL deploy, deleted dc create in api * Deleted more dc create code and uncommented findAz() with unfinished work on Do Not Ask Again. * Removed (preview) from extensions/arc and extensions/azcli excluding preview:true in package.json * Commented out install/update prompts until DoNotAskAgain is implemented * Fixed bugs: JSON Output errors are now being caught, --infrastructure now has a required UI component with dropdown options, config page loads properly, SQL create flags use full names instead of shortnames. * Adds validation to pg extensions and bug fixes (#16486) * Extensions * Server parameters * Change locaiton of postgres extensions, pr fixes * Change location of list * List spacing * Commented out Don't Ask Again prompt implementation. * Uncommented header of a test file. * Added Azure CLI arcdata extension to Prerequisites * Reverted package.json and yarn.lock * Took away casting of stderr and stdout in executeCommand. * Deleted override function for initializeFields in connectControllerDialog.ts * Removed fakeAzApi for testing and added back in (Preview) * Removed en-us from python notebook links. * Deleted azdata tool from tool tests in resource-deployment * Deleted another instance of azdata in tool test * Add back in azdata tooltype * Remove en-us * Replaced AzdataTool in typings * Reverting adding azdata tool back in * Changed Azdata to AzdataToolOld * Added back azdata tool type * Added AzdataToolOld to tool types * fix test Co-authored-by: Candice Ye <canye@microsoft.com> Co-authored-by: nasc17 <nasc@microsoft.com> Co-authored-by: nasc17 <69922333+nasc17@users.noreply.github.com> Co-authored-by: chgagnon <chgagnon@microsoft.com>
This commit is contained in:
@@ -4,12 +4,9 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { ControllerInfo, ResourceType } from 'arc';
|
||||
import * as azdataExt from 'azdata-ext';
|
||||
import * as azExt from 'az-ext';
|
||||
import * as vscode from 'vscode';
|
||||
import { UserCancelledError } from '../common/api';
|
||||
import { getCurrentClusterContext, getKubeConfigClusterContexts } from '../common/kubeUtils';
|
||||
import * as loc from '../localizedConstants';
|
||||
import { ConnectToControllerDialog } from '../ui/dialogs/connectControllerDialog';
|
||||
import { AzureArcTreeDataProvider } from '../ui/tree/azureArcTreeDataProvider';
|
||||
|
||||
export type Registration = {
|
||||
@@ -19,13 +16,13 @@ export type Registration = {
|
||||
};
|
||||
|
||||
export class ControllerModel {
|
||||
private readonly _azdataApi: azdataExt.IExtension;
|
||||
private _endpoints: azdataExt.DcEndpointListResult[] = [];
|
||||
private readonly _azApi: azExt.IExtension;
|
||||
private _endpoints: azExt.DcEndpointListResult[] = [];
|
||||
private _registrations: Registration[] = [];
|
||||
private _controllerConfig: azdataExt.DcConfigShowResult | undefined = undefined;
|
||||
private _controllerConfig: azExt.DcConfigShowResult | undefined = undefined;
|
||||
|
||||
private readonly _onConfigUpdated = new vscode.EventEmitter<azdataExt.DcConfigShowResult | undefined>();
|
||||
private readonly _onEndpointsUpdated = new vscode.EventEmitter<azdataExt.DcEndpointListResult[]>();
|
||||
private readonly _onConfigUpdated = new vscode.EventEmitter<azExt.DcConfigShowResult | undefined>();
|
||||
private readonly _onEndpointsUpdated = new vscode.EventEmitter<azExt.DcEndpointListResult[]>();
|
||||
private readonly _onRegistrationsUpdated = new vscode.EventEmitter<Registration[]>();
|
||||
private readonly _onInfoUpdated = new vscode.EventEmitter<ControllerInfo>();
|
||||
|
||||
@@ -38,85 +35,26 @@ export class ControllerModel {
|
||||
public endpointsLastUpdated?: Date;
|
||||
public registrationsLastUpdated?: Date;
|
||||
|
||||
constructor(public treeDataProvider: AzureArcTreeDataProvider, private _info: ControllerInfo, private _password?: string) {
|
||||
this._azdataApi = <azdataExt.IExtension>vscode.extensions.getExtension(azdataExt.extension.name)?.exports;
|
||||
constructor(public treeDataProvider: AzureArcTreeDataProvider, private _info: ControllerInfo) {
|
||||
this._azApi = <azExt.IExtension>vscode.extensions.getExtension(azExt.extension.name)?.exports;
|
||||
}
|
||||
|
||||
public get info(): ControllerInfo {
|
||||
return this._info;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the controller context to use when executing azdata commands. This is in one of two forms :
|
||||
*
|
||||
* If no URL is specified for this controller then just the namespace is used (e.g. test-namespace)
|
||||
* If a URL is specified then a 3-part name is used, combining the namespace, username and URL separated by
|
||||
* / (e.g. test-namespace/admin/https://10.91.86.13:30080)
|
||||
*/
|
||||
public get controllerContext(): string {
|
||||
if (this._info.endpoint) {
|
||||
return `${this._info.namespace}/${this._info.username}/${this._info.endpoint}`;
|
||||
}
|
||||
return this._info.namespace;
|
||||
}
|
||||
|
||||
public set info(value: ControllerInfo) {
|
||||
this._info = value;
|
||||
this._onInfoUpdated.fire(this._info);
|
||||
}
|
||||
|
||||
public get azdataAdditionalEnvVars(): azdataExt.AdditionalEnvVars {
|
||||
public get azAdditionalEnvVars(): azExt.AdditionalEnvVars {
|
||||
return {
|
||||
'KUBECONFIG': this.info.kubeConfigFilePath,
|
||||
'KUBECTL_CONTEXT': this.info.kubeClusterContext
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls azdata login to set the context to this controller and acquires a login session to prevent other
|
||||
* calls from changing the context while commands for this session are being executed.
|
||||
* @param promptReconnect
|
||||
*/
|
||||
public async login(promptReconnect: boolean = false): Promise<void> {
|
||||
let promptForValidClusterContext: boolean = false;
|
||||
try {
|
||||
const contexts = getKubeConfigClusterContexts(this.info.kubeConfigFilePath);
|
||||
getCurrentClusterContext(contexts, this.info.kubeClusterContext, true); // this throws if this.info.kubeClusterContext is not found in 'contexts'
|
||||
} catch (error) {
|
||||
const response = await vscode.window.showErrorMessage(loc.clusterContextConfigNoLongerValid(this.info.kubeConfigFilePath, this.info.kubeClusterContext, error), loc.yes, loc.no);
|
||||
if (response === loc.yes) {
|
||||
promptForValidClusterContext = true;
|
||||
} else {
|
||||
if (!promptReconnect) { //throw unless we are required to prompt for reconnect anyways
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// We haven't gotten our password yet or we want to prompt for a reconnect or we want to prompt to reacquire valid cluster context or any and all of these.
|
||||
if (!this._password || promptReconnect || promptForValidClusterContext) {
|
||||
this._password = '';
|
||||
if (this.info.rememberPassword) {
|
||||
// It should be in the credentials store, get it from there
|
||||
this._password = await this.treeDataProvider.getPassword(this.info);
|
||||
}
|
||||
if (promptReconnect || !this._password || promptForValidClusterContext) {
|
||||
// No password yet or we want to re-prompt for credentials so prompt for it from the user
|
||||
const dialog = new ConnectToControllerDialog(this.treeDataProvider);
|
||||
dialog.showDialog(this.info, this._password);
|
||||
const model = await dialog.waitForClose();
|
||||
if (model) {
|
||||
await this.treeDataProvider.addOrUpdateController(model.controllerModel, model.password, false);
|
||||
this._password = model.password;
|
||||
this._info = model.controllerModel.info;
|
||||
} else {
|
||||
throw new UserCancelledError(loc.userCancelledError);
|
||||
}
|
||||
}
|
||||
}
|
||||
await this._azdataApi.azdata.login({ endpoint: this.info.endpoint, namespace: this.info.namespace }, this.info.username, this._password, this.azdataAdditionalEnvVars);
|
||||
}
|
||||
|
||||
/**
|
||||
* Refreshes the Tree Node for this model. This will also result in the model being refreshed.
|
||||
*/
|
||||
@@ -125,16 +63,14 @@ export class ControllerModel {
|
||||
if (node) {
|
||||
this.treeDataProvider.refreshNode(node);
|
||||
} else {
|
||||
await this.refresh(false);
|
||||
await this.refresh(false, this.info.namespace);
|
||||
}
|
||||
}
|
||||
public async refresh(showErrors: boolean = true): Promise<void> {
|
||||
// First need to log in to ensure that we're able to authenticate with the controller
|
||||
await this.login(false);
|
||||
public async refresh(showErrors: boolean = true, namespace: string): Promise<void> {
|
||||
const newRegistrations: Registration[] = [];
|
||||
await Promise.all([
|
||||
this._azdataApi.azdata.arc.dc.config.show(this.azdataAdditionalEnvVars, this.controllerContext).then(result => {
|
||||
this._controllerConfig = result.result;
|
||||
this._azApi.az.arcdata.dc.config.show(namespace, this.azAdditionalEnvVars).then(result => {
|
||||
this._controllerConfig = result.stdout;
|
||||
this.configLastUpdated = new Date();
|
||||
this._onConfigUpdated.fire(this._controllerConfig);
|
||||
}).catch(err => {
|
||||
@@ -147,8 +83,8 @@ export class ControllerModel {
|
||||
this._onConfigUpdated.fire(this._controllerConfig);
|
||||
throw err;
|
||||
}),
|
||||
this._azdataApi.azdata.arc.dc.endpoint.list(this.azdataAdditionalEnvVars, this.controllerContext).then(result => {
|
||||
this._endpoints = result.result;
|
||||
this._azApi.az.arcdata.dc.endpoint.list(namespace, this.azAdditionalEnvVars).then(result => {
|
||||
this._endpoints = result.stdout;
|
||||
this.endpointsLastUpdated = new Date();
|
||||
this._onEndpointsUpdated.fire(this._endpoints);
|
||||
}).catch(err => {
|
||||
@@ -162,8 +98,8 @@ export class ControllerModel {
|
||||
throw err;
|
||||
}),
|
||||
Promise.all([
|
||||
this._azdataApi.azdata.arc.postgres.server.list(this.azdataAdditionalEnvVars, this.controllerContext).then(result => {
|
||||
newRegistrations.push(...result.result.map(r => {
|
||||
this._azApi.az.postgres.arcserver.list(namespace, this.azAdditionalEnvVars).then(result => {
|
||||
newRegistrations.push(...result.stdout.map(r => {
|
||||
return {
|
||||
instanceName: r.name,
|
||||
state: r.state,
|
||||
@@ -171,14 +107,15 @@ export class ControllerModel {
|
||||
};
|
||||
}));
|
||||
}),
|
||||
this._azdataApi.azdata.arc.sql.mi.list(this.azdataAdditionalEnvVars, this.controllerContext).then(result => {
|
||||
newRegistrations.push(...result.result.map(r => {
|
||||
this._azApi.az.sql.miarc.list(namespace, this.azAdditionalEnvVars).then(result => {
|
||||
newRegistrations.push(...result.stdout.map(r => {
|
||||
return {
|
||||
instanceName: r.name,
|
||||
state: r.state,
|
||||
instanceType: ResourceType.sqlManagedInstances
|
||||
};
|
||||
}));
|
||||
|
||||
})
|
||||
]).then(() => {
|
||||
this._registrations = newRegistrations;
|
||||
@@ -188,11 +125,11 @@ export class ControllerModel {
|
||||
]);
|
||||
}
|
||||
|
||||
public get endpoints(): azdataExt.DcEndpointListResult[] {
|
||||
public get endpoints(): azExt.DcEndpointListResult[] {
|
||||
return this._endpoints;
|
||||
}
|
||||
|
||||
public getEndpoint(name: string): azdataExt.DcEndpointListResult | undefined {
|
||||
public getEndpoint(name: string): azExt.DcEndpointListResult | undefined {
|
||||
return this._endpoints.find(e => e.name === name);
|
||||
}
|
||||
|
||||
@@ -200,7 +137,7 @@ export class ControllerModel {
|
||||
return this._registrations;
|
||||
}
|
||||
|
||||
public get controllerConfig(): azdataExt.DcConfigShowResult | undefined {
|
||||
public get controllerConfig(): azExt.DcConfigShowResult | undefined {
|
||||
return this._controllerConfig;
|
||||
}
|
||||
|
||||
@@ -214,6 +151,6 @@ export class ControllerModel {
|
||||
* property to for use a display label for this controller
|
||||
*/
|
||||
public get label(): string {
|
||||
return `${this.info.name} (${this.controllerContext})`;
|
||||
return `${this.info.name}`;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user