mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-12 11:08:31 -05:00
azdata startup: install/update commands and configrations (#11924)
* WIP * first version with working tests * fixes needed after merge from main * Linux untest changes and merge from other changes from mac * after testing getTextContent * rename 2 methods * linux discovery * tested code on linux * using release.json for update discovery on linux * comment added * dead code removed * coomments * revert unrelated change * revert testing changes * code complete, testing pending * test complete * PR feedback * remove SendOutputChannelToConsole * cleanup * pr feedback * PR Feedback * pr feedback * pr feedback * pr feedback * fix loc function * install/upgrade command - context sensitive * add awaits as pr feedback * cleanup * merge from main * merge from main * cleanup and pr feedback * PR feedback and cleanup * cleanup * pr feedback * pr feedback. * revert accidental changes * cleanup * test fixes * test fixes and pr feedback * pr fixes and eula similar to install/upgrade * revert extraneous change * log and prompt fixes * string fixes * string updates * string updates based on PR feedback * loc const rename * pr feedback * string fixes * make setContext settings uniform * add commandPallete * eulaAccepted setContext from memento * misc fixes * bug fixes * test fix * skip failinf test for fix later * pr feedback * upgrading -> updating Co-authored-by: chgagnon <chgagnon@microsoft.com>
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
|
||||
import * as azdataExt from 'azdata-ext';
|
||||
import * as vscode from 'vscode';
|
||||
import { findAzdata, IAzdataTool, manuallyInstallOrUpgradeAzdata, promptForEula } from './azdata';
|
||||
import { checkAndInstallAzdata, checkAndUpdateAzdata, findAzdata, IAzdataTool, promptForEula } from './azdata';
|
||||
import Logger from './common/logger';
|
||||
import * as constants from './constants';
|
||||
import * as loc from './localizedConstants';
|
||||
@@ -14,41 +14,71 @@ let localAzdata: IAzdataTool | undefined = undefined;
|
||||
let eulaAccepted: boolean = false;
|
||||
|
||||
export async function activate(context: vscode.ExtensionContext): Promise<azdataExt.IExtension> {
|
||||
localAzdata = await checkForAzdata();
|
||||
eulaAccepted = !!context.globalState.get(constants.acceptEula);
|
||||
vscode.commands.registerCommand('azdata.acceptEula', async () => {
|
||||
eulaAccepted = await promptForEula(context.globalState, true /* userRequested */);
|
||||
|
||||
});
|
||||
|
||||
vscode.commands.registerCommand('azdata.install', async () => {
|
||||
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
|
||||
}
|
||||
});
|
||||
|
||||
eulaAccepted = !!context.globalState.get<boolean>(constants.eulaAccepted); // 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));
|
||||
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.
|
||||
promptForEula(context.globalState)
|
||||
.then(userResponse => {
|
||||
.then(async (userResponse: boolean) => {
|
||||
eulaAccepted = userResponse;
|
||||
})
|
||||
.catch(err => console.log(err));
|
||||
.catch((err) => console.log(err));
|
||||
}
|
||||
// Don't block on this since we want the extension to finish activating without user actions
|
||||
manuallyInstallOrUpgradeAzdata(context, localAzdata)
|
||||
.catch(err => console.log(err));
|
||||
|
||||
// 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.
|
||||
.then(async azdataTool => {
|
||||
localAzdata = azdataTool;
|
||||
if (localAzdata !== undefined) {
|
||||
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
|
||||
}
|
||||
} catch (err) {
|
||||
vscode.window.showWarningMessage(loc.updateError(err));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
azdata: {
|
||||
arc: {
|
||||
dc: {
|
||||
create: async (namespace: string, name: string, connectivityMode: string, resourceGroup: string, location: string, subscription: string, profileName?: string, storageClass?: string) => {
|
||||
await throwIfNoAzdataOrEulaNotAccepted(context);
|
||||
await throwIfNoAzdataOrEulaNotAccepted();
|
||||
return localAzdata!.arc.dc.create(namespace, name, connectivityMode, resourceGroup, location, subscription, profileName, storageClass);
|
||||
},
|
||||
endpoint: {
|
||||
list: async () => {
|
||||
await throwIfNoAzdataOrEulaNotAccepted(context);
|
||||
await throwIfNoAzdataOrEulaNotAccepted();
|
||||
return localAzdata!.arc.dc.endpoint.list();
|
||||
}
|
||||
},
|
||||
config: {
|
||||
list: async () => {
|
||||
await throwIfNoAzdataOrEulaNotAccepted(context);
|
||||
await throwIfNoAzdataOrEulaNotAccepted();
|
||||
return localAzdata!.arc.dc.config.list();
|
||||
},
|
||||
show: async () => {
|
||||
await throwIfNoAzdataOrEulaNotAccepted(context);
|
||||
await throwIfNoAzdataOrEulaNotAccepted();
|
||||
return localAzdata!.arc.dc.config.show();
|
||||
}
|
||||
}
|
||||
@@ -56,11 +86,11 @@ export async function activate(context: vscode.ExtensionContext): Promise<azdata
|
||||
postgres: {
|
||||
server: {
|
||||
list: async () => {
|
||||
await throwIfNoAzdataOrEulaNotAccepted(context);
|
||||
await throwIfNoAzdataOrEulaNotAccepted();
|
||||
return localAzdata!.arc.postgres.server.list();
|
||||
},
|
||||
show: async (name: string) => {
|
||||
await throwIfNoAzdataOrEulaNotAccepted(context);
|
||||
await throwIfNoAzdataOrEulaNotAccepted();
|
||||
return localAzdata!.arc.postgres.server.show(name);
|
||||
}
|
||||
}
|
||||
@@ -68,72 +98,41 @@ export async function activate(context: vscode.ExtensionContext): Promise<azdata
|
||||
sql: {
|
||||
mi: {
|
||||
delete: async (name: string) => {
|
||||
await throwIfNoAzdataOrEulaNotAccepted(context);
|
||||
await throwIfNoAzdataOrEulaNotAccepted();
|
||||
return localAzdata!.arc.sql.mi.delete(name);
|
||||
},
|
||||
list: async () => {
|
||||
await throwIfNoAzdataOrEulaNotAccepted(context);
|
||||
await throwIfNoAzdataOrEulaNotAccepted();
|
||||
return localAzdata!.arc.sql.mi.list();
|
||||
},
|
||||
show: async (name: string) => {
|
||||
await throwIfNoAzdataOrEulaNotAccepted(context);
|
||||
await throwIfNoAzdataOrEulaNotAccepted();
|
||||
return localAzdata!.arc.sql.mi.show(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
login: async (endpoint: string, username: string, password: string) => {
|
||||
await throwIfNoAzdataOrEulaNotAccepted(context);
|
||||
await throwIfNoAzdataOrEulaNotAccepted();
|
||||
return localAzdata!.login(endpoint, username, password);
|
||||
},
|
||||
version: async () => {
|
||||
await throwIfNoAzdataOrEulaNotAccepted(context);
|
||||
await throwIfNoAzdataOrEulaNotAccepted();
|
||||
return localAzdata!.version();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
async function throwIfNoAzdataOrEulaNotAccepted(context: vscode.ExtensionContext): Promise<void> {
|
||||
async function throwIfNoAzdataOrEulaNotAccepted(): Promise<void> {
|
||||
if (!localAzdata) {
|
||||
Logger.log(loc.noAzdata);
|
||||
throw new Error(loc.noAzdata);
|
||||
}
|
||||
if (!eulaAccepted) {
|
||||
eulaAccepted = await promptForEula(context.globalState);
|
||||
}
|
||||
if (!eulaAccepted) {
|
||||
Logger.log(loc.eulaNotAccepted);
|
||||
throw new Error(loc.eulaNotAccepted);
|
||||
}
|
||||
}
|
||||
|
||||
async function checkForAzdata(): Promise<IAzdataTool | undefined> {
|
||||
try {
|
||||
return await findAzdata(); // find currently installed Azdata
|
||||
} catch (err) {
|
||||
// Don't block on this since we want the extension to finish activating without needing user input.
|
||||
// Calls will be made to handle azdata not being installed
|
||||
await promptToInstallAzdata().catch(e => console.log(`Unexpected error prompting to install azdata ${e}`));
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
async function promptToInstallAzdata(): Promise<void> {
|
||||
//TODO: Figure out better way to display/prompt
|
||||
/*
|
||||
const response = await vscode.window.showErrorMessage(loc.couldNotFindAzdataWithPrompt, loc.install, loc.cancel);
|
||||
if (response === loc.install) {
|
||||
try {
|
||||
await downloadAndInstallAzdata();
|
||||
vscode.window.showInformationMessage(loc.azdataInstalled);
|
||||
} catch (err) {
|
||||
// Windows: 1602 is User Cancelling installation - not unexpected so don't display
|
||||
if (!(err instanceof ExitCodeError) || err.code !== 1602) {
|
||||
vscode.window.showWarningMessage(loc.installError(err));
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
export function deactivate(): void { }
|
||||
|
||||
Reference in New Issue
Block a user