Refactor Azure Core extension for easier resource addition (#7958)

Consolidated most logic into a base class and common resource request pattern.
Reduces cost to add new providers, which will help for SQL Managed Instance support
This commit is contained in:
Kevin Cunnane
2019-10-23 16:29:51 -07:00
committed by GitHub
parent 24e3b1c5e6
commit 806d807eae
20 changed files with 200 additions and 385 deletions

View File

@@ -3,10 +3,9 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { window, QuickPickItem } from 'vscode';
import { AzureResource } from 'azdata';
import * as azdata from 'azdata';
import { TokenCredentials } from 'ms-rest';
import { AppContext } from '../appContext';
import * as nls from 'vscode-nls';
@@ -34,7 +33,7 @@ export function registerAzureResourceCommands(appContext: AppContext, tree: Azur
const subscriptions = (await accountNode.getCachedSubscriptions()) || <azureResource.AzureResourceSubscription[]>[];
if (subscriptions.length === 0) {
try {
const tokens = await this.servicePool.apiWrapper.getSecurityToken(this.account, AzureResource.ResourceManagement);
const tokens = await this.servicePool.apiWrapper.getSecurityToken(this.account, azdata.AzureResource.ResourceManagement);
for (const tenant of this.account.properties.tenants) {
const token = tokens[tenant.id].token;
@@ -86,4 +85,21 @@ export function registerAzureResourceCommands(appContext: AppContext, tree: Azur
appContext.apiWrapper.registerCommand('azure.resource.signin', async (node?: TreeNode) => {
appContext.apiWrapper.executeCommand('workbench.actions.modal.linkedAccount');
});
appContext.apiWrapper.registerCommand('azure.resource.connectsqlserver', async (node?: TreeNode) => {
if (!node) {
return;
}
const treeItem: azdata.TreeItem = await node.getTreeItem();
if (!treeItem.payload) {
return;
}
// Ensure connection is saved to the Connections list, then open connection dialog
let connectionProfile = Object.assign({}, treeItem.payload, { saveProfile: true });
const conn = await appContext.apiWrapper.openConnectionDialog(undefined, connectionProfile, { saveConnection: true, showDashboard: true });
if (conn) {
appContext.apiWrapper.executeCommand('workbench.view.connections');
}
});
}