azdata.Account -> AzureAccount (#16842)

This commit is contained in:
Charles Gagnon
2021-08-20 10:28:33 -07:00
committed by GitHub
parent d1dc226ff6
commit 5b3fbaa5ff
24 changed files with 115 additions and 96 deletions

View File

@@ -69,7 +69,7 @@ export class AzureAccountProvider implements azdata.AccountProvider, vscode.Disp
} }
} }
private getAuthMethod(account?: azdata.Account): AzureAuth { private getAuthMethod(account?: AzureAccount): AzureAuth {
if (this.authMappings.size === 1) { if (this.authMappings.size === 1) {
return this.authMappings.values().next().value; return this.authMappings.values().next().value;
} }
@@ -82,12 +82,12 @@ export class AzureAccountProvider implements azdata.AccountProvider, vscode.Disp
} }
} }
initialize(storedAccounts: azdata.Account[]): Thenable<azdata.Account[]> { initialize(storedAccounts: AzureAccount[]): Thenable<AzureAccount[]> {
return this._initialize(storedAccounts); return this._initialize(storedAccounts);
} }
private async _initialize(storedAccounts: azdata.Account[]): Promise<azdata.Account[]> { private async _initialize(storedAccounts: AzureAccount[]): Promise<AzureAccount[]> {
const accounts: azdata.Account[] = []; const accounts: AzureAccount[] = [];
console.log(`Initializing stored accounts ${JSON.stringify(accounts)}`); console.log(`Initializing stored accounts ${JSON.stringify(accounts)}`);
for (let account of storedAccounts) { for (let account of storedAccounts) {
const azureAuth = this.getAuthMethod(account); const azureAuth = this.getAuthMethod(account);
@@ -103,21 +103,21 @@ export class AzureAccountProvider implements azdata.AccountProvider, vscode.Disp
} }
getSecurityToken(account: azdata.Account, resource: azdata.AzureResource): Thenable<MultiTenantTokenResponse | undefined> { getSecurityToken(account: AzureAccount, resource: azdata.AzureResource): Thenable<MultiTenantTokenResponse | undefined> {
return this._getSecurityToken(account, resource); return this._getSecurityToken(account, resource);
} }
getAccountSecurityToken(account: azdata.Account, tenantId: string, resource: azdata.AzureResource): Thenable<Token | undefined> { getAccountSecurityToken(account: AzureAccount, tenantId: string, resource: azdata.AzureResource): Thenable<Token | undefined> {
return this._getAccountSecurityToken(account, tenantId, resource); return this._getAccountSecurityToken(account, tenantId, resource);
} }
private async _getAccountSecurityToken(account: azdata.Account, tenantId: string, resource: azdata.AzureResource): Promise<Token | undefined> { private async _getAccountSecurityToken(account: AzureAccount, tenantId: string, resource: azdata.AzureResource): Promise<Token | undefined> {
await this.initCompletePromise; await this.initCompletePromise;
const azureAuth = this.getAuthMethod(undefined); const azureAuth = this.getAuthMethod(undefined);
return azureAuth?.getAccountSecurityToken(account, tenantId, resource); return azureAuth?.getAccountSecurityToken(account, tenantId, resource);
} }
private async _getSecurityToken(account: azdata.Account, resource: azdata.AzureResource): Promise<MultiTenantTokenResponse | undefined> { private async _getSecurityToken(account: AzureAccount, resource: azdata.AzureResource): Promise<MultiTenantTokenResponse | undefined> {
vscode.window.showInformationMessage(localize('azure.deprecatedGetSecurityToken', "A call was made to azdata.accounts.getSecurityToken, this method is deprecated and will be removed in future releases. Please use getAccountSecurityToken instead.")); vscode.window.showInformationMessage(localize('azure.deprecatedGetSecurityToken', "A call was made to azdata.accounts.getSecurityToken, this method is deprecated and will be removed in future releases. Please use getAccountSecurityToken instead."));
const azureAccount = account as AzureAccount; const azureAccount = account as AzureAccount;
const response: MultiTenantTokenResponse = {}; const response: MultiTenantTokenResponse = {};
@@ -128,11 +128,11 @@ export class AzureAccountProvider implements azdata.AccountProvider, vscode.Disp
return response; return response;
} }
prompt(): Thenable<azdata.Account | azdata.PromptFailedResult> { prompt(): Thenable<AzureAccount | azdata.PromptFailedResult> {
return this._prompt(); return this._prompt();
} }
private async _prompt(): Promise<azdata.Account | azdata.PromptFailedResult> { private async _prompt(): Promise<AzureAccount | azdata.PromptFailedResult> {
const noAuthSelected = localize('azure.NoAuthMethod.Selected', "No Azure auth method selected. You must select what method of authentication you want to use."); const noAuthSelected = localize('azure.NoAuthMethod.Selected', "No Azure auth method selected. You must select what method of authentication you want to use.");
const noAuthAvailable = localize('azure.NoAuthMethod.Available', "No Azure auth method available. You must enable the auth methods in ADS configuration."); const noAuthAvailable = localize('azure.NoAuthMethod.Available', "No Azure auth method available. You must enable the auth methods in ADS configuration.");
@@ -170,7 +170,7 @@ export class AzureAccountProvider implements azdata.AccountProvider, vscode.Disp
return pick.azureAuth.startLogin(); return pick.azureAuth.startLogin();
} }
refresh(account: azdata.Account): Thenable<azdata.Account | azdata.PromptFailedResult> { refresh(account: AzureAccount): Thenable<AzureAccount | azdata.PromptFailedResult> {
return this.prompt(); return this.prompt();
} }

View File

@@ -5,8 +5,9 @@
declare module 'azureResource' { declare module 'azureResource' {
import { TreeDataProvider } from 'vscode'; import { TreeDataProvider } from 'vscode';
import { DataProvider, Account, TreeItem } from 'azdata'; import { DataProvider, TreeItem } from 'azdata';
import { BlobItem } from '@azure/storage-blob'; import { BlobItem } from '@azure/storage-blob';
import { AzureAccount } from 'azurecore';
export namespace azureResource { export namespace azureResource {
@@ -38,7 +39,7 @@ declare module 'azureResource' {
} }
export interface IAzureResourceNode { export interface IAzureResourceNode {
readonly account: Account; readonly account: AzureAccount;
readonly subscription: AzureResourceSubscription; readonly subscription: AzureResourceSubscription;
readonly tenantId: string; readonly tenantId: string;
readonly treeItem: TreeItem; readonly treeItem: TreeItem;

View File

@@ -5,8 +5,6 @@
import * as msRest from '@azure/ms-rest-js'; import * as msRest from '@azure/ms-rest-js';
import { Account } from 'azdata';
import { azureResource } from 'azureResource'; import { azureResource } from 'azureResource';
import { AzureAccount, Tenant } from 'azurecore'; import { AzureAccount, Tenant } from 'azurecore';
@@ -22,8 +20,8 @@ export interface IAzureResourceSubscriptionService {
} }
export interface IAzureResourceSubscriptionFilterService { export interface IAzureResourceSubscriptionFilterService {
getSelectedSubscriptions(account: Account): Promise<azureResource.AzureResourceSubscription[]>; getSelectedSubscriptions(account: AzureAccount): Promise<azureResource.AzureResourceSubscription[]>;
saveSelectedSubscriptions(account: Account, selectedSubscriptions: azureResource.AzureResourceSubscription[]): Promise<void>; saveSelectedSubscriptions(account: AzureAccount, selectedSubscriptions: azureResource.AzureResourceSubscription[]): Promise<void>;
} }
export interface IAzureTerminalService { export interface IAzureTerminalService {
@@ -45,5 +43,5 @@ export interface IAzureResourceNodeWithProviderId {
} }
export interface IAzureResourceService<T extends azureResource.AzureResource> { export interface IAzureResourceService<T extends azureResource.AzureResource> {
getResources(subscriptions: azureResource.AzureResourceSubscription[], credential: msRest.ServiceClientCredentials, account: Account): Promise<T[]>; getResources(subscriptions: azureResource.AzureResourceSubscription[], credential: msRest.ServiceClientCredentials, account: AzureAccount): Promise<T[]>;
} }

View File

@@ -3,7 +3,7 @@
* Licensed under the Source EULA. See License.txt in the project root for license information. * Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import { ExtensionNodeType, TreeItem, Account } from 'azdata'; import { ExtensionNodeType, TreeItem } from 'azdata';
import { TreeItemCollapsibleState, ExtensionContext } from 'vscode'; import { TreeItemCollapsibleState, ExtensionContext } from 'vscode';
import * as nls from 'vscode-nls'; import * as nls from 'vscode-nls';
const localize = nls.loadMessageBundle(); const localize = nls.loadMessageBundle();
@@ -13,6 +13,7 @@ import { generateGuid } from '../../utils';
import { IAzureResourceService } from '../../interfaces'; import { IAzureResourceService } from '../../interfaces';
import { ResourceTreeDataProviderBase } from '../resourceTreeDataProviderBase'; import { ResourceTreeDataProviderBase } from '../resourceTreeDataProviderBase';
import { azureResource } from 'azureResource'; import { azureResource } from 'azureResource';
import { AzureAccount } from 'azurecore';
export class AzureMonitorTreeDataProvider extends ResourceTreeDataProviderBase<azureResource.AzureResourceDatabaseServer> { export class AzureMonitorTreeDataProvider extends ResourceTreeDataProviderBase<azureResource.AzureResourceDatabaseServer> {
private static readonly containerId = 'azure.resource.providers.AzureMonitorContainer'; private static readonly containerId = 'azure.resource.providers.AzureMonitorContainer';
@@ -26,7 +27,7 @@ export class AzureMonitorTreeDataProvider extends ResourceTreeDataProviderBase<a
} }
protected getTreeItemForResource(databaseServer: azureResource.AzureResourceDatabaseServer, account: Account): TreeItem { protected getTreeItemForResource(databaseServer: azureResource.AzureResourceDatabaseServer, account: AzureAccount): TreeItem {
return { return {
id: `LogAnalytics_${databaseServer.id ? databaseServer.id : databaseServer.name}`, id: `LogAnalytics_${databaseServer.id ? databaseServer.id : databaseServer.name}`,
label: this.browseConnectionMode ? `${databaseServer.name} (${AzureMonitorTreeDataProvider.containerLabel}, ${databaseServer.subscription.name})` : databaseServer.name, label: this.browseConnectionMode ? `${databaseServer.name} (${AzureMonitorTreeDataProvider.containerLabel}, ${databaseServer.subscription.name})` : databaseServer.name,

View File

@@ -9,13 +9,13 @@ import { IAzureResourceService } from '../../interfaces';
import { serversQuery, DbServerGraphData } from '../databaseServer/databaseServerService'; import { serversQuery, DbServerGraphData } from '../databaseServer/databaseServerService';
import { ResourceGraphClient } from '@azure/arm-resourcegraph'; import { ResourceGraphClient } from '@azure/arm-resourcegraph';
import { queryGraphResources, GraphData } from '../resourceTreeDataProviderBase'; import { queryGraphResources, GraphData } from '../resourceTreeDataProviderBase';
import { Account } from 'azdata'; import { AzureAccount } from 'azurecore';
interface DatabaseGraphData extends GraphData { interface DatabaseGraphData extends GraphData {
kind: string; kind: string;
} }
export class AzureResourceDatabaseService implements IAzureResourceService<azureResource.AzureResourceDatabase> { export class AzureResourceDatabaseService implements IAzureResourceService<azureResource.AzureResourceDatabase> {
public async getResources(subscriptions: azureResource.AzureResourceSubscription[], credential: ServiceClientCredentials, account: Account): Promise<azureResource.AzureResourceDatabase[]> { public async getResources(subscriptions: azureResource.AzureResourceSubscription[], credential: ServiceClientCredentials, account: AzureAccount): Promise<azureResource.AzureResourceDatabase[]> {
const databases: azureResource.AzureResourceDatabase[] = []; const databases: azureResource.AzureResourceDatabase[] = [];
const resourceClient = new ResourceGraphClient(credential, { baseUri: account.properties.providerSettings.settings.armResource.endpoint }); const resourceClient = new ResourceGraphClient(credential, { baseUri: account.properties.providerSettings.settings.armResource.endpoint });

View File

@@ -3,7 +3,7 @@
* Licensed under the Source EULA. See License.txt in the project root for license information. * Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import { TreeItem, ExtensionNodeType, Account } from 'azdata'; import { TreeItem, ExtensionNodeType } from 'azdata';
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import * as nls from 'vscode-nls'; import * as nls from 'vscode-nls';
const localize = nls.loadMessageBundle(); const localize = nls.loadMessageBundle();
@@ -13,6 +13,7 @@ import { AzureResourceItemType } from '../../../azureResource/constants';
import { generateGuid } from '../../utils'; import { generateGuid } from '../../utils';
import { IAzureResourceService } from '../../interfaces'; import { IAzureResourceService } from '../../interfaces';
import { ResourceTreeDataProviderBase } from '../resourceTreeDataProviderBase'; import { ResourceTreeDataProviderBase } from '../resourceTreeDataProviderBase';
import { AzureAccount } from 'azurecore';
export class AzureResourceDatabaseTreeDataProvider extends ResourceTreeDataProviderBase<azureResource.AzureResourceDatabase> { export class AzureResourceDatabaseTreeDataProvider extends ResourceTreeDataProviderBase<azureResource.AzureResourceDatabase> {
@@ -25,7 +26,7 @@ export class AzureResourceDatabaseTreeDataProvider extends ResourceTreeDataProvi
) { ) {
super(databaseService); super(databaseService);
} }
protected getTreeItemForResource(database: azureResource.AzureResourceDatabase, account: Account): TreeItem { protected getTreeItemForResource(database: azureResource.AzureResourceDatabase, account: AzureAccount): TreeItem {
return { return {
id: `databaseServer_${database.serverFullName}.database_${database.name}`, id: `databaseServer_${database.serverFullName}.database_${database.name}`,
label: this.browseConnectionMode ? `${database.serverName}/${database.name} (${AzureResourceDatabaseTreeDataProvider.containerLabel}, ${database.subscription.name})` : `${database.name} (${database.serverName})`, label: this.browseConnectionMode ? `${database.serverName}/${database.name} (${AzureResourceDatabaseTreeDataProvider.containerLabel}, ${database.subscription.name})` : `${database.name} (${database.serverName})`,

View File

@@ -3,7 +3,7 @@
* Licensed under the Source EULA. See License.txt in the project root for license information. * Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import { ExtensionNodeType, TreeItem, Account } from 'azdata'; import { ExtensionNodeType, TreeItem } from 'azdata';
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import * as nls from 'vscode-nls'; import * as nls from 'vscode-nls';
const localize = nls.loadMessageBundle(); const localize = nls.loadMessageBundle();
@@ -13,6 +13,7 @@ import { generateGuid } from '../../utils';
import { IAzureResourceService } from '../../interfaces'; import { IAzureResourceService } from '../../interfaces';
import { ResourceTreeDataProviderBase } from '../resourceTreeDataProviderBase'; import { ResourceTreeDataProviderBase } from '../resourceTreeDataProviderBase';
import { azureResource } from 'azureResource'; import { azureResource } from 'azureResource';
import { AzureAccount } from 'azurecore';
export class AzureResourceDatabaseServerTreeDataProvider extends ResourceTreeDataProviderBase<azureResource.AzureResourceDatabaseServer> { export class AzureResourceDatabaseServerTreeDataProvider extends ResourceTreeDataProviderBase<azureResource.AzureResourceDatabaseServer> {
private static readonly containerId = 'azure.resource.providers.databaseServer.treeDataProvider.databaseServerContainer'; private static readonly containerId = 'azure.resource.providers.databaseServer.treeDataProvider.databaseServerContainer';
@@ -26,7 +27,7 @@ export class AzureResourceDatabaseServerTreeDataProvider extends ResourceTreeDat
} }
protected getTreeItemForResource(databaseServer: azureResource.AzureResourceDatabaseServer, account: Account): TreeItem { protected getTreeItemForResource(databaseServer: azureResource.AzureResourceDatabaseServer, account: AzureAccount): TreeItem {
return { return {
id: `databaseServer_${databaseServer.id ? databaseServer.id : databaseServer.name}`, id: `databaseServer_${databaseServer.id ? databaseServer.id : databaseServer.name}`,
label: this.browseConnectionMode ? `${databaseServer.name} (${AzureResourceDatabaseServerTreeDataProvider.containerLabel}, ${databaseServer.subscription.name})` : databaseServer.name, label: this.browseConnectionMode ? `${databaseServer.name} (${AzureResourceDatabaseServerTreeDataProvider.containerLabel}, ${databaseServer.subscription.name})` : databaseServer.name,

View File

@@ -3,7 +3,7 @@
* Licensed under the Source EULA. See License.txt in the project root for license information. * Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import { ExtensionNodeType, TreeItem, Account } from 'azdata'; import { ExtensionNodeType, TreeItem } from 'azdata';
import { TreeItemCollapsibleState, ExtensionContext } from 'vscode'; import { TreeItemCollapsibleState, ExtensionContext } from 'vscode';
import * as nls from 'vscode-nls'; import * as nls from 'vscode-nls';
const localize = nls.loadMessageBundle(); const localize = nls.loadMessageBundle();
@@ -13,6 +13,7 @@ import { generateGuid } from '../../utils';
import { IAzureResourceService } from '../../interfaces'; import { IAzureResourceService } from '../../interfaces';
import { ResourceTreeDataProviderBase } from '../resourceTreeDataProviderBase'; import { ResourceTreeDataProviderBase } from '../resourceTreeDataProviderBase';
import { azureResource } from 'azureResource'; import { azureResource } from 'azureResource';
import { AzureAccount } from 'azurecore';
export class KustoTreeDataProvider extends ResourceTreeDataProviderBase<azureResource.AzureResourceDatabaseServer> { export class KustoTreeDataProvider extends ResourceTreeDataProviderBase<azureResource.AzureResourceDatabaseServer> {
private static readonly containerId = 'azure.resource.providers.KustoContainer'; private static readonly containerId = 'azure.resource.providers.KustoContainer';
@@ -26,7 +27,7 @@ export class KustoTreeDataProvider extends ResourceTreeDataProviderBase<azureRes
} }
protected getTreeItemForResource(databaseServer: azureResource.AzureResourceDatabaseServer, account: Account): TreeItem { protected getTreeItemForResource(databaseServer: azureResource.AzureResourceDatabaseServer, account: AzureAccount): TreeItem {
return { return {
id: `Kusto_${databaseServer.id ? databaseServer.id : databaseServer.name}`, id: `Kusto_${databaseServer.id ? databaseServer.id : databaseServer.name}`,
label: this.browseConnectionMode ? `${databaseServer.name} (${KustoTreeDataProvider.containerLabel}, ${databaseServer.subscription.name})` : databaseServer.name, label: this.browseConnectionMode ? `${databaseServer.name} (${KustoTreeDataProvider.containerLabel}, ${databaseServer.subscription.name})` : databaseServer.name,

View File

@@ -3,7 +3,7 @@
* Licensed under the Source EULA. See License.txt in the project root for license information. * Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import { ExtensionNodeType, TreeItem, Account } from 'azdata'; import { ExtensionNodeType, TreeItem } from 'azdata';
import { TreeItemCollapsibleState, ExtensionContext } from 'vscode'; import { TreeItemCollapsibleState, ExtensionContext } from 'vscode';
import * as nls from 'vscode-nls'; import * as nls from 'vscode-nls';
const localize = nls.loadMessageBundle(); const localize = nls.loadMessageBundle();
@@ -13,6 +13,7 @@ import { generateGuid } from '../../utils';
import { IAzureResourceService } from '../../interfaces'; import { IAzureResourceService } from '../../interfaces';
import { ResourceTreeDataProviderBase } from '../resourceTreeDataProviderBase'; import { ResourceTreeDataProviderBase } from '../resourceTreeDataProviderBase';
import { azureResource } from 'azureResource'; import { azureResource } from 'azureResource';
import { AzureAccount } from 'azurecore';
export class PostgresServerArcTreeDataProvider extends ResourceTreeDataProviderBase<azureResource.AzureResourceDatabaseServer> { export class PostgresServerArcTreeDataProvider extends ResourceTreeDataProviderBase<azureResource.AzureResourceDatabaseServer> {
private static readonly containerId = 'azure.resource.providers.postgresArcServer.treeDataProvider.postgresServerContainer'; private static readonly containerId = 'azure.resource.providers.postgresArcServer.treeDataProvider.postgresServerContainer';
@@ -26,7 +27,7 @@ export class PostgresServerArcTreeDataProvider extends ResourceTreeDataProviderB
} }
protected getTreeItemForResource(databaseServer: azureResource.AzureResourceDatabaseServer, account: Account): TreeItem { protected getTreeItemForResource(databaseServer: azureResource.AzureResourceDatabaseServer, account: AzureAccount): TreeItem {
return { return {
id: `databaseServer_${databaseServer.id ? databaseServer.id : databaseServer.name}`, id: `databaseServer_${databaseServer.id ? databaseServer.id : databaseServer.name}`,
label: this.browseConnectionMode ? `${databaseServer.name} (${PostgresServerArcTreeDataProvider.containerLabel}, ${databaseServer.subscription.name})` : databaseServer.name, label: this.browseConnectionMode ? `${databaseServer.name} (${PostgresServerArcTreeDataProvider.containerLabel}, ${databaseServer.subscription.name})` : databaseServer.name,

View File

@@ -3,7 +3,7 @@
* Licensed under the Source EULA. See License.txt in the project root for license information. * Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import { ExtensionNodeType, TreeItem, Account } from 'azdata'; import { ExtensionNodeType, TreeItem } from 'azdata';
import { TreeItemCollapsibleState, ExtensionContext } from 'vscode'; import { TreeItemCollapsibleState, ExtensionContext } from 'vscode';
import * as nls from 'vscode-nls'; import * as nls from 'vscode-nls';
const localize = nls.loadMessageBundle(); const localize = nls.loadMessageBundle();
@@ -13,6 +13,7 @@ import { generateGuid } from '../../utils';
import { IAzureResourceService } from '../../interfaces'; import { IAzureResourceService } from '../../interfaces';
import { ResourceTreeDataProviderBase } from '../resourceTreeDataProviderBase'; import { ResourceTreeDataProviderBase } from '../resourceTreeDataProviderBase';
import { azureResource } from 'azureResource'; import { azureResource } from 'azureResource';
import { AzureAccount } from 'azurecore';
export class PostgresServerTreeDataProvider extends ResourceTreeDataProviderBase<azureResource.AzureResourceDatabaseServer> { export class PostgresServerTreeDataProvider extends ResourceTreeDataProviderBase<azureResource.AzureResourceDatabaseServer> {
private static readonly containerId = 'azure.resource.providers.databaseServer.treeDataProvider.postgresServerContainer'; private static readonly containerId = 'azure.resource.providers.databaseServer.treeDataProvider.postgresServerContainer';
@@ -26,7 +27,7 @@ export class PostgresServerTreeDataProvider extends ResourceTreeDataProviderBase
} }
protected getTreeItemForResource(databaseServer: azureResource.AzureResourceDatabaseServer, account: Account): TreeItem { protected getTreeItemForResource(databaseServer: azureResource.AzureResourceDatabaseServer, account: AzureAccount): TreeItem {
return { return {
id: `databaseServer_${databaseServer.id ? databaseServer.id : databaseServer.name}`, id: `databaseServer_${databaseServer.id ? databaseServer.id : databaseServer.name}`,
label: this.browseConnectionMode ? `${databaseServer.name} (${PostgresServerTreeDataProvider.containerLabel}, ${databaseServer.subscription.name})` : databaseServer.name, label: this.browseConnectionMode ? `${databaseServer.name} (${PostgresServerTreeDataProvider.containerLabel}, ${databaseServer.subscription.name})` : databaseServer.name,

View File

@@ -10,6 +10,7 @@ import { azureResource } from 'azureResource';
import { IAzureResourceService } from '../interfaces'; import { IAzureResourceService } from '../interfaces';
import { AzureResourceErrorMessageUtil } from '../utils'; import { AzureResourceErrorMessageUtil } from '../utils';
import { ResourceGraphClient } from '@azure/arm-resourcegraph'; import { ResourceGraphClient } from '@azure/arm-resourcegraph';
import { AzureAccount } from 'azurecore';
export abstract class ResourceTreeDataProviderBase<T extends azureResource.AzureResource> implements azureResource.IAzureResourceTreeDataProvider { export abstract class ResourceTreeDataProviderBase<T extends azureResource.AzureResource> implements azureResource.IAzureResourceTreeDataProvider {
public browseConnectionMode: boolean = false; public browseConnectionMode: boolean = false;
@@ -49,7 +50,7 @@ export abstract class ResourceTreeDataProviderBase<T extends azureResource.Azure
return resources; return resources;
} }
protected abstract getTreeItemForResource(resource: T, account: azdata.Account): azdata.TreeItem; protected abstract getTreeItemForResource(resource: T, account: AzureAccount): azdata.TreeItem;
protected abstract createContainerNode(): azureResource.IAzureResourceNode; protected abstract createContainerNode(): azureResource.IAzureResourceNode;
} }
@@ -121,7 +122,7 @@ export abstract class ResourceServiceBase<T extends GraphData, U extends azureRe
*/ */
protected abstract get query(): string; protected abstract get query(): string;
public async getResources(subscriptions: azureResource.AzureResourceSubscription[], credential: msRest.ServiceClientCredentials, account: azdata.Account): Promise<U[]> { public async getResources(subscriptions: azureResource.AzureResourceSubscription[], credential: msRest.ServiceClientCredentials, account: AzureAccount): Promise<U[]> {
const convertedResources: U[] = []; const convertedResources: U[] = [];
const resourceClient = new ResourceGraphClient(credential, { baseUri: account.properties.providerSettings.settings.armResource.endpoint }); const resourceClient = new ResourceGraphClient(credential, { baseUri: account.properties.providerSettings.settings.armResource.endpoint });
const graphResources = await queryGraphResources<T>(resourceClient, subscriptions, this.query); const graphResources = await queryGraphResources<T>(resourceClient, subscriptions, this.query);

View File

@@ -3,7 +3,7 @@
* Licensed under the Source EULA. See License.txt in the project root for license information. * Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import { ExtensionNodeType, TreeItem, Account } from 'azdata'; import { ExtensionNodeType, TreeItem } from 'azdata';
import { TreeItemCollapsibleState, ExtensionContext } from 'vscode'; import { TreeItemCollapsibleState, ExtensionContext } from 'vscode';
import * as nls from 'vscode-nls'; import * as nls from 'vscode-nls';
const localize = nls.loadMessageBundle(); const localize = nls.loadMessageBundle();
@@ -13,6 +13,7 @@ import { generateGuid } from '../../utils';
import { IAzureResourceService } from '../../interfaces'; import { IAzureResourceService } from '../../interfaces';
import { ResourceTreeDataProviderBase } from '../resourceTreeDataProviderBase'; import { ResourceTreeDataProviderBase } from '../resourceTreeDataProviderBase';
import { azureResource } from 'azureResource'; import { azureResource } from 'azureResource';
import { AzureAccount } from 'azurecore';
export class SqlInstanceTreeDataProvider extends ResourceTreeDataProviderBase<azureResource.AzureResourceDatabaseServer> { export class SqlInstanceTreeDataProvider extends ResourceTreeDataProviderBase<azureResource.AzureResourceDatabaseServer> {
private static readonly containerId = 'azure.resource.providers.sqlInstanceContainer'; private static readonly containerId = 'azure.resource.providers.sqlInstanceContainer';
@@ -26,7 +27,7 @@ export class SqlInstanceTreeDataProvider extends ResourceTreeDataProviderBase<az
} }
protected getTreeItemForResource(databaseServer: azureResource.AzureResourceDatabaseServer, account: Account): TreeItem { protected getTreeItemForResource(databaseServer: azureResource.AzureResourceDatabaseServer, account: AzureAccount): TreeItem {
return { return {
id: `sqlInstance_${databaseServer.id ? databaseServer.id : databaseServer.name}`, id: `sqlInstance_${databaseServer.id ? databaseServer.id : databaseServer.name}`,
label: this.browseConnectionMode ? `${databaseServer.name} (${SqlInstanceTreeDataProvider.containerLabel}, ${databaseServer.subscription.name})` : databaseServer.name, label: this.browseConnectionMode ? `${databaseServer.name} (${SqlInstanceTreeDataProvider.containerLabel}, ${databaseServer.subscription.name})` : databaseServer.name,

View File

@@ -3,7 +3,7 @@
* Licensed under the Source EULA. See License.txt in the project root for license information. * Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import { ExtensionNodeType, TreeItem, Account } from 'azdata'; import { ExtensionNodeType, TreeItem } from 'azdata';
import { TreeItemCollapsibleState, ExtensionContext } from 'vscode'; import { TreeItemCollapsibleState, ExtensionContext } from 'vscode';
import * as nls from 'vscode-nls'; import * as nls from 'vscode-nls';
const localize = nls.loadMessageBundle(); const localize = nls.loadMessageBundle();
@@ -13,6 +13,7 @@ import { generateGuid } from '../../utils';
import { IAzureResourceService } from '../../interfaces'; import { IAzureResourceService } from '../../interfaces';
import { ResourceTreeDataProviderBase } from '../resourceTreeDataProviderBase'; import { ResourceTreeDataProviderBase } from '../resourceTreeDataProviderBase';
import { azureResource } from 'azureResource'; import { azureResource } from 'azureResource';
import { AzureAccount } from 'azurecore';
export class SqlInstanceArcTreeDataProvider extends ResourceTreeDataProviderBase<azureResource.AzureResourceDatabaseServer> { export class SqlInstanceArcTreeDataProvider extends ResourceTreeDataProviderBase<azureResource.AzureResourceDatabaseServer> {
private static readonly containerId = 'azure.resource.providers.sqlInstanceArcContainer'; private static readonly containerId = 'azure.resource.providers.sqlInstanceArcContainer';
@@ -26,7 +27,7 @@ export class SqlInstanceArcTreeDataProvider extends ResourceTreeDataProviderBase
} }
protected getTreeItemForResource(databaseServer: azureResource.AzureResourceDatabaseServer, account: Account): TreeItem { protected getTreeItemForResource(databaseServer: azureResource.AzureResourceDatabaseServer, account: AzureAccount): TreeItem {
return { return {
id: `sqlInstance_${databaseServer.id ? databaseServer.id : databaseServer.name}`, id: `sqlInstance_${databaseServer.id ? databaseServer.id : databaseServer.name}`,
label: this.browseConnectionMode ? `${databaseServer.name} (${SqlInstanceArcTreeDataProvider.containerLabel}, ${databaseServer.subscription.name})` : databaseServer.name, label: this.browseConnectionMode ? `${databaseServer.name} (${SqlInstanceArcTreeDataProvider.containerLabel}, ${databaseServer.subscription.name})` : databaseServer.name,

View File

@@ -4,10 +4,10 @@
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import { extensions, TreeItem } from 'vscode'; import { extensions, TreeItem } from 'vscode';
import { Account } from 'azdata';
import { azureResource } from 'azureResource'; import { azureResource } from 'azureResource';
import { IAzureResourceNodeWithProviderId } from './interfaces'; import { IAzureResourceNodeWithProviderId } from './interfaces';
import { AzureAccount } from 'azurecore';
export class AzureResourceService { export class AzureResourceService {
private _areResourceProvidersLoaded: boolean = false; private _areResourceProvidersLoaded: boolean = false;
@@ -33,7 +33,7 @@ export class AzureResourceService {
this._areResourceProvidersLoaded = false; this._areResourceProvidersLoaded = false;
} }
public async getRootChildren(resourceProviderId: string, account: Account, subscription: azureResource.AzureResourceSubscription, tenatId: string): Promise<IAzureResourceNodeWithProviderId[]> { public async getRootChildren(resourceProviderId: string, account: AzureAccount, subscription: azureResource.AzureResourceSubscription, tenatId: string): Promise<IAzureResourceNodeWithProviderId[]> {
await this.ensureResourceProvidersRegistered(); await this.ensureResourceProvidersRegistered();
if (!(resourceProviderId in this._resourceProviders)) { if (!(resourceProviderId in this._resourceProviders)) {

View File

@@ -3,8 +3,7 @@
* Licensed under the Source EULA. See License.txt in the project root for license information. * Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import { Account } from 'azdata'; import { AzureAccount } from 'azurecore';
import { azureResource } from 'azureResource'; import { azureResource } from 'azureResource';
import { IAzureResourceSubscriptionFilterService, IAzureResourceCacheService } from '../interfaces'; import { IAzureResourceSubscriptionFilterService, IAzureResourceCacheService } from '../interfaces';
@@ -21,7 +20,7 @@ export class AzureResourceSubscriptionFilterService implements IAzureResourceSub
this._cacheKey = this._cacheService.generateKey('selectedSubscriptions'); this._cacheKey = this._cacheService.generateKey('selectedSubscriptions');
} }
public async getSelectedSubscriptions(account: Account): Promise<azureResource.AzureResourceSubscription[]> { public async getSelectedSubscriptions(account: AzureAccount): Promise<azureResource.AzureResourceSubscription[]> {
let selectedSubscriptions: azureResource.AzureResourceSubscription[] = []; let selectedSubscriptions: azureResource.AzureResourceSubscription[] = [];
const cache = this._cacheService.get<AzureResourceSelectedSubscriptionsCache>(this._cacheKey); const cache = this._cacheService.get<AzureResourceSelectedSubscriptionsCache>(this._cacheKey);
@@ -32,7 +31,7 @@ export class AzureResourceSubscriptionFilterService implements IAzureResourceSub
return selectedSubscriptions; return selectedSubscriptions;
} }
public async saveSelectedSubscriptions(account: Account, selectedSubscriptions: azureResource.AzureResourceSubscription[]): Promise<void> { public async saveSelectedSubscriptions(account: AzureAccount, selectedSubscriptions: azureResource.AzureResourceSubscription[]): Promise<void> {
let selectedSubscriptionsCache: { [accountId: string]: azureResource.AzureResourceSubscription[] } = {}; let selectedSubscriptionsCache: { [accountId: string]: azureResource.AzureResourceSubscription[] } = {};
const cache = this._cacheService.get<AzureResourceSelectedSubscriptionsCache>(this._cacheKey); const cache = this._cacheService.get<AzureResourceSelectedSubscriptionsCache>(this._cacheKey);

View File

@@ -17,11 +17,12 @@ import { AzureResourceErrorMessageUtil, equals } from '../utils';
import { IAzureResourceTreeChangeHandler } from './treeChangeHandler'; import { IAzureResourceTreeChangeHandler } from './treeChangeHandler';
import { FlatAccountTreeNode } from './flatAccountTreeNode'; import { FlatAccountTreeNode } from './flatAccountTreeNode';
import { Logger } from '../../utils/Logger'; import { Logger } from '../../utils/Logger';
import { AzureAccount } from 'azurecore';
export class ConnectionDialogTreeProvider implements vscode.TreeDataProvider<TreeNode>, IAzureResourceTreeChangeHandler { export class ConnectionDialogTreeProvider implements vscode.TreeDataProvider<TreeNode>, IAzureResourceTreeChangeHandler {
public isSystemInitialized: boolean = false; public isSystemInitialized: boolean = false;
private accounts: azdata.Account[]; private accounts: AzureAccount[];
private _onDidChangeTreeData = new vscode.EventEmitter<TreeNode>(); private _onDidChangeTreeData = new vscode.EventEmitter<TreeNode>();
private loadingAccountsPromise: Promise<void>; private loadingAccountsPromise: Promise<void>;

View File

@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import { TreeItem, TreeItemCollapsibleState } from 'vscode'; import { TreeItem, TreeItemCollapsibleState } from 'vscode';
import { Account, NodeInfo } from 'azdata'; import { NodeInfo } from 'azdata';
import { AppContext } from '../../appContext'; import { AppContext } from '../../appContext';
import * as nls from 'vscode-nls'; import * as nls from 'vscode-nls';
const localize = nls.loadMessageBundle(); const localize = nls.loadMessageBundle();
@@ -19,10 +19,11 @@ import { AzureResourceMessageTreeNode } from '../messageTreeNode';
import { AzureResourceErrorMessageUtil } from '../utils'; import { AzureResourceErrorMessageUtil } from '../utils';
import { AzureResourceService } from '../resourceService'; import { AzureResourceService } from '../resourceService';
import { AzureResourceResourceTreeNode } from '../resourceTreeNode'; import { AzureResourceResourceTreeNode } from '../resourceTreeNode';
import { AzureAccount } from 'azurecore';
export class AzureResourceSubscriptionTreeNode extends AzureResourceContainerTreeNodeBase { export class AzureResourceSubscriptionTreeNode extends AzureResourceContainerTreeNodeBase {
public constructor( public constructor(
public readonly account: Account, public readonly account: AzureAccount,
public readonly subscription: azureResource.AzureResourceSubscription, public readonly subscription: azureResource.AzureResourceSubscription,
public readonly tenatId: string, public readonly tenatId: string,
appContext: AppContext, appContext: AppContext,

View File

@@ -16,12 +16,13 @@ import { AzureResourceMessageTreeNode } from '../messageTreeNode';
import { AzureResourceContainerTreeNodeBase } from './baseTreeNodes'; import { AzureResourceContainerTreeNodeBase } from './baseTreeNodes';
import { AzureResourceErrorMessageUtil, equals } from '../utils'; import { AzureResourceErrorMessageUtil, equals } from '../utils';
import { IAzureResourceTreeChangeHandler } from './treeChangeHandler'; import { IAzureResourceTreeChangeHandler } from './treeChangeHandler';
import { AzureAccount } from 'azurecore';
export class AzureResourceTreeProvider implements vscode.TreeDataProvider<TreeNode>, IAzureResourceTreeChangeHandler { export class AzureResourceTreeProvider implements vscode.TreeDataProvider<TreeNode>, IAzureResourceTreeChangeHandler {
public isSystemInitialized: boolean = false; public isSystemInitialized: boolean = false;
private accounts: azdata.Account[]; private accounts: AzureAccount[];
private _onDidChangeTreeData = new vscode.EventEmitter<TreeNode>(); private _onDidChangeTreeData = new vscode.EventEmitter<TreeNode>();
private loadingAccountsPromise: Promise<void>; private loadingAccountsPromise: Promise<void>;

View File

@@ -107,7 +107,7 @@ export function equals(one: any, other: any): boolean {
return true; return true;
} }
export async function getResourceGroups(appContext: AppContext, account?: azdata.Account, subscription?: azureResource.AzureResourceSubscription, ignoreErrors: boolean = false): Promise<GetResourceGroupsResult> { export async function getResourceGroups(appContext: AppContext, account?: AzureAccount, subscription?: azureResource.AzureResourceSubscription, ignoreErrors: boolean = false): Promise<GetResourceGroupsResult> {
const result: GetResourceGroupsResult = { resourceGroups: [], errors: [] }; const result: GetResourceGroupsResult = { resourceGroups: [], errors: [] };
if (!account?.properties?.tenants || !Array.isArray(account.properties.tenants) || !subscription) { if (!account?.properties?.tenants || !Array.isArray(account.properties.tenants) || !subscription) {
const error = new Error(invalidAzureAccount); const error = new Error(invalidAzureAccount);
@@ -143,7 +143,7 @@ export async function getResourceGroups(appContext: AppContext, account?: azdata
return result; return result;
} }
export async function getLocations(appContext: AppContext, account?: azdata.Account, subscription?: azureResource.AzureResourceSubscription, ignoreErrors: boolean = false): Promise<GetLocationsResult> { export async function getLocations(appContext: AppContext, account?: AzureAccount, subscription?: azureResource.AzureResourceSubscription, ignoreErrors: boolean = false): Promise<GetLocationsResult> {
const result: GetLocationsResult = { locations: [], errors: [] }; const result: GetLocationsResult = { locations: [], errors: [] };
if (!account?.properties?.tenants || !Array.isArray(account.properties.tenants) || !subscription) { if (!account?.properties?.tenants || !Array.isArray(account.properties.tenants) || !subscription) {
const error = new Error(invalidAzureAccount); const error = new Error(invalidAzureAccount);
@@ -178,7 +178,7 @@ export async function getLocations(appContext: AppContext, account?: azdata.Acco
} }
export async function runResourceQuery<T extends azureResource.AzureGraphResource>( export async function runResourceQuery<T extends azureResource.AzureGraphResource>(
account: azdata.Account, account: AzureAccount,
subscriptions: azureResource.AzureResourceSubscription[], subscriptions: azureResource.AzureResourceSubscription[],
ignoreErrors: boolean = false, ignoreErrors: boolean = false,
query: string): Promise<ResourceQueryResult<T>> { query: string): Promise<ResourceQueryResult<T>> {
@@ -292,7 +292,7 @@ export async function getSubscriptions(appContext: AppContext, account?: AzureAc
return result; return result;
} }
export async function getSelectedSubscriptions(appContext: AppContext, account?: azdata.Account, ignoreErrors: boolean = false): Promise<GetSubscriptionsResult> { export async function getSelectedSubscriptions(appContext: AppContext, account?: AzureAccount, ignoreErrors: boolean = false): Promise<GetSubscriptionsResult> {
const result: GetSubscriptionsResult = { subscriptions: [], errors: [] }; const result: GetSubscriptionsResult = { subscriptions: [], errors: [] };
if (!account?.properties?.tenants || !Array.isArray(account.properties.tenants)) { if (!account?.properties?.tenants || !Array.isArray(account.properties.tenants)) {
const error = new Error(invalidAzureAccount); const error = new Error(invalidAzureAccount);
@@ -331,7 +331,7 @@ export async function getSelectedSubscriptions(appContext: AppContext, account?:
* @param host Use this to override the host. The default host is https://management.azure.com * @param host Use this to override the host. The default host is https://management.azure.com
* @param requestHeaders Provide additional request headers * @param requestHeaders Provide additional request headers
*/ */
export async function makeHttpRequest(account: azdata.Account, subscription: azureResource.AzureResourceSubscription, path: string, requestType: HttpRequestMethod, requestBody?: any, ignoreErrors: boolean = false, host: string = 'https://management.azure.com', requestHeaders: { [key: string]: string } = {}): Promise<AzureRestResponse> { export async function makeHttpRequest(account: AzureAccount, subscription: azureResource.AzureResourceSubscription, path: string, requestType: HttpRequestMethod, requestBody?: any, ignoreErrors: boolean = false, host: string = 'https://management.azure.com', requestHeaders: { [key: string]: string } = {}): Promise<AzureRestResponse> {
const result: AzureRestResponse = { response: {}, errors: [] }; const result: AzureRestResponse = { response: {}, errors: [] };
if (!account?.properties?.tenants || !Array.isArray(account.properties.tenants)) { if (!account?.properties?.tenants || !Array.isArray(account.properties.tenants)) {
@@ -430,7 +430,7 @@ export async function makeHttpRequest(account: azdata.Account, subscription: azu
return result; return result;
} }
export async function getManagedDatabases(account: azdata.Account, subscription: azureResource.AzureResourceSubscription, managedInstance: azureResource.AzureSqlManagedInstance, ignoreErrors: boolean): Promise<GetManagedDatabasesResult> { export async function getManagedDatabases(account: AzureAccount, subscription: azureResource.AzureResourceSubscription, managedInstance: azureResource.AzureSqlManagedInstance, ignoreErrors: boolean): Promise<GetManagedDatabasesResult> {
const path = `/subscriptions/${subscription.id}/resourceGroups/${managedInstance.resourceGroup}/providers/Microsoft.Sql/managedInstances/${managedInstance.name}/databases?api-version=2020-02-02-preview`; const path = `/subscriptions/${subscription.id}/resourceGroups/${managedInstance.resourceGroup}/providers/Microsoft.Sql/managedInstances/${managedInstance.name}/databases?api-version=2020-02-02-preview`;
const response = await makeHttpRequest(account, subscription, path, HttpRequestMethod.GET, undefined, ignoreErrors); const response = await makeHttpRequest(account, subscription, path, HttpRequestMethod.GET, undefined, ignoreErrors);
return { return {
@@ -439,7 +439,7 @@ export async function getManagedDatabases(account: azdata.Account, subscription:
}; };
} }
export async function getBlobContainers(account: azdata.Account, subscription: azureResource.AzureResourceSubscription, storageAccount: azureResource.AzureGraphResource, ignoreErrors: boolean): Promise<GetBlobContainersResult> { export async function getBlobContainers(account: AzureAccount, subscription: azureResource.AzureResourceSubscription, storageAccount: azureResource.AzureGraphResource, ignoreErrors: boolean): Promise<GetBlobContainersResult> {
const path = `/subscriptions/${subscription.id}/resourceGroups/${storageAccount.resourceGroup}/providers/Microsoft.Storage/storageAccounts/${storageAccount.name}/blobServices/default/containers?api-version=2019-06-01`; const path = `/subscriptions/${subscription.id}/resourceGroups/${storageAccount.resourceGroup}/providers/Microsoft.Storage/storageAccounts/${storageAccount.name}/blobServices/default/containers?api-version=2019-06-01`;
const response = await makeHttpRequest(account, subscription, path, HttpRequestMethod.GET, undefined, ignoreErrors); const response = await makeHttpRequest(account, subscription, path, HttpRequestMethod.GET, undefined, ignoreErrors);
return { return {
@@ -448,7 +448,7 @@ export async function getBlobContainers(account: azdata.Account, subscription: a
}; };
} }
export async function getFileShares(account: azdata.Account, subscription: azureResource.AzureResourceSubscription, storageAccount: azureResource.AzureGraphResource, ignoreErrors: boolean): Promise<GetFileSharesResult> { export async function getFileShares(account: AzureAccount, subscription: azureResource.AzureResourceSubscription, storageAccount: azureResource.AzureGraphResource, ignoreErrors: boolean): Promise<GetFileSharesResult> {
const path = `/subscriptions/${subscription.id}/resourceGroups/${storageAccount.resourceGroup}/providers/Microsoft.Storage/storageAccounts/${storageAccount.name}/fileServices/default/shares?api-version=2019-06-01`; const path = `/subscriptions/${subscription.id}/resourceGroups/${storageAccount.resourceGroup}/providers/Microsoft.Storage/storageAccounts/${storageAccount.name}/fileServices/default/shares?api-version=2019-06-01`;
const response = await makeHttpRequest(account, subscription, path, HttpRequestMethod.GET, undefined, ignoreErrors); const response = await makeHttpRequest(account, subscription, path, HttpRequestMethod.GET, undefined, ignoreErrors);
return { return {
@@ -457,7 +457,7 @@ export async function getFileShares(account: azdata.Account, subscription: azure
}; };
} }
export async function createResourceGroup(account: azdata.Account, subscription: azureResource.AzureResourceSubscription, resourceGroupName: string, location: string, ignoreErrors: boolean): Promise<CreateResourceGroupResult> { export async function createResourceGroup(account: AzureAccount, subscription: azureResource.AzureResourceSubscription, resourceGroupName: string, location: string, ignoreErrors: boolean): Promise<CreateResourceGroupResult> {
const path = `/subscriptions/${subscription.id}/resourcegroups/${resourceGroupName}?api-version=2021-04-01`; const path = `/subscriptions/${subscription.id}/resourcegroups/${resourceGroupName}?api-version=2021-04-01`;
const requestBody = { const requestBody = {
location: location location: location
@@ -469,7 +469,7 @@ export async function createResourceGroup(account: azdata.Account, subscription:
}; };
} }
export async function getStorageAccountAccessKey(account: azdata.Account, subscription: azureResource.AzureResourceSubscription, storageAccount: azureResource.AzureGraphResource, ignoreErrors: boolean): Promise<GetStorageAccountAccessKeyResult> { export async function getStorageAccountAccessKey(account: AzureAccount, subscription: azureResource.AzureResourceSubscription, storageAccount: azureResource.AzureGraphResource, ignoreErrors: boolean): Promise<GetStorageAccountAccessKeyResult> {
const path = `/subscriptions/${subscription.id}/resourceGroups/${storageAccount.resourceGroup}/providers/Microsoft.Storage/storageAccounts/${storageAccount.name}/listKeys?api-version=2019-06-01`; const path = `/subscriptions/${subscription.id}/resourceGroups/${storageAccount.resourceGroup}/providers/Microsoft.Storage/storageAccounts/${storageAccount.name}/listKeys?api-version=2019-06-01`;
const response = await makeHttpRequest(account, subscription, path, HttpRequestMethod.POST, undefined, ignoreErrors); const response = await makeHttpRequest(account, subscription, path, HttpRequestMethod.POST, undefined, ignoreErrors);
return { return {
@@ -479,7 +479,7 @@ export async function getStorageAccountAccessKey(account: azdata.Account, subscr
}; };
} }
export async function getBlobs(account: azdata.Account, subscription: azureResource.AzureResourceSubscription, storageAccount: azureResource.AzureGraphResource, containerName: string, ignoreErrors: boolean): Promise<GetBlobsResult> { export async function getBlobs(account: AzureAccount, subscription: azureResource.AzureResourceSubscription, storageAccount: azureResource.AzureGraphResource, containerName: string, ignoreErrors: boolean): Promise<GetBlobsResult> {
const result: GetBlobsResult = { blobs: [], errors: [] }; const result: GetBlobsResult = { blobs: [], errors: [] };
const storageKeys = await getStorageAccountAccessKey(account, subscription, storageAccount, ignoreErrors); const storageKeys = await getStorageAccountAccessKey(account, subscription, storageAccount, ignoreErrors);
if (!ignoreErrors) { if (!ignoreErrors) {

View File

@@ -263,19 +263,19 @@ declare module 'azurecore' {
} }
export interface IExtension { export interface IExtension {
getSubscriptions(account?: azdata.Account, ignoreErrors?: boolean, selectedOnly?: boolean): Promise<GetSubscriptionsResult>; getSubscriptions(account?: AzureAccount, ignoreErrors?: boolean, selectedOnly?: boolean): Promise<GetSubscriptionsResult>;
getResourceGroups(account?: azdata.Account, subscription?: azureResource.AzureResourceSubscription, ignoreErrors?: boolean): Promise<GetResourceGroupsResult>; getResourceGroups(account?: AzureAccount, subscription?: azureResource.AzureResourceSubscription, ignoreErrors?: boolean): Promise<GetResourceGroupsResult>;
getLocations(account?: azdata.Account, subscription?: azureResource.AzureResourceSubscription, ignoreErrors?: boolean): Promise<GetLocationsResult>; getLocations(account?: AzureAccount, subscription?: azureResource.AzureResourceSubscription, ignoreErrors?: boolean): Promise<GetLocationsResult>;
getSqlManagedInstances(account: azdata.Account, subscriptions: azureResource.AzureResourceSubscription[], ignoreErrors?: boolean): Promise<GetSqlManagedInstancesResult>; getSqlManagedInstances(account: AzureAccount, subscriptions: azureResource.AzureResourceSubscription[], ignoreErrors?: boolean): Promise<GetSqlManagedInstancesResult>;
getManagedDatabases(account: azdata.Account, subscription: azureResource.AzureResourceSubscription, managedInstance: azureResource.AzureSqlManagedInstance, ignoreErrors?: boolean): Promise<GetManagedDatabasesResult>; getManagedDatabases(account: AzureAccount, subscription: azureResource.AzureResourceSubscription, managedInstance: azureResource.AzureSqlManagedInstance, ignoreErrors?: boolean): Promise<GetManagedDatabasesResult>;
getSqlServers(account: azdata.Account, subscriptions: azureResource.AzureResourceSubscription[], ignoreErrors?: boolean): Promise<GetSqlServersResult>; getSqlServers(account: AzureAccount, subscriptions: azureResource.AzureResourceSubscription[], ignoreErrors?: boolean): Promise<GetSqlServersResult>;
getSqlVMServers(account: azdata.Account, subscriptions: azureResource.AzureResourceSubscription[], ignoreErrors?: boolean): Promise<GetSqlVMServersResult>; getSqlVMServers(account: AzureAccount, subscriptions: azureResource.AzureResourceSubscription[], ignoreErrors?: boolean): Promise<GetSqlVMServersResult>;
getStorageAccounts(account: azdata.Account, subscriptions: azureResource.AzureResourceSubscription[], ignoreErrors?: boolean): Promise<GetStorageAccountResult>; getStorageAccounts(account: AzureAccount, subscriptions: azureResource.AzureResourceSubscription[], ignoreErrors?: boolean): Promise<GetStorageAccountResult>;
getBlobContainers(account: azdata.Account, subscription: azureResource.AzureResourceSubscription, storageAccount: azureResource.AzureGraphResource, ignoreErrors?: boolean): Promise<GetBlobContainersResult>; getBlobContainers(account: AzureAccount, subscription: azureResource.AzureResourceSubscription, storageAccount: azureResource.AzureGraphResource, ignoreErrors?: boolean): Promise<GetBlobContainersResult>;
getFileShares(account: azdata.Account, subscription: azureResource.AzureResourceSubscription, storageAccount: azureResource.AzureGraphResource, ignoreErrors?: boolean): Promise<GetFileSharesResult>; getFileShares(account: AzureAccount, subscription: azureResource.AzureResourceSubscription, storageAccount: azureResource.AzureGraphResource, ignoreErrors?: boolean): Promise<GetFileSharesResult>;
createResourceGroup(account: azdata.Account, subscription: azureResource.AzureResourceSubscription, resourceGroupName: string, location: string, ignoreErrors?: boolean): Promise<CreateResourceGroupResult>; createResourceGroup(account: AzureAccount, subscription: azureResource.AzureResourceSubscription, resourceGroupName: string, location: string, ignoreErrors?: boolean): Promise<CreateResourceGroupResult>;
getStorageAccountAccessKey(account: azdata.Account, subscription: azureResource.AzureResourceSubscription, storageAccount: azureResource.AzureGraphResource, ignoreErrors?: boolean): Promise<GetStorageAccountAccessKeyResult>; getStorageAccountAccessKey(account: AzureAccount, subscription: azureResource.AzureResourceSubscription, storageAccount: azureResource.AzureGraphResource, ignoreErrors?: boolean): Promise<GetStorageAccountAccessKeyResult>;
getBlobs(account: azdata.Account, subscription: azureResource.AzureResourceSubscription, storageAccount: azureResource.AzureGraphResource, containerName: string, ignoreErrors?: boolean): Promise<GetBlobsResult>; getBlobs(account: AzureAccount, subscription: azureResource.AzureResourceSubscription, storageAccount: azureResource.AzureGraphResource, containerName: string, ignoreErrors?: boolean): Promise<GetBlobsResult>;
/** /**
* Makes Azure REST requests to create, retrieve, update or delete access to azure service's resources. * Makes Azure REST requests to create, retrieve, update or delete access to azure service's resources.
* For reference to different service URLs, See https://docs.microsoft.com/rest/api/?view=Azure * For reference to different service URLs, See https://docs.microsoft.com/rest/api/?view=Azure
@@ -288,7 +288,7 @@ declare module 'azurecore' {
* @param host Use this to override the host. The default host is https://management.azure.com * @param host Use this to override the host. The default host is https://management.azure.com
* @param requestHeaders Provide additional request headers * @param requestHeaders Provide additional request headers
*/ */
makeAzureRestRequest(account: azdata.Account, subscription: azureResource.AzureResourceSubscription, path: string, requestType: HttpRequestMethod, requestBody?: any, ignoreErrors?: boolean, host?: string, requestHeaders?: { [key: string]: string }): Promise<AzureRestResponse>; makeAzureRestRequest(account: AzureAccount, subscription: azureResource.AzureResourceSubscription, path: string, requestType: HttpRequestMethod, requestBody?: any, ignoreErrors?: boolean, host?: string, requestHeaders?: { [key: string]: string }): Promise<AzureRestResponse>;
/** /**
* Converts a region value (@see AzureRegion) into the localized Display Name * Converts a region value (@see AzureRegion) into the localized Display Name
* @param region The region value * @param region The region value
@@ -296,7 +296,7 @@ declare module 'azurecore' {
getRegionDisplayName(region?: string): string; getRegionDisplayName(region?: string): string;
provideResources(): azureResource.IAzureResourceProvider[]; provideResources(): azureResource.IAzureResourceProvider[];
runGraphQuery<T extends azureResource.AzureGraphResource>(account: azdata.Account, subscriptions: azureResource.AzureResourceSubscription[], ignoreErrors: boolean, query: string): Promise<ResourceQueryResult<T>>; runGraphQuery<T extends azureResource.AzureGraphResource>(account: AzureAccount, subscriptions: azureResource.AzureResourceSubscription[], ignoreErrors: boolean, query: string): Promise<ResourceQueryResult<T>>;
} }
export type GetSubscriptionsResult = { subscriptions: azureResource.AzureResourceSubscription[], errors: Error[] }; export type GetSubscriptionsResult = { subscriptions: azureResource.AzureResourceSubscription[], errors: Error[] };

View File

@@ -117,7 +117,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<azurec
if (triggerValue === '') { if (triggerValue === '') {
return ''; return '';
} }
let accounts: azdata.Account[] = []; let accounts: azurecore.AzureAccount[] = [];
try { try {
accounts = await azdata.accounts.getAllAccounts(); accounts = await azdata.accounts.getAllAccounts();
} catch (err) { } catch (err) {
@@ -148,8 +148,8 @@ export async function activate(context: vscode.ExtensionContext): Promise<azurec
? azureResourceUtils.getSelectedSubscriptions(appContext, account, ignoreErrors) ? azureResourceUtils.getSelectedSubscriptions(appContext, account, ignoreErrors)
: azureResourceUtils.getSubscriptions(appContext, account, ignoreErrors); : azureResourceUtils.getSubscriptions(appContext, account, ignoreErrors);
}, },
getResourceGroups(account?: azdata.Account, subscription?: azureResource.AzureResourceSubscription, ignoreErrors?: boolean): Promise<azurecore.GetResourceGroupsResult> { return azureResourceUtils.getResourceGroups(appContext, account, subscription, ignoreErrors); }, getResourceGroups(account?: azurecore.AzureAccount, subscription?: azureResource.AzureResourceSubscription, ignoreErrors?: boolean): Promise<azurecore.GetResourceGroupsResult> { return azureResourceUtils.getResourceGroups(appContext, account, subscription, ignoreErrors); },
getLocations(account?: azdata.Account, getLocations(account?: azurecore.AzureAccount,
subscription?: azureResource.AzureResourceSubscription, subscription?: azureResource.AzureResourceSubscription,
ignoreErrors?: boolean): Promise<azurecore.GetLocationsResult> { ignoreErrors?: boolean): Promise<azurecore.GetLocationsResult> {
return azureResourceUtils.getLocations(appContext, account, subscription, ignoreErrors); return azureResourceUtils.getLocations(appContext, account, subscription, ignoreErrors);
@@ -172,65 +172,65 @@ export async function activate(context: vscode.ExtensionContext): Promise<azurec
} }
return providers; return providers;
}, },
getSqlManagedInstances(account: azdata.Account, getSqlManagedInstances(account: azurecore.AzureAccount,
subscriptions: azureResource.AzureResourceSubscription[], subscriptions: azureResource.AzureResourceSubscription[],
ignoreErrors: boolean): Promise<azurecore.GetSqlManagedInstancesResult> { ignoreErrors: boolean): Promise<azurecore.GetSqlManagedInstancesResult> {
return azureResourceUtils.runResourceQuery(account, subscriptions, ignoreErrors, `where type == "${azureResource.AzureResourceType.sqlManagedInstance}"`); return azureResourceUtils.runResourceQuery(account, subscriptions, ignoreErrors, `where type == "${azureResource.AzureResourceType.sqlManagedInstance}"`);
}, },
getManagedDatabases(account: azdata.Account, getManagedDatabases(account: azurecore.AzureAccount,
subscription: azureResource.AzureResourceSubscription, subscription: azureResource.AzureResourceSubscription,
managedInstance: azureResource.AzureSqlManagedInstance, managedInstance: azureResource.AzureSqlManagedInstance,
ignoreErrors: boolean): Promise<azurecore.GetManagedDatabasesResult> { ignoreErrors: boolean): Promise<azurecore.GetManagedDatabasesResult> {
return azureResourceUtils.getManagedDatabases(account, subscription, managedInstance, ignoreErrors); return azureResourceUtils.getManagedDatabases(account, subscription, managedInstance, ignoreErrors);
}, },
getSqlServers(account: azdata.Account, getSqlServers(account: azurecore.AzureAccount,
subscriptions: azureResource.AzureResourceSubscription[], subscriptions: azureResource.AzureResourceSubscription[],
ignoreErrors: boolean): Promise<azurecore.GetSqlServersResult> { ignoreErrors: boolean): Promise<azurecore.GetSqlServersResult> {
return azureResourceUtils.runResourceQuery(account, subscriptions, ignoreErrors, `where type == "${azureResource.AzureResourceType.sqlServer}"`); return azureResourceUtils.runResourceQuery(account, subscriptions, ignoreErrors, `where type == "${azureResource.AzureResourceType.sqlServer}"`);
}, },
getSqlVMServers(account: azdata.Account, getSqlVMServers(account: azurecore.AzureAccount,
subscriptions: azureResource.AzureResourceSubscription[], subscriptions: azureResource.AzureResourceSubscription[],
ignoreErrors: boolean): Promise<azurecore.GetSqlVMServersResult> { ignoreErrors: boolean): Promise<azurecore.GetSqlVMServersResult> {
return azureResourceUtils.runResourceQuery(account, subscriptions, ignoreErrors, `where type == "${azureResource.AzureResourceType.virtualMachines}" and properties.storageProfile.imageReference.publisher == "microsoftsqlserver"`); return azureResourceUtils.runResourceQuery(account, subscriptions, ignoreErrors, `where type == "${azureResource.AzureResourceType.virtualMachines}" and properties.storageProfile.imageReference.publisher == "microsoftsqlserver"`);
}, },
getStorageAccounts(account: azdata.Account, getStorageAccounts(account: azurecore.AzureAccount,
subscriptions: azureResource.AzureResourceSubscription[], subscriptions: azureResource.AzureResourceSubscription[],
ignoreErrors: boolean): Promise<azurecore.GetStorageAccountResult> { ignoreErrors: boolean): Promise<azurecore.GetStorageAccountResult> {
return azureResourceUtils.runResourceQuery(account, subscriptions, ignoreErrors, `where type == "${azureResource.AzureResourceType.storageAccount}"`); return azureResourceUtils.runResourceQuery(account, subscriptions, ignoreErrors, `where type == "${azureResource.AzureResourceType.storageAccount}"`);
}, },
getBlobContainers(account: azdata.Account, getBlobContainers(account: azurecore.AzureAccount,
subscription: azureResource.AzureResourceSubscription, subscription: azureResource.AzureResourceSubscription,
storageAccount: azureResource.AzureGraphResource, storageAccount: azureResource.AzureGraphResource,
ignoreErrors: boolean): Promise<azurecore.GetBlobContainersResult> { ignoreErrors: boolean): Promise<azurecore.GetBlobContainersResult> {
return azureResourceUtils.getBlobContainers(account, subscription, storageAccount, ignoreErrors); return azureResourceUtils.getBlobContainers(account, subscription, storageAccount, ignoreErrors);
}, },
getFileShares(account: azdata.Account, getFileShares(account: azurecore.AzureAccount,
subscription: azureResource.AzureResourceSubscription, subscription: azureResource.AzureResourceSubscription,
storageAccount: azureResource.AzureGraphResource, storageAccount: azureResource.AzureGraphResource,
ignoreErrors: boolean): Promise<azurecore.GetFileSharesResult> { ignoreErrors: boolean): Promise<azurecore.GetFileSharesResult> {
return azureResourceUtils.getFileShares(account, subscription, storageAccount, ignoreErrors); return azureResourceUtils.getFileShares(account, subscription, storageAccount, ignoreErrors);
}, },
getStorageAccountAccessKey(account: azdata.Account, getStorageAccountAccessKey(account: azurecore.AzureAccount,
subscription: azureResource.AzureResourceSubscription, subscription: azureResource.AzureResourceSubscription,
storageAccount: azureResource.AzureGraphResource, storageAccount: azureResource.AzureGraphResource,
ignoreErrors: boolean): Promise<azurecore.GetStorageAccountAccessKeyResult> { ignoreErrors: boolean): Promise<azurecore.GetStorageAccountAccessKeyResult> {
return azureResourceUtils.getStorageAccountAccessKey(account, subscription, storageAccount, ignoreErrors); return azureResourceUtils.getStorageAccountAccessKey(account, subscription, storageAccount, ignoreErrors);
}, },
getBlobs(account: azdata.Account, getBlobs(account: azurecore.AzureAccount,
subscription: azureResource.AzureResourceSubscription, subscription: azureResource.AzureResourceSubscription,
storageAccount: azureResource.AzureGraphResource, storageAccount: azureResource.AzureGraphResource,
containerName: string, containerName: string,
ignoreErrors: boolean): Promise<azurecore.GetBlobsResult> { ignoreErrors: boolean): Promise<azurecore.GetBlobsResult> {
return azureResourceUtils.getBlobs(account, subscription, storageAccount, containerName, ignoreErrors); return azureResourceUtils.getBlobs(account, subscription, storageAccount, containerName, ignoreErrors);
}, },
createResourceGroup(account: azdata.Account, createResourceGroup(account: azurecore.AzureAccount,
subscription: azureResource.AzureResourceSubscription, subscription: azureResource.AzureResourceSubscription,
resourceGroupName: string, resourceGroupName: string,
location: string, location: string,
ignoreErrors: boolean): Promise<azurecore.CreateResourceGroupResult> { ignoreErrors: boolean): Promise<azurecore.CreateResourceGroupResult> {
return azureResourceUtils.createResourceGroup(account, subscription, resourceGroupName, location, ignoreErrors); return azureResourceUtils.createResourceGroup(account, subscription, resourceGroupName, location, ignoreErrors);
}, },
makeAzureRestRequest(account: azdata.Account, makeAzureRestRequest(account: azurecore.AzureAccount,
subscription: azureResource.AzureResourceSubscription, subscription: azureResource.AzureResourceSubscription,
path: string, path: string,
requestType: azurecore.HttpRequestMethod, requestType: azurecore.HttpRequestMethod,
@@ -241,7 +241,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<azurec
return azureResourceUtils.makeHttpRequest(account, subscription, path, requestType, requestBody, ignoreErrors, host, requestHeaders); return azureResourceUtils.makeHttpRequest(account, subscription, path, requestType, requestBody, ignoreErrors, host, requestHeaders);
}, },
getRegionDisplayName: utils.getRegionDisplayName, getRegionDisplayName: utils.getRegionDisplayName,
runGraphQuery<T extends azureResource.AzureGraphResource>(account: azdata.Account, runGraphQuery<T extends azureResource.AzureGraphResource>(account: azurecore.AzureAccount,
subscriptions: azureResource.AzureResourceSubscription[], subscriptions: azureResource.AzureResourceSubscription[],
ignoreErrors: boolean, ignoreErrors: boolean,
query: string): Promise<azurecore.ResourceQueryResult<T>> { query: string): Promise<azurecore.ResourceQueryResult<T>> {

View File

@@ -23,6 +23,7 @@ import { AzureResourceSubscriptionTreeNode } from '../../../azureResource/tree/s
import { AzureResourceItemType, AzureResourceServiceNames } from '../../../azureResource/constants'; import { AzureResourceItemType, AzureResourceServiceNames } from '../../../azureResource/constants';
import { AzureResourceMessageTreeNode } from '../../../azureResource/messageTreeNode'; import { AzureResourceMessageTreeNode } from '../../../azureResource/messageTreeNode';
import { generateGuid } from '../../../azureResource/utils'; import { generateGuid } from '../../../azureResource/utils';
import { AzureAccount } from 'azurecore';
// Mock services // Mock services
let mockExtensionContext: TypeMoq.IMock<vscode.ExtensionContext>; let mockExtensionContext: TypeMoq.IMock<vscode.ExtensionContext>;
@@ -35,7 +36,7 @@ let mockTreeChangeHandler: TypeMoq.IMock<IAzureResourceTreeChangeHandler>;
// Mock test data // Mock test data
const mockTenantId = 'mock_tenant_id'; const mockTenantId = 'mock_tenant_id';
const mockAccount: azdata.Account = { const mockAccount: AzureAccount = {
key: { key: {
accountId: '97915f6d-84fa-4926-b60c-38db64327ad7', accountId: '97915f6d-84fa-4926-b60c-38db64327ad7',
providerId: 'mock_provider' providerId: 'mock_provider'
@@ -50,9 +51,16 @@ const mockAccount: azdata.Account = {
properties: { properties: {
tenants: [ tenants: [
{ {
id: mockTenantId id: mockTenantId,
displayName: 'Mock Tenant'
} }
] ],
providerSettings: {
settings: { },
id: 'azure',
displayName: 'Azure'
},
isMsAccount: true
}, },
isStale: false isStale: false
}; };

View File

@@ -5,7 +5,6 @@
import * as should from 'should'; import * as should from 'should';
import * as TypeMoq from 'typemoq'; import * as TypeMoq from 'typemoq';
import * as azdata from 'azdata';
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import 'mocha'; import 'mocha';
import { AppContext } from '../../../appContext'; import { AppContext } from '../../../appContext';
@@ -18,6 +17,7 @@ import { AzureResourceService } from '../../../azureResource/resourceService';
import { AzureResourceResourceTreeNode } from '../../../azureResource/resourceTreeNode'; import { AzureResourceResourceTreeNode } from '../../../azureResource/resourceTreeNode';
import { IAzureResourceCacheService } from '../../../azureResource/interfaces'; import { IAzureResourceCacheService } from '../../../azureResource/interfaces';
import { generateGuid } from '../../../azureResource/utils'; import { generateGuid } from '../../../azureResource/utils';
import { AzureAccount } from 'azurecore';
// Mock services // Mock services
let appContext: AppContext; let appContext: AppContext;
@@ -28,7 +28,7 @@ let mockCacheService: TypeMoq.IMock<IAzureResourceCacheService>;
let mockTreeChangeHandler: TypeMoq.IMock<IAzureResourceTreeChangeHandler>; let mockTreeChangeHandler: TypeMoq.IMock<IAzureResourceTreeChangeHandler>;
// Mock test data // Mock test data
const mockAccount: azdata.Account = { const mockAccount: AzureAccount = {
key: { key: {
accountId: 'mock_account', accountId: 'mock_account',
providerId: 'mock_provider' providerId: 'mock_provider'

View File

@@ -17,6 +17,7 @@ import { AzureResourceAccountTreeNode } from '../../../azureResource/tree/accoun
import { AzureResourceAccountNotSignedInTreeNode } from '../../../azureResource/tree/accountNotSignedInTreeNode'; import { AzureResourceAccountNotSignedInTreeNode } from '../../../azureResource/tree/accountNotSignedInTreeNode';
import { AzureResourceServiceNames } from '../../../azureResource/constants'; import { AzureResourceServiceNames } from '../../../azureResource/constants';
import { generateGuid } from '../../../azureResource/utils'; import { generateGuid } from '../../../azureResource/utils';
import { AzureAccount } from 'azurecore';
// Mock services // Mock services
let mockAppContext: AppContext; let mockAppContext: AppContext;
@@ -25,7 +26,7 @@ let mockExtensionContext: TypeMoq.IMock<vscode.ExtensionContext>;
let mockCacheService: TypeMoq.IMock<IAzureResourceCacheService>; let mockCacheService: TypeMoq.IMock<IAzureResourceCacheService>;
// Mock test data // Mock test data
const mockAccount1: azdata.Account = { const mockAccount1: AzureAccount = {
key: { key: {
accountId: 'mock_account_1', accountId: 'mock_account_1',
providerId: 'mock_provider' providerId: 'mock_provider'
@@ -39,7 +40,7 @@ const mockAccount1: azdata.Account = {
properties: undefined, properties: undefined,
isStale: false isStale: false
}; };
const mockAccount2: azdata.Account = { const mockAccount2: AzureAccount = {
key: { key: {
accountId: 'mock_account_2', accountId: 'mock_account_2',
providerId: 'mock_provider' providerId: 'mock_provider'