mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
Remove AzureCore ApiWrapper (#11335)
This commit is contained in:
@@ -3,9 +3,8 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
import { window, QuickPickItem, env, Uri } from 'vscode';
|
||||
import * as azdata from 'azdata';
|
||||
import * as vscode from 'vscode';
|
||||
import { TokenCredentials } from '@azure/ms-rest-js';
|
||||
import * as nls from 'vscode-nls';
|
||||
const localize = nls.loadMessageBundle();
|
||||
@@ -21,12 +20,12 @@ import { AzureResourceServiceNames } from './constants';
|
||||
import { AzureAccount, Tenant } from '../account-provider/interfaces';
|
||||
|
||||
export function registerAzureResourceCommands(appContext: AppContext, tree: AzureResourceTreeProvider): void {
|
||||
appContext.apiWrapper.registerCommand('azure.resource.startterminal', async (node?: TreeNode) => {
|
||||
vscode.commands.registerCommand('azure.resource.startterminal', async (node?: TreeNode) => {
|
||||
try {
|
||||
const enablePreviewFeatures = appContext.apiWrapper.getConfiguration('workbench').get('enablePreviewFeatures');
|
||||
const enablePreviewFeatures = vscode.workspace.getConfiguration('workbench').get('enablePreviewFeatures');
|
||||
if (!enablePreviewFeatures) {
|
||||
const msg = localize('azure.cloudTerminalPreview', "You must enable preview features in order to use Azure Cloud Shell.");
|
||||
appContext.apiWrapper.showInformationMessage(msg);
|
||||
vscode.window.showInformationMessage(msg);
|
||||
return;
|
||||
}
|
||||
if (!node || !(node instanceof AzureResourceAccountTreeNode)) {
|
||||
@@ -36,28 +35,28 @@ export function registerAzureResourceCommands(appContext: AppContext, tree: Azur
|
||||
const accountNode = node as AzureResourceAccountTreeNode;
|
||||
const azureAccount = accountNode.account as AzureAccount;
|
||||
|
||||
const tokens = await appContext.apiWrapper.getSecurityToken(azureAccount, azdata.AzureResource.MicrosoftResourceManagement);
|
||||
const tokens = await azdata.accounts.getSecurityToken(azureAccount, azdata.AzureResource.MicrosoftResourceManagement);
|
||||
|
||||
const terminalService = appContext.getService<IAzureTerminalService>(AzureResourceServiceNames.terminalService);
|
||||
|
||||
const listOfTenants = azureAccount.properties.tenants.map(t => t.displayName);
|
||||
|
||||
if (listOfTenants.length === 0) {
|
||||
window.showErrorMessage(localize('azure.noTenants', "A tenant is required for this feature. Your Azure subscription seems to have no tenants."));
|
||||
vscode.window.showErrorMessage(localize('azure.noTenants', "A tenant is required for this feature. Your Azure subscription seems to have no tenants."));
|
||||
return;
|
||||
}
|
||||
|
||||
let tenant: Tenant;
|
||||
window.setStatusBarMessage(localize('azure.startingCloudShell', "Starting cloud shell…"), 5000);
|
||||
vscode.window.setStatusBarMessage(localize('azure.startingCloudShell', "Starting cloud shell…"), 5000);
|
||||
|
||||
if (listOfTenants.length === 1) {
|
||||
// Don't show quickpick for a single option
|
||||
tenant = azureAccount.properties.tenants[0];
|
||||
} else {
|
||||
const pickedTenant = await window.showQuickPick(listOfTenants, { canPickMany: false });
|
||||
const pickedTenant = await vscode.window.showQuickPick(listOfTenants, { canPickMany: false });
|
||||
|
||||
if (!pickedTenant) {
|
||||
window.showErrorMessage(localize('azure.mustPickTenant', "You must select a tenant for this feature to work."));
|
||||
vscode.window.showErrorMessage(localize('azure.mustPickTenant', "You must select a tenant for this feature to work."));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -68,13 +67,13 @@ export function registerAzureResourceCommands(appContext: AppContext, tree: Azur
|
||||
await terminalService.getOrCreateCloudConsole(azureAccount, tenant, tokens);
|
||||
} catch (ex) {
|
||||
console.error(ex);
|
||||
window.showErrorMessage(ex);
|
||||
vscode.window.showErrorMessage(ex);
|
||||
}
|
||||
});
|
||||
|
||||
// Resource Tree commands
|
||||
|
||||
appContext.apiWrapper.registerCommand('azure.resource.selectsubscriptions', async (node?: TreeNode) => {
|
||||
vscode.commands.registerCommand('azure.resource.selectsubscriptions', async (node?: TreeNode) => {
|
||||
if (!(node instanceof AzureResourceAccountTreeNode)) {
|
||||
return;
|
||||
}
|
||||
@@ -92,7 +91,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(account, azdata.AzureResource.ResourceManagement);
|
||||
const tokens = await azdata.accounts.getSecurityToken(account, azdata.AzureResource.ResourceManagement);
|
||||
|
||||
for (const tenant of account.properties.tenants) {
|
||||
const token = tokens[tenant.id].token;
|
||||
@@ -119,7 +118,7 @@ export function registerAzureResourceCommands(appContext: AppContext, tree: Azur
|
||||
selectedSubscriptionIds.push(...subscriptions.map((subscription) => subscription.id));
|
||||
}
|
||||
|
||||
interface AzureResourceSubscriptionQuickPickItem extends QuickPickItem {
|
||||
interface AzureResourceSubscriptionQuickPickItem extends vscode.QuickPickItem {
|
||||
subscription: azureResource.AzureResourceSubscription;
|
||||
}
|
||||
|
||||
@@ -131,7 +130,7 @@ export function registerAzureResourceCommands(appContext: AppContext, tree: Azur
|
||||
};
|
||||
}).sort((a, b) => a.label.localeCompare(b.label));
|
||||
|
||||
const selectedSubscriptionQuickPickItems = await window.showQuickPick(subscriptionQuickPickItems, { canPickMany: true });
|
||||
const selectedSubscriptionQuickPickItems = await vscode.window.showQuickPick(subscriptionQuickPickItems, { canPickMany: true });
|
||||
if (selectedSubscriptionQuickPickItems && selectedSubscriptionQuickPickItems.length > 0) {
|
||||
await tree.refresh(node, false);
|
||||
|
||||
@@ -140,17 +139,17 @@ export function registerAzureResourceCommands(appContext: AppContext, tree: Azur
|
||||
}
|
||||
});
|
||||
|
||||
appContext.apiWrapper.registerCommand('azure.resource.refreshall', () => tree.notifyNodeChanged(undefined));
|
||||
vscode.commands.registerCommand('azure.resource.refreshall', () => tree.notifyNodeChanged(undefined));
|
||||
|
||||
appContext.apiWrapper.registerCommand('azure.resource.refresh', async (node?: TreeNode) => {
|
||||
vscode.commands.registerCommand('azure.resource.refresh', async (node?: TreeNode) => {
|
||||
await tree.refresh(node, true);
|
||||
});
|
||||
|
||||
appContext.apiWrapper.registerCommand('azure.resource.signin', async (node?: TreeNode) => {
|
||||
appContext.apiWrapper.executeCommand('workbench.actions.modal.linkedAccount');
|
||||
vscode.commands.registerCommand('azure.resource.signin', async (node?: TreeNode) => {
|
||||
vscode.commands.executeCommand('workbench.actions.modal.linkedAccount');
|
||||
});
|
||||
|
||||
appContext.apiWrapper.registerCommand('azure.resource.connectsqlserver', async (node?: TreeNode) => {
|
||||
vscode.commands.registerCommand('azure.resource.connectsqlserver', async (node?: TreeNode) => {
|
||||
if (!node) {
|
||||
return;
|
||||
}
|
||||
@@ -161,13 +160,13 @@ export function registerAzureResourceCommands(appContext: AppContext, tree: Azur
|
||||
}
|
||||
// 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 });
|
||||
const conn = await azdata.connection.openConnectionDialog(undefined, connectionProfile, { saveConnection: true, showDashboard: true });
|
||||
if (conn) {
|
||||
appContext.apiWrapper.executeCommand('workbench.view.connections');
|
||||
vscode.commands.executeCommand('workbench.view.connections');
|
||||
}
|
||||
});
|
||||
|
||||
appContext.apiWrapper.registerCommand('azure.resource.openInAzurePortal', async (connectionProfile: azdata.IConnectionProfile) => {
|
||||
vscode.commands.registerCommand('azure.resource.openInAzurePortal', async (connectionProfile: azdata.IConnectionProfile) => {
|
||||
|
||||
if (
|
||||
!connectionProfile.azureResourceId ||
|
||||
@@ -178,6 +177,6 @@ export function registerAzureResourceCommands(appContext: AppContext, tree: Azur
|
||||
}
|
||||
|
||||
const urlToOpen = `${connectionProfile.azurePortalEndpoint}//${connectionProfile.azureTenantId}/#resource/${connectionProfile.azureResourceId}`;
|
||||
env.openExternal(Uri.parse(urlToOpen));
|
||||
vscode.env.openExternal(vscode.Uri.parse(urlToOpen));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -5,17 +5,11 @@
|
||||
|
||||
import * as msRest from '@azure/ms-rest-js';
|
||||
|
||||
import { Account, DidChangeAccountsParams } from 'azdata';
|
||||
import { Event } from 'vscode';
|
||||
import { Account } from 'azdata';
|
||||
|
||||
import { azureResource } from './azure-resource';
|
||||
import { AzureAccount, AzureAccountSecurityToken, Tenant } from '../account-provider/interfaces';
|
||||
|
||||
export interface IAzureResourceAccountService {
|
||||
getAccounts(): Promise<Account[]>;
|
||||
readonly onDidChangeAccounts: Event<DidChangeAccountsParams>;
|
||||
}
|
||||
|
||||
export interface IAzureResourceSubscriptionService {
|
||||
getSubscriptions(account: Account, credential: msRest.ServiceClientCredentials): Promise<azureResource.AzureResourceSubscription[]>;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
|
||||
|
||||
import { ExtensionContext } from 'vscode';
|
||||
import { ApiWrapper } from '../../../apiWrapper';
|
||||
|
||||
import { azureResource } from '../../azure-resource';
|
||||
import { AzureResourceDatabaseTreeDataProvider } from './databaseTreeDataProvider';
|
||||
@@ -14,13 +13,12 @@ import { IAzureResourceService } from '../../interfaces';
|
||||
export class AzureResourceDatabaseProvider implements azureResource.IAzureResourceProvider {
|
||||
public constructor(
|
||||
private _databaseService: IAzureResourceService<azureResource.AzureResourceDatabase>,
|
||||
private _apiWrapper: ApiWrapper,
|
||||
private _extensionContext: ExtensionContext
|
||||
) {
|
||||
}
|
||||
|
||||
public getTreeDataProvider(): azureResource.IAzureResourceTreeDataProvider {
|
||||
return new AzureResourceDatabaseTreeDataProvider(this._databaseService, this._apiWrapper, this._extensionContext);
|
||||
return new AzureResourceDatabaseTreeDataProvider(this._databaseService, this._extensionContext);
|
||||
}
|
||||
|
||||
public get providerId(): string {
|
||||
|
||||
@@ -10,7 +10,6 @@ const localize = nls.loadMessageBundle();
|
||||
|
||||
import { azureResource } from '../../azure-resource';
|
||||
import { AzureResourceItemType } from '../../../azureResource/constants';
|
||||
import { ApiWrapper } from '../../../apiWrapper';
|
||||
import { generateGuid } from '../../utils';
|
||||
import { IAzureResourceService } from '../../interfaces';
|
||||
import { ResourceTreeDataProviderBase } from '../resourceTreeDataProviderBase';
|
||||
@@ -22,10 +21,9 @@ export class AzureResourceDatabaseTreeDataProvider extends ResourceTreeDataProvi
|
||||
|
||||
public constructor(
|
||||
databaseService: IAzureResourceService<azureResource.AzureResourceDatabase>,
|
||||
apiWrapper: ApiWrapper,
|
||||
private _extensionContext: ExtensionContext
|
||||
) {
|
||||
super(databaseService, apiWrapper);
|
||||
super(databaseService);
|
||||
}
|
||||
protected getTreeItemForResource(database: azureResource.AzureResourceDatabase, account: Account): TreeItem {
|
||||
return {
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { ExtensionContext } from 'vscode';
|
||||
import { ApiWrapper } from '../../../apiWrapper';
|
||||
|
||||
import { azureResource } from '../../azure-resource';
|
||||
import { IAzureResourceService } from '../../interfaces';
|
||||
@@ -13,13 +12,12 @@ import { AzureResourceDatabaseServerTreeDataProvider } from './databaseServerTre
|
||||
export class AzureResourceDatabaseServerProvider implements azureResource.IAzureResourceProvider {
|
||||
public constructor(
|
||||
private _databaseServerService: IAzureResourceService<azureResource.AzureResourceDatabaseServer>,
|
||||
private _apiWrapper: ApiWrapper,
|
||||
private _extensionContext: ExtensionContext
|
||||
) {
|
||||
}
|
||||
|
||||
public getTreeDataProvider(): azureResource.IAzureResourceTreeDataProvider {
|
||||
return new AzureResourceDatabaseServerTreeDataProvider(this._databaseServerService, this._apiWrapper, this._extensionContext);
|
||||
return new AzureResourceDatabaseServerTreeDataProvider(this._databaseServerService, this._extensionContext);
|
||||
}
|
||||
|
||||
public get providerId(): string {
|
||||
|
||||
@@ -9,7 +9,6 @@ import * as nls from 'vscode-nls';
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
import { AzureResourceItemType } from '../../../azureResource/constants';
|
||||
import { ApiWrapper } from '../../../apiWrapper';
|
||||
import { generateGuid } from '../../utils';
|
||||
import { IAzureResourceService } from '../../interfaces';
|
||||
import { ResourceTreeDataProviderBase } from '../resourceTreeDataProviderBase';
|
||||
@@ -21,10 +20,9 @@ export class AzureResourceDatabaseServerTreeDataProvider extends ResourceTreeDat
|
||||
|
||||
public constructor(
|
||||
databaseServerService: IAzureResourceService<azureResource.AzureResourceDatabaseServer>,
|
||||
apiWrapper: ApiWrapper,
|
||||
private _extensionContext: ExtensionContext
|
||||
) {
|
||||
super(databaseServerService, apiWrapper);
|
||||
super(databaseServerService);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { ExtensionContext } from 'vscode';
|
||||
import { ApiWrapper } from '../../../apiWrapper';
|
||||
|
||||
import { azureResource } from '../../azure-resource';
|
||||
import { IAzureResourceService } from '../../interfaces';
|
||||
@@ -13,13 +12,12 @@ import { PostgresServerArcTreeDataProvider as PostgresServerArcTreeDataProvider
|
||||
export class PostgresServerArcProvider implements azureResource.IAzureResourceProvider {
|
||||
public constructor(
|
||||
private _databaseServerService: IAzureResourceService<azureResource.AzureResourceDatabaseServer>,
|
||||
private _apiWrapper: ApiWrapper,
|
||||
private _extensionContext: ExtensionContext
|
||||
) {
|
||||
}
|
||||
|
||||
public getTreeDataProvider(): azureResource.IAzureResourceTreeDataProvider {
|
||||
return new PostgresServerArcTreeDataProvider(this._databaseServerService, this._apiWrapper, this._extensionContext);
|
||||
return new PostgresServerArcTreeDataProvider(this._databaseServerService, this._extensionContext);
|
||||
}
|
||||
|
||||
public get providerId(): string {
|
||||
|
||||
@@ -9,7 +9,6 @@ import * as nls from 'vscode-nls';
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
import { AzureResourceItemType } from '../../constants';
|
||||
import { ApiWrapper } from '../../../apiWrapper';
|
||||
import { generateGuid } from '../../utils';
|
||||
import { IAzureResourceService } from '../../interfaces';
|
||||
import { ResourceTreeDataProviderBase } from '../resourceTreeDataProviderBase';
|
||||
@@ -21,10 +20,9 @@ export class PostgresServerArcTreeDataProvider extends ResourceTreeDataProviderB
|
||||
|
||||
public constructor(
|
||||
databaseServerService: IAzureResourceService<azureResource.AzureResourceDatabaseServer>,
|
||||
apiWrapper: ApiWrapper,
|
||||
private _extensionContext: ExtensionContext
|
||||
) {
|
||||
super(databaseServerService, apiWrapper);
|
||||
super(databaseServerService);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { ExtensionContext } from 'vscode';
|
||||
import { ApiWrapper } from '../../../apiWrapper';
|
||||
|
||||
import { azureResource } from '../../azure-resource';
|
||||
import { IAzureResourceService } from '../../interfaces';
|
||||
@@ -13,13 +12,12 @@ import { PostgresServerTreeDataProvider as PostgresServerTreeDataProvider } from
|
||||
export class PostgresServerProvider implements azureResource.IAzureResourceProvider {
|
||||
public constructor(
|
||||
private _databaseServerService: IAzureResourceService<azureResource.AzureResourceDatabaseServer>,
|
||||
private _apiWrapper: ApiWrapper,
|
||||
private _extensionContext: ExtensionContext
|
||||
) {
|
||||
}
|
||||
|
||||
public getTreeDataProvider(): azureResource.IAzureResourceTreeDataProvider {
|
||||
return new PostgresServerTreeDataProvider(this._databaseServerService, this._apiWrapper, this._extensionContext);
|
||||
return new PostgresServerTreeDataProvider(this._databaseServerService, this._extensionContext);
|
||||
}
|
||||
|
||||
public get providerId(): string {
|
||||
|
||||
@@ -9,7 +9,6 @@ import * as nls from 'vscode-nls';
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
import { AzureResourceItemType } from '../../constants';
|
||||
import { ApiWrapper } from '../../../apiWrapper';
|
||||
import { generateGuid } from '../../utils';
|
||||
import { IAzureResourceService } from '../../interfaces';
|
||||
import { ResourceTreeDataProviderBase } from '../resourceTreeDataProviderBase';
|
||||
@@ -21,10 +20,9 @@ export class PostgresServerTreeDataProvider extends ResourceTreeDataProviderBase
|
||||
|
||||
public constructor(
|
||||
databaseServerService: IAzureResourceService<azureResource.AzureResourceDatabaseServer>,
|
||||
apiWrapper: ApiWrapper,
|
||||
private _extensionContext: ExtensionContext
|
||||
) {
|
||||
super(databaseServerService, apiWrapper);
|
||||
super(databaseServerService);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -7,17 +7,13 @@ import * as azdata from 'azdata';
|
||||
import * as msRest from '@azure/ms-rest-js';
|
||||
|
||||
import { azureResource } from '../azure-resource';
|
||||
import { ApiWrapper } from '../../apiWrapper';
|
||||
import { IAzureResourceService } from '../interfaces';
|
||||
import { AzureResourceErrorMessageUtil } from '../utils';
|
||||
import { ResourceGraphClient } from '@azure/arm-resourcegraph';
|
||||
|
||||
export abstract class ResourceTreeDataProviderBase<T extends azureResource.AzureResource> implements azureResource.IAzureResourceTreeDataProvider {
|
||||
|
||||
public constructor(
|
||||
protected _resourceService: IAzureResourceService<T>,
|
||||
protected _apiWrapper: ApiWrapper
|
||||
) {
|
||||
public constructor(protected _resourceService: IAzureResourceService<T>) {
|
||||
}
|
||||
|
||||
public getTreeItem(element: azureResource.IAzureResourceNode): azdata.TreeItem | Thenable<azdata.TreeItem> {
|
||||
@@ -45,7 +41,7 @@ export abstract class ResourceTreeDataProviderBase<T extends azureResource.Azure
|
||||
}
|
||||
|
||||
private async getResources(element: azureResource.IAzureResourceNode): Promise<T[]> {
|
||||
const tokens = await this._apiWrapper.getSecurityToken(element.account, azdata.AzureResource.ResourceManagement);
|
||||
const tokens = await azdata.accounts.getSecurityToken(element.account, azdata.AzureResource.ResourceManagement);
|
||||
const credential = new msRest.TokenCredentials(tokens[element.tenantId].token, tokens[element.tenantId].tokenType);
|
||||
|
||||
const resources: T[] = await this._resourceService.getResources(element.subscription, credential, element.account) || <T[]>[];
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { ExtensionContext } from 'vscode';
|
||||
import { ApiWrapper } from '../../../apiWrapper';
|
||||
|
||||
import { azureResource } from '../../azure-resource';
|
||||
import { IAzureResourceService } from '../../interfaces';
|
||||
@@ -13,13 +12,12 @@ import { SqlInstanceTreeDataProvider as SqlInstanceTreeDataProvider } from './sq
|
||||
export class SqlInstanceProvider implements azureResource.IAzureResourceProvider {
|
||||
public constructor(
|
||||
private _service: IAzureResourceService<azureResource.AzureResourceDatabaseServer>,
|
||||
private _apiWrapper: ApiWrapper,
|
||||
private _extensionContext: ExtensionContext
|
||||
) {
|
||||
}
|
||||
|
||||
public getTreeDataProvider(): azureResource.IAzureResourceTreeDataProvider {
|
||||
return new SqlInstanceTreeDataProvider(this._service, this._apiWrapper, this._extensionContext);
|
||||
return new SqlInstanceTreeDataProvider(this._service, this._extensionContext);
|
||||
}
|
||||
|
||||
public get providerId(): string {
|
||||
|
||||
@@ -9,7 +9,6 @@ import * as nls from 'vscode-nls';
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
import { AzureResourceItemType } from '../../constants';
|
||||
import { ApiWrapper } from '../../../apiWrapper';
|
||||
import { generateGuid } from '../../utils';
|
||||
import { IAzureResourceService } from '../../interfaces';
|
||||
import { ResourceTreeDataProviderBase } from '../resourceTreeDataProviderBase';
|
||||
@@ -21,10 +20,9 @@ export class SqlInstanceTreeDataProvider extends ResourceTreeDataProviderBase<az
|
||||
|
||||
public constructor(
|
||||
databaseServerService: IAzureResourceService<azureResource.AzureResourceDatabaseServer>,
|
||||
apiWrapper: ApiWrapper,
|
||||
private _extensionContext: ExtensionContext
|
||||
) {
|
||||
super(databaseServerService, apiWrapper);
|
||||
super(databaseServerService);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { ExtensionContext } from 'vscode';
|
||||
import { ApiWrapper } from '../../../apiWrapper';
|
||||
|
||||
import { azureResource } from '../../azure-resource';
|
||||
import { IAzureResourceService } from '../../interfaces';
|
||||
@@ -13,13 +12,12 @@ import { SqlInstanceArcTreeDataProvider as SqlInstanceArcTreeDataProvider } from
|
||||
export class SqlInstanceArcProvider implements azureResource.IAzureResourceProvider {
|
||||
public constructor(
|
||||
private _service: IAzureResourceService<azureResource.AzureResourceDatabaseServer>,
|
||||
private _apiWrapper: ApiWrapper,
|
||||
private _extensionContext: ExtensionContext
|
||||
) {
|
||||
}
|
||||
|
||||
public getTreeDataProvider(): azureResource.IAzureResourceTreeDataProvider {
|
||||
return new SqlInstanceArcTreeDataProvider(this._service, this._apiWrapper, this._extensionContext);
|
||||
return new SqlInstanceArcTreeDataProvider(this._service, this._extensionContext);
|
||||
}
|
||||
|
||||
public get providerId(): string {
|
||||
|
||||
@@ -9,7 +9,6 @@ import * as nls from 'vscode-nls';
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
import { AzureResourceItemType } from '../../constants';
|
||||
import { ApiWrapper } from '../../../apiWrapper';
|
||||
import { generateGuid } from '../../utils';
|
||||
import { IAzureResourceService } from '../../interfaces';
|
||||
import { ResourceTreeDataProviderBase } from '../resourceTreeDataProviderBase';
|
||||
@@ -21,10 +20,9 @@ export class SqlInstanceArcTreeDataProvider extends ResourceTreeDataProviderBase
|
||||
|
||||
public constructor(
|
||||
databaseServerService: IAzureResourceService<azureResource.AzureResourceDatabaseServer>,
|
||||
apiWrapper: ApiWrapper,
|
||||
private _extensionContext: ExtensionContext
|
||||
) {
|
||||
super(databaseServerService, apiWrapper);
|
||||
super(databaseServerService);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { Event } from 'vscode';
|
||||
import { Account, DidChangeAccountsParams } from 'azdata';
|
||||
import { ApiWrapper } from '../../apiWrapper';
|
||||
|
||||
import { IAzureResourceAccountService } from '../interfaces';
|
||||
|
||||
export class AzureResourceAccountService implements IAzureResourceAccountService {
|
||||
public constructor(
|
||||
apiWrapper: ApiWrapper
|
||||
) {
|
||||
this._apiWrapper = apiWrapper;
|
||||
this._onDidChangeAccounts = this._apiWrapper.onDidChangeAccounts;
|
||||
}
|
||||
|
||||
public async getAccounts(): Promise<Account[]> {
|
||||
return await this._apiWrapper.getAllAccounts();
|
||||
}
|
||||
|
||||
public get onDidChangeAccounts(): Event<DidChangeAccountsParams> {
|
||||
return this._onDidChangeAccounts;
|
||||
}
|
||||
|
||||
private _apiWrapper: ApiWrapper = undefined;
|
||||
private _onDidChangeAccounts: Event<DidChangeAccountsParams> = undefined;
|
||||
}
|
||||
@@ -3,8 +3,8 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { TreeItem, TreeItemCollapsibleState } from 'vscode';
|
||||
import { Account, NodeInfo, AzureResource } from 'azdata';
|
||||
import * as vscode from 'vscode';
|
||||
import * as azdata from 'azdata';
|
||||
import { TokenCredentials } from '@azure/ms-rest-js';
|
||||
|
||||
import * as nls from 'vscode-nls';
|
||||
@@ -24,7 +24,7 @@ import { IAzureResourceSubscriptionService, IAzureResourceSubscriptionFilterServ
|
||||
|
||||
export class AzureResourceAccountTreeNode extends AzureResourceContainerTreeNodeBase {
|
||||
public constructor(
|
||||
public readonly account: Account,
|
||||
public readonly account: azdata.Account,
|
||||
appContext: AppContext,
|
||||
treeChangeHandler: IAzureResourceTreeChangeHandler
|
||||
) {
|
||||
@@ -42,7 +42,7 @@ export class AzureResourceAccountTreeNode extends AzureResourceContainerTreeNode
|
||||
public async getChildren(): Promise<TreeNode[]> {
|
||||
try {
|
||||
let subscriptions: azureResource.AzureResourceSubscription[] = [];
|
||||
const tokens = await this.appContext.apiWrapper.getSecurityToken(this.account, AzureResource.ResourceManagement);
|
||||
const tokens = await azdata.accounts.getSecurityToken(this.account, azdata.AzureResource.ResourceManagement);
|
||||
|
||||
if (this._isClearingCache) {
|
||||
try {
|
||||
@@ -99,7 +99,7 @@ export class AzureResourceAccountTreeNode extends AzureResourceContainerTreeNode
|
||||
}
|
||||
} catch (error) {
|
||||
if (error instanceof AzureResourceCredentialError) {
|
||||
this.appContext.apiWrapper.executeCommand('azure.resource.signin');
|
||||
vscode.commands.executeCommand('azure.resource.signin');
|
||||
}
|
||||
return [AzureResourceMessageTreeNode.create(AzureResourceErrorMessageUtil.getErrorMessage(error), this)];
|
||||
}
|
||||
@@ -109,8 +109,8 @@ export class AzureResourceAccountTreeNode extends AzureResourceContainerTreeNode
|
||||
return this.getCache<azureResource.AzureResourceSubscription[]>();
|
||||
}
|
||||
|
||||
public getTreeItem(): TreeItem | Promise<TreeItem> {
|
||||
const item = new TreeItem(this._label, TreeItemCollapsibleState.Collapsed);
|
||||
public getTreeItem(): vscode.TreeItem | Promise<vscode.TreeItem> {
|
||||
const item = new vscode.TreeItem(this._label, vscode.TreeItemCollapsibleState.Collapsed);
|
||||
item.id = this._id;
|
||||
item.contextValue = AzureResourceItemType.account;
|
||||
item.iconPath = {
|
||||
@@ -120,7 +120,7 @@ export class AzureResourceAccountTreeNode extends AzureResourceContainerTreeNode
|
||||
return item;
|
||||
}
|
||||
|
||||
public getNodeInfo(): NodeInfo {
|
||||
public getNodeInfo(): azdata.NodeInfo {
|
||||
return {
|
||||
label: this._label,
|
||||
isLeaf: false,
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { TreeDataProvider, EventEmitter, Event, TreeItem } from 'vscode';
|
||||
import * as vscode from 'vscode';
|
||||
import * as azdata from 'azdata';
|
||||
import { AppContext } from '../../appContext';
|
||||
import * as nls from 'vscode-nls';
|
||||
@@ -16,41 +16,29 @@ import { AzureResourceMessageTreeNode } from '../messageTreeNode';
|
||||
import { AzureResourceContainerTreeNodeBase } from './baseTreeNodes';
|
||||
import { AzureResourceErrorMessageUtil, equals } from '../utils';
|
||||
import { IAzureResourceTreeChangeHandler } from './treeChangeHandler';
|
||||
import { IAzureResourceAccountService } from '../../azureResource/interfaces';
|
||||
import { AzureResourceServiceNames } from '../constants';
|
||||
|
||||
|
||||
export class AzureResourceTreeProvider implements TreeDataProvider<TreeNode>, IAzureResourceTreeChangeHandler {
|
||||
export class AzureResourceTreeProvider implements vscode.TreeDataProvider<TreeNode>, IAzureResourceTreeChangeHandler {
|
||||
public isSystemInitialized: boolean = false;
|
||||
|
||||
private accountService: IAzureResourceAccountService;
|
||||
private accounts: azdata.Account[];
|
||||
private _onDidChangeTreeData = new EventEmitter<TreeNode>();
|
||||
private _onDidChangeTreeData = new vscode.EventEmitter<TreeNode>();
|
||||
private loadingAccountsPromise: Promise<void>;
|
||||
|
||||
public constructor(public readonly appContext: AppContext) {
|
||||
if (appContext) {
|
||||
this.hookAccountService(appContext);
|
||||
}
|
||||
}
|
||||
|
||||
private hookAccountService(appContext: AppContext): void {
|
||||
this.accountService = appContext.getService<IAzureResourceAccountService>(AzureResourceServiceNames.accountService);
|
||||
if (this.accountService) {
|
||||
this.accountService.onDidChangeAccounts(async (e: azdata.DidChangeAccountsParams) => {
|
||||
// This event sends it per provider, we need to make sure we get all the azure related accounts
|
||||
let accounts = await this.accountService.getAccounts();
|
||||
accounts = accounts.filter(a => a.key.providerId.startsWith('azure'));
|
||||
// the onDidChangeAccounts event will trigger in many cases where the accounts didn't actually change
|
||||
// the notifyNodeChanged event triggers a refresh which triggers a getChildren which can trigger this callback
|
||||
// this below check short-circuits the infinite callback loop
|
||||
this.setSystemInitialized();
|
||||
if (!equals(accounts, this.accounts)) {
|
||||
this.accounts = accounts;
|
||||
this.notifyNodeChanged(undefined);
|
||||
}
|
||||
});
|
||||
}
|
||||
public constructor(private readonly appContext: AppContext) {
|
||||
azdata.accounts.onDidChangeAccounts(async (e: azdata.DidChangeAccountsParams) => {
|
||||
// This event sends it per provider, we need to make sure we get all the azure related accounts
|
||||
let accounts = await azdata.accounts.getAllAccounts();
|
||||
accounts = accounts.filter(a => a.key.providerId.startsWith('azure'));
|
||||
// the onDidChangeAccounts event will trigger in many cases where the accounts didn't actually change
|
||||
// the notifyNodeChanged event triggers a refresh which triggers a getChildren which can trigger this callback
|
||||
// this below check short-circuits the infinite callback loop
|
||||
this.setSystemInitialized();
|
||||
if (!equals(accounts, this.accounts)) {
|
||||
this.accounts = accounts;
|
||||
this.notifyNodeChanged(undefined);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public async getChildren(element?: TreeNode): Promise<TreeNode[]> {
|
||||
@@ -78,7 +66,7 @@ export class AzureResourceTreeProvider implements TreeDataProvider<TreeNode>, IA
|
||||
|
||||
private async loadAccounts(): Promise<void> {
|
||||
try {
|
||||
this.accounts = await this.appContext.getService<IAzureResourceAccountService>(AzureResourceServiceNames.accountService).getAccounts();
|
||||
this.accounts = await azdata.accounts.getAllAccounts();
|
||||
// System has been initialized
|
||||
this.setSystemInitialized();
|
||||
this._onDidChangeTreeData.fire(undefined);
|
||||
@@ -93,7 +81,7 @@ export class AzureResourceTreeProvider implements TreeDataProvider<TreeNode>, IA
|
||||
this.loadingAccountsPromise = undefined;
|
||||
}
|
||||
|
||||
public get onDidChangeTreeData(): Event<TreeNode> {
|
||||
public get onDidChangeTreeData(): vscode.Event<TreeNode> {
|
||||
return this._onDidChangeTreeData.event;
|
||||
}
|
||||
|
||||
@@ -111,7 +99,7 @@ export class AzureResourceTreeProvider implements TreeDataProvider<TreeNode>, IA
|
||||
this._onDidChangeTreeData.fire(node);
|
||||
}
|
||||
|
||||
public getTreeItem(element: TreeNode): TreeItem | Thenable<TreeItem> {
|
||||
public getTreeItem(element: TreeNode): vscode.TreeItem | Thenable<vscode.TreeItem> {
|
||||
return element.getTreeItem();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,7 +151,7 @@ export async function getSubscriptions(appContext: AppContext, account?: azdata.
|
||||
}
|
||||
|
||||
const subscriptionService = appContext.getService<IAzureResourceSubscriptionService>(AzureResourceServiceNames.subscriptionService);
|
||||
const tokens = await appContext.apiWrapper.getSecurityToken(account, azdata.AzureResource.ResourceManagement);
|
||||
const tokens = await azdata.accounts.getSecurityToken(account, azdata.AzureResource.ResourceManagement);
|
||||
await Promise.all(account.properties.tenants.map(async (tenant: { id: string | number; }) => {
|
||||
try {
|
||||
const token = tokens[tenant.id].token;
|
||||
|
||||
Reference in New Issue
Block a user