Remove AzureCore ApiWrapper (#11335)

This commit is contained in:
Charles Gagnon
2020-07-13 18:11:54 -07:00
committed by GitHub
parent 9e6056968b
commit cbf3cd7445
30 changed files with 246 additions and 439 deletions

View File

@@ -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,

View File

@@ -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();
}
}