mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-09 17:52:34 -05:00
allow registering options source providers to resource-deployment (#12712)
* first draft * compile fixes * uncomment code * waitForAzdataToolDisovery added to azdata api * missed change in last commit * remove switchReturn * contributeOptionsSource renamed * remove switchReturn reference * create optionSourceService * azdataTool usage more reliable * package.json fixes and cleanup * cleanup * revert 4831a6e6b8b08684488b2c9e18092fa252e3057f * pr feedback * pr feedback * pr feedback * cleanup * cleanup * fix eulaAccepted check * fix whitespade in doc comments.
This commit is contained in:
@@ -4,40 +4,42 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as azdataExt from 'azdata-ext';
|
||||
import * as rd from 'resource-deployment';
|
||||
import * as vscode from 'vscode';
|
||||
import { checkAndInstallAzdata, checkAndUpdateAzdata, findAzdata, IAzdataTool, promptForEula } from './azdata';
|
||||
import { getExtensionApi } from './api';
|
||||
import { checkAndInstallAzdata, checkAndUpdateAzdata, findAzdata, isEulaAccepted, promptForEula } from './azdata';
|
||||
import Logger from './common/logger';
|
||||
import { NoAzdataError } from './common/utils';
|
||||
import * as constants from './constants';
|
||||
import * as loc from './localizedConstants';
|
||||
import { ArcControllerConfigProfilesOptionsSource } from './providers/arcControllerConfigProfilesOptionsSource';
|
||||
import { AzdataToolService } from './services/azdataToolService';
|
||||
|
||||
let localAzdata: IAzdataTool | undefined = undefined;
|
||||
let eulaAccepted: boolean = false;
|
||||
export async function activate(context: vscode.ExtensionContext): Promise<azdataExt.IExtension> {
|
||||
const azdataToolService = new AzdataToolService();
|
||||
let eulaAccepted: boolean = false;
|
||||
vscode.commands.registerCommand('azdata.acceptEula', async () => {
|
||||
eulaAccepted = await promptForEula(context.globalState, true /* userRequested */);
|
||||
|
||||
await promptForEula(context.globalState, true /* userRequested */);
|
||||
});
|
||||
|
||||
vscode.commands.registerCommand('azdata.install', async () => {
|
||||
localAzdata = await checkAndInstallAzdata(true /* userRequested */);
|
||||
azdataToolService.localAzdata = await checkAndInstallAzdata(true /* userRequested */);
|
||||
});
|
||||
|
||||
vscode.commands.registerCommand('azdata.update', async () => {
|
||||
if (await checkAndUpdateAzdata(localAzdata, true /* userRequested */)) { // if an update was performed
|
||||
localAzdata = await findAzdata(); // find and save the currently installed azdata
|
||||
if (await checkAndUpdateAzdata(azdataToolService.localAzdata, true /* userRequested */)) { // if an update was performed
|
||||
azdataToolService.localAzdata = await findAzdata(); // find and save the currently installed azdata
|
||||
}
|
||||
});
|
||||
|
||||
eulaAccepted = !!context.globalState.get<boolean>(constants.eulaAccepted); // fetch eula acceptance state from memento
|
||||
eulaAccepted = isEulaAccepted(context.globalState); // fetch eula acceptance state from memento
|
||||
await vscode.commands.executeCommand('setContext', constants.eulaAccepted, eulaAccepted); // set a context key for current value of eulaAccepted state retrieved from memento so that command for accepting eula is available/unavailable in commandPalette appropriately.
|
||||
Logger.log(loc.eulaAcceptedStateOnStartup(eulaAccepted));
|
||||
|
||||
// Don't block on this since we want the extension to finish activating without needing user input
|
||||
checkAndInstallAzdata() // install if not installed and user wants it.
|
||||
const localAzdataDiscovered = checkAndInstallAzdata() // install if not installed and user wants it.
|
||||
.then(async azdataTool => {
|
||||
localAzdata = azdataTool;
|
||||
if (localAzdata !== undefined) {
|
||||
if (azdataTool !== undefined) {
|
||||
azdataToolService.localAzdata = azdataTool;
|
||||
if (!eulaAccepted) {
|
||||
// Don't block on this since we want extension to finish activating without requiring user actions.
|
||||
// If EULA has not been accepted then we will check again while executing azdata commands.
|
||||
@@ -49,127 +51,23 @@ export async function activate(context: vscode.ExtensionContext): Promise<azdata
|
||||
}
|
||||
try {
|
||||
//update if available and user wants it.
|
||||
if (await checkAndUpdateAzdata(localAzdata)) { // if an update was performed
|
||||
localAzdata = await findAzdata(); // find and save the currently installed azdata
|
||||
if (await checkAndUpdateAzdata(azdataToolService.localAzdata)) { // if an update was performed
|
||||
azdataToolService.localAzdata = await findAzdata(); // find and save the currently installed azdata
|
||||
}
|
||||
} catch (err) {
|
||||
vscode.window.showWarningMessage(loc.updateError(err));
|
||||
}
|
||||
}
|
||||
return azdataTool;
|
||||
});
|
||||
|
||||
return {
|
||||
isEulaAccepted: () => !!context.globalState.get<boolean>(constants.eulaAccepted),
|
||||
promptForEula: (onError: boolean = true): Promise<boolean> => promptForEula(context.globalState, true /* userRequested */, onError),
|
||||
azdata: {
|
||||
arc: {
|
||||
dc: {
|
||||
create: async (namespace: string, name: string, connectivityMode: string, resourceGroup: string, location: string, subscription: string, profileName?: string, storageClass?: string) => {
|
||||
throwIfNoAzdataOrEulaNotAccepted();
|
||||
return localAzdata!.arc.dc.create(namespace, name, connectivityMode, resourceGroup, location, subscription, profileName, storageClass);
|
||||
},
|
||||
endpoint: {
|
||||
list: async () => {
|
||||
throwIfNoAzdataOrEulaNotAccepted();
|
||||
return localAzdata!.arc.dc.endpoint.list();
|
||||
}
|
||||
},
|
||||
config: {
|
||||
list: async () => {
|
||||
throwIfNoAzdataOrEulaNotAccepted();
|
||||
return localAzdata!.arc.dc.config.list();
|
||||
},
|
||||
show: async () => {
|
||||
throwIfNoAzdataOrEulaNotAccepted();
|
||||
return localAzdata!.arc.dc.config.show();
|
||||
}
|
||||
}
|
||||
},
|
||||
postgres: {
|
||||
server: {
|
||||
delete: async (name: string) => {
|
||||
throwIfNoAzdataOrEulaNotAccepted();
|
||||
return localAzdata!.arc.postgres.server.delete(name);
|
||||
},
|
||||
list: async () => {
|
||||
throwIfNoAzdataOrEulaNotAccepted();
|
||||
return localAzdata!.arc.postgres.server.list();
|
||||
},
|
||||
show: async (name: string) => {
|
||||
throwIfNoAzdataOrEulaNotAccepted();
|
||||
return localAzdata!.arc.postgres.server.show(name);
|
||||
},
|
||||
edit: async (
|
||||
name: string,
|
||||
args: {
|
||||
adminPassword?: boolean,
|
||||
coresLimit?: string,
|
||||
coresRequest?: string,
|
||||
engineSettings?: string,
|
||||
extensions?: string,
|
||||
memoryLimit?: string,
|
||||
memoryRequest?: string,
|
||||
noWait?: boolean,
|
||||
port?: number,
|
||||
replaceEngineSettings?: boolean,
|
||||
workers?: number
|
||||
},
|
||||
additionalEnvVars?: { [key: string]: string }) => {
|
||||
throwIfNoAzdataOrEulaNotAccepted();
|
||||
return localAzdata!.arc.postgres.server.edit(name, args, additionalEnvVars);
|
||||
}
|
||||
}
|
||||
},
|
||||
sql: {
|
||||
mi: {
|
||||
delete: async (name: string) => {
|
||||
throwIfNoAzdataOrEulaNotAccepted();
|
||||
return localAzdata!.arc.sql.mi.delete(name);
|
||||
},
|
||||
list: async () => {
|
||||
throwIfNoAzdataOrEulaNotAccepted();
|
||||
return localAzdata!.arc.sql.mi.list();
|
||||
},
|
||||
show: async (name: string) => {
|
||||
throwIfNoAzdataOrEulaNotAccepted();
|
||||
return localAzdata!.arc.sql.mi.show(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
getPath: () => {
|
||||
throwIfNoAzdata();
|
||||
return localAzdata!.getPath();
|
||||
},
|
||||
login: async (endpoint: string, username: string, password: string) => {
|
||||
throwIfNoAzdataOrEulaNotAccepted();
|
||||
return localAzdata!.login(endpoint, username, password);
|
||||
},
|
||||
getSemVersion: () => {
|
||||
throwIfNoAzdata();
|
||||
return localAzdata!.getSemVersion();
|
||||
},
|
||||
version: async () => {
|
||||
throwIfNoAzdata();
|
||||
return localAzdata!.version();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
const azdataApi = getExtensionApi(context.globalState, azdataToolService, localAzdataDiscovered);
|
||||
|
||||
function throwIfNoAzdataOrEulaNotAccepted(): void {
|
||||
throwIfNoAzdata();
|
||||
if (!eulaAccepted) {
|
||||
Logger.log(loc.eulaNotAccepted);
|
||||
throw new Error(loc.eulaNotAccepted);
|
||||
}
|
||||
}
|
||||
// register option source(s)
|
||||
const rdApi = <rd.IExtension>vscode.extensions.getExtension(rd.extension.name)?.exports;
|
||||
rdApi.registerOptionsSourceProvider(new ArcControllerConfigProfilesOptionsSource(azdataApi));
|
||||
|
||||
function throwIfNoAzdata() {
|
||||
if (!localAzdata) {
|
||||
Logger.log(loc.noAzdata);
|
||||
throw new NoAzdataError();
|
||||
}
|
||||
return azdataApi;
|
||||
}
|
||||
|
||||
export function deactivate(): void { }
|
||||
|
||||
Reference in New Issue
Block a user