mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Support for removing hardcoded deployment options (#8986)
* Support for removing hardcode deployment options * Add missing file * Generalize errors and make name and id required. Sort dropdowns. * Fix test * Capitalize text
This commit is contained in:
@@ -21,8 +21,30 @@ export namespace azureResource {
|
||||
readonly treeItem: TreeItem;
|
||||
}
|
||||
|
||||
export interface AzureResourceSubscription {
|
||||
id: string;
|
||||
export interface AzureResource {
|
||||
name: string;
|
||||
id: string;
|
||||
}
|
||||
|
||||
export interface AzureResourceSubscription extends AzureResource {
|
||||
}
|
||||
|
||||
export interface AzureSqlResource extends AzureResource {
|
||||
loginName: string;
|
||||
}
|
||||
|
||||
export interface AzureResourceResourceGroup extends AzureResource {
|
||||
}
|
||||
|
||||
export interface AzureResourceDatabase extends AzureSqlResource {
|
||||
serverName: string;
|
||||
serverFullName: string;
|
||||
}
|
||||
|
||||
export interface AzureResourceDatabaseServer extends AzureSqlResource {
|
||||
fullName: string;
|
||||
defaultDatabaseName: string;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -18,8 +18,47 @@ import { AzureResourceTreeProvider } from './tree/treeProvider';
|
||||
import { AzureResourceAccountTreeNode } from './tree/accountTreeNode';
|
||||
import { IAzureResourceSubscriptionService, IAzureResourceSubscriptionFilterService } from '../azureResource/interfaces';
|
||||
import { AzureResourceServiceNames } from './constants';
|
||||
import { AzureResourceGroupService } from './providers/resourceGroup/resourceGroupService';
|
||||
|
||||
export function registerAzureResourceCommands(appContext: AppContext, tree: AzureResourceTreeProvider): void {
|
||||
|
||||
// Resource Management commands
|
||||
appContext.apiWrapper.registerCommand('azure.accounts.getSubscriptions', async (account: azdata.Account) => {
|
||||
const subscriptions = <azureResource.AzureResourceSubscription[]>[];
|
||||
try {
|
||||
const subscriptionService = appContext.getService<IAzureResourceSubscriptionService>(AzureResourceServiceNames.subscriptionService);
|
||||
const tokens = await appContext.apiWrapper.getSecurityToken(account, azdata.AzureResource.ResourceManagement);
|
||||
|
||||
for (const tenant of account.properties.tenants) {
|
||||
const token = tokens[tenant.id].token;
|
||||
const tokenType = tokens[tenant.id].tokenType;
|
||||
|
||||
subscriptions.push(...await subscriptionService.getSubscriptions(account, new TokenCredentials(token, tokenType)));
|
||||
}
|
||||
} catch (error) {
|
||||
throw new Error(localize('azure.accounts.getSubscriptions.error', "Unexpected error occurred getting the subscriptions for account {0}. {1}", account.key.accountId, error));
|
||||
}
|
||||
return subscriptions;
|
||||
});
|
||||
|
||||
appContext.apiWrapper.registerCommand('azure.accounts.getResourceGroups', async (account: azdata.Account, subscription: azureResource.AzureResourceSubscription) => {
|
||||
try {
|
||||
const service = new AzureResourceGroupService();
|
||||
const resourceGroups: azureResource.AzureResourceResourceGroup[] = [];
|
||||
for (const tenant of account.properties.tenants) {
|
||||
const tokens = await appContext.apiWrapper.getSecurityToken(account, azdata.AzureResource.ResourceManagement);
|
||||
const token = tokens[tenant.id].token;
|
||||
const tokenType = tokens[tenant.id].tokenType;
|
||||
|
||||
resourceGroups.push(...await service.getResources(subscription, new TokenCredentials(token, tokenType)));
|
||||
}
|
||||
return resourceGroups;
|
||||
} catch (error) {
|
||||
throw new Error(localize('azure.accounts.getResourceGroups.error', "Unexpected error occurred getting the subscriptions for subscription {0} ({1}). {2}", subscription.name, subscription.id, error));
|
||||
}
|
||||
});
|
||||
|
||||
// Resource Tree commands
|
||||
appContext.apiWrapper.registerCommand('azure.resource.selectsubscriptions', async (node?: TreeNode) => {
|
||||
if (!(node instanceof AzureResourceAccountTreeNode)) {
|
||||
return;
|
||||
|
||||
@@ -41,23 +41,6 @@ export interface IAzureResourceNodeWithProviderId {
|
||||
resourceNode: azureResource.IAzureResourceNode;
|
||||
}
|
||||
|
||||
export interface AzureSqlResource {
|
||||
name: string;
|
||||
loginName: string;
|
||||
}
|
||||
|
||||
export interface IAzureResourceService<T extends AzureSqlResource> {
|
||||
export interface IAzureResourceService<T extends azureResource.AzureResource> {
|
||||
getResources(subscription: azureResource.AzureResourceSubscription, credential: msRest.ServiceClientCredentials): Promise<T[]>;
|
||||
}
|
||||
|
||||
|
||||
export interface AzureResourceDatabase extends AzureSqlResource {
|
||||
serverName: string;
|
||||
serverFullName: string;
|
||||
}
|
||||
|
||||
export interface AzureResourceDatabaseServer extends AzureSqlResource {
|
||||
id?: string;
|
||||
fullName: string;
|
||||
defaultDatabaseName: string;
|
||||
}
|
||||
|
||||
@@ -9,11 +9,11 @@ import { ApiWrapper } from '../../../apiWrapper';
|
||||
|
||||
import { azureResource } from '../../azure-resource';
|
||||
import { AzureResourceDatabaseTreeDataProvider } from './databaseTreeDataProvider';
|
||||
import { IAzureResourceService, AzureResourceDatabase } from '../../interfaces';
|
||||
import { IAzureResourceService } from '../../interfaces';
|
||||
|
||||
export class AzureResourceDatabaseProvider implements azureResource.IAzureResourceProvider {
|
||||
public constructor(
|
||||
private _databaseService: IAzureResourceService<AzureResourceDatabase>,
|
||||
private _databaseService: IAzureResourceService<azureResource.AzureResourceDatabase>,
|
||||
private _apiWrapper: ApiWrapper,
|
||||
private _extensionContext: ExtensionContext
|
||||
) {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
import { ServiceClientCredentials } from '@azure/ms-rest-js';
|
||||
import { azureResource } from '../../azure-resource';
|
||||
import { IAzureResourceService, AzureResourceDatabase } from '../../interfaces';
|
||||
import { IAzureResourceService } from '../../interfaces';
|
||||
import { serversQuery, DbServerGraphData } from '../databaseServer/databaseServerService';
|
||||
import { ResourceGraphClient } from '@azure/arm-resourcegraph';
|
||||
import { queryGraphResources, GraphData } from '../resourceTreeDataProviderBase';
|
||||
@@ -13,9 +13,9 @@ import { queryGraphResources, GraphData } from '../resourceTreeDataProviderBase'
|
||||
interface DatabaseGraphData extends GraphData {
|
||||
kind: string;
|
||||
}
|
||||
export class AzureResourceDatabaseService implements IAzureResourceService<AzureResourceDatabase> {
|
||||
public async getResources(subscription: azureResource.AzureResourceSubscription, credential: ServiceClientCredentials): Promise<AzureResourceDatabase[]> {
|
||||
const databases: AzureResourceDatabase[] = [];
|
||||
export class AzureResourceDatabaseService implements IAzureResourceService<azureResource.AzureResourceDatabase> {
|
||||
public async getResources(subscription: azureResource.AzureResourceSubscription, credential: ServiceClientCredentials): Promise<azureResource.AzureResourceDatabase[]> {
|
||||
const databases: azureResource.AzureResourceDatabase[] = [];
|
||||
const resourceClient = new ResourceGraphClient(credential);
|
||||
|
||||
// Query servers and databases in parallel (start both promises before waiting on the 1st)
|
||||
@@ -46,6 +46,7 @@ export class AzureResourceDatabaseService implements IAzureResourceService<Azure
|
||||
if (server) {
|
||||
databases.push({
|
||||
name: db.name,
|
||||
id: db.id,
|
||||
serverName: server.name,
|
||||
serverFullName: server.properties.fullyQualifiedDomainName,
|
||||
loginName: server.properties.administratorLogin
|
||||
|
||||
@@ -12,22 +12,22 @@ import { azureResource } from '../../azure-resource';
|
||||
import { AzureResourceItemType } from '../../../azureResource/constants';
|
||||
import { ApiWrapper } from '../../../apiWrapper';
|
||||
import { generateGuid } from '../../utils';
|
||||
import { IAzureResourceService, AzureResourceDatabase } from '../../interfaces';
|
||||
import { IAzureResourceService } from '../../interfaces';
|
||||
import { ResourceTreeDataProviderBase } from '../resourceTreeDataProviderBase';
|
||||
|
||||
export class AzureResourceDatabaseTreeDataProvider extends ResourceTreeDataProviderBase<AzureResourceDatabase> {
|
||||
export class AzureResourceDatabaseTreeDataProvider extends ResourceTreeDataProviderBase<azureResource.AzureResourceDatabase> {
|
||||
|
||||
private static readonly containerId = 'azure.resource.providers.database.treeDataProvider.databaseContainer';
|
||||
private static readonly containerLabel = localize('azure.resource.providers.database.treeDataProvider.databaseContainerLabel', "SQL Databases");
|
||||
|
||||
public constructor(
|
||||
databaseService: IAzureResourceService<AzureResourceDatabase>,
|
||||
databaseService: IAzureResourceService<azureResource.AzureResourceDatabase>,
|
||||
apiWrapper: ApiWrapper,
|
||||
private _extensionContext: ExtensionContext
|
||||
) {
|
||||
super(databaseService, apiWrapper);
|
||||
}
|
||||
protected getTreeItemForResource(database: AzureResourceDatabase): TreeItem {
|
||||
protected getTreeItemForResource(database: azureResource.AzureResourceDatabase): TreeItem {
|
||||
return {
|
||||
id: `databaseServer_${database.serverFullName}.database_${database.name}`,
|
||||
label: `${database.name} (${database.serverName})`,
|
||||
|
||||
@@ -7,12 +7,12 @@ import { ExtensionContext } from 'vscode';
|
||||
import { ApiWrapper } from '../../../apiWrapper';
|
||||
|
||||
import { azureResource } from '../../azure-resource';
|
||||
import { IAzureResourceService, AzureResourceDatabaseServer } from '../../interfaces';
|
||||
import { IAzureResourceService } from '../../interfaces';
|
||||
import { AzureResourceDatabaseServerTreeDataProvider } from './databaseServerTreeDataProvider';
|
||||
|
||||
export class AzureResourceDatabaseServerProvider implements azureResource.IAzureResourceProvider {
|
||||
public constructor(
|
||||
private _databaseServerService: IAzureResourceService<AzureResourceDatabaseServer>,
|
||||
private _databaseServerService: IAzureResourceService<azureResource.AzureResourceDatabaseServer>,
|
||||
private _apiWrapper: ApiWrapper,
|
||||
private _extensionContext: ExtensionContext
|
||||
) {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
|
||||
import { ResourceServiceBase, GraphData } from '../resourceTreeDataProviderBase';
|
||||
import { AzureResourceDatabaseServer } from '../../interfaces';
|
||||
import { azureResource } from '../../azure-resource';
|
||||
|
||||
|
||||
export interface DbServerGraphData extends GraphData {
|
||||
@@ -17,13 +17,13 @@ export interface DbServerGraphData extends GraphData {
|
||||
|
||||
export const serversQuery = 'where type == "microsoft.sql/servers"';
|
||||
|
||||
export class AzureResourceDatabaseServerService extends ResourceServiceBase<DbServerGraphData, AzureResourceDatabaseServer> {
|
||||
export class AzureResourceDatabaseServerService extends ResourceServiceBase<DbServerGraphData, azureResource.AzureResourceDatabaseServer> {
|
||||
|
||||
protected get query(): string {
|
||||
return serversQuery;
|
||||
}
|
||||
|
||||
protected convertResource(resource: DbServerGraphData): AzureResourceDatabaseServer {
|
||||
protected convertResource(resource: DbServerGraphData): azureResource.AzureResourceDatabaseServer {
|
||||
return {
|
||||
id: resource.id,
|
||||
name: resource.name,
|
||||
|
||||
@@ -11,16 +11,16 @@ const localize = nls.loadMessageBundle();
|
||||
import { AzureResourceItemType } from '../../../azureResource/constants';
|
||||
import { ApiWrapper } from '../../../apiWrapper';
|
||||
import { generateGuid } from '../../utils';
|
||||
import { IAzureResourceService, AzureResourceDatabaseServer } from '../../interfaces';
|
||||
import { IAzureResourceService } from '../../interfaces';
|
||||
import { ResourceTreeDataProviderBase } from '../resourceTreeDataProviderBase';
|
||||
import { azureResource } from '../../azure-resource';
|
||||
|
||||
export class AzureResourceDatabaseServerTreeDataProvider extends ResourceTreeDataProviderBase<AzureResourceDatabaseServer> {
|
||||
export class AzureResourceDatabaseServerTreeDataProvider extends ResourceTreeDataProviderBase<azureResource.AzureResourceDatabaseServer> {
|
||||
private static readonly containerId = 'azure.resource.providers.databaseServer.treeDataProvider.databaseServerContainer';
|
||||
private static readonly containerLabel = localize('azure.resource.providers.databaseServer.treeDataProvider.databaseServerContainerLabel', "SQL Servers");
|
||||
|
||||
public constructor(
|
||||
databaseServerService: IAzureResourceService<AzureResourceDatabaseServer>,
|
||||
databaseServerService: IAzureResourceService<azureResource.AzureResourceDatabaseServer>,
|
||||
apiWrapper: ApiWrapper,
|
||||
private _extensionContext: ExtensionContext
|
||||
) {
|
||||
@@ -28,7 +28,7 @@ export class AzureResourceDatabaseServerTreeDataProvider extends ResourceTreeDat
|
||||
}
|
||||
|
||||
|
||||
protected getTreeItemForResource(databaseServer: AzureResourceDatabaseServer): TreeItem {
|
||||
protected getTreeItemForResource(databaseServer: azureResource.AzureResourceDatabaseServer): TreeItem {
|
||||
return {
|
||||
id: `databaseServer_${databaseServer.id ? databaseServer.id : databaseServer.name}`,
|
||||
label: databaseServer.name,
|
||||
|
||||
@@ -7,12 +7,12 @@ import { ExtensionContext } from 'vscode';
|
||||
import { ApiWrapper } from '../../../apiWrapper';
|
||||
|
||||
import { azureResource } from '../../azure-resource';
|
||||
import { IAzureResourceService, AzureResourceDatabaseServer } from '../../interfaces';
|
||||
import { IAzureResourceService } from '../../interfaces';
|
||||
import { PostgresServerTreeDataProvider as PostgresServerTreeDataProvider } from './postgresServerTreeDataProvider';
|
||||
|
||||
export class PostgresServerProvider implements azureResource.IAzureResourceProvider {
|
||||
public constructor(
|
||||
private _databaseServerService: IAzureResourceService<AzureResourceDatabaseServer>,
|
||||
private _databaseServerService: IAzureResourceService<azureResource.AzureResourceDatabaseServer>,
|
||||
private _apiWrapper: ApiWrapper,
|
||||
private _extensionContext: ExtensionContext
|
||||
) {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
|
||||
import { ResourceServiceBase, GraphData } from '../resourceTreeDataProviderBase';
|
||||
import { AzureResourceDatabaseServer } from '../../interfaces';
|
||||
import { azureResource } from '../../azure-resource';
|
||||
|
||||
|
||||
interface DbServerGraphData extends GraphData {
|
||||
@@ -17,13 +17,13 @@ interface DbServerGraphData extends GraphData {
|
||||
|
||||
const serversQuery = 'where type == "microsoft.dbforpostgresql/servers"';
|
||||
|
||||
export class PostgresServerService extends ResourceServiceBase<DbServerGraphData, AzureResourceDatabaseServer> {
|
||||
export class PostgresServerService extends ResourceServiceBase<DbServerGraphData, azureResource.AzureResourceDatabaseServer> {
|
||||
|
||||
protected get query(): string {
|
||||
return serversQuery;
|
||||
}
|
||||
|
||||
protected convertResource(resource: DbServerGraphData): AzureResourceDatabaseServer {
|
||||
protected convertResource(resource: DbServerGraphData): azureResource.AzureResourceDatabaseServer {
|
||||
return {
|
||||
id: resource.id,
|
||||
name: resource.name,
|
||||
|
||||
@@ -11,16 +11,16 @@ const localize = nls.loadMessageBundle();
|
||||
import { AzureResourceItemType } from '../../constants';
|
||||
import { ApiWrapper } from '../../../apiWrapper';
|
||||
import { generateGuid } from '../../utils';
|
||||
import { IAzureResourceService, AzureResourceDatabaseServer } from '../../interfaces';
|
||||
import { IAzureResourceService } from '../../interfaces';
|
||||
import { ResourceTreeDataProviderBase } from '../resourceTreeDataProviderBase';
|
||||
import { azureResource } from '../../azure-resource';
|
||||
|
||||
export class PostgresServerTreeDataProvider extends ResourceTreeDataProviderBase<AzureResourceDatabaseServer> {
|
||||
export class PostgresServerTreeDataProvider extends ResourceTreeDataProviderBase<azureResource.AzureResourceDatabaseServer> {
|
||||
private static readonly containerId = 'azure.resource.providers.databaseServer.treeDataProvider.postgresServerContainer';
|
||||
private static readonly containerLabel = localize('azure.resource.providers.databaseServer.treeDataProvider.postgresServerContainerLabel', "Azure Database for PostgreSQL Servers");
|
||||
|
||||
public constructor(
|
||||
databaseServerService: IAzureResourceService<AzureResourceDatabaseServer>,
|
||||
databaseServerService: IAzureResourceService<azureResource.AzureResourceDatabaseServer>,
|
||||
apiWrapper: ApiWrapper,
|
||||
private _extensionContext: ExtensionContext
|
||||
) {
|
||||
@@ -28,7 +28,7 @@ export class PostgresServerTreeDataProvider extends ResourceTreeDataProviderBase
|
||||
}
|
||||
|
||||
|
||||
protected getTreeItemForResource(databaseServer: AzureResourceDatabaseServer): TreeItem {
|
||||
protected getTreeItemForResource(databaseServer: azureResource.AzureResourceDatabaseServer): TreeItem {
|
||||
return {
|
||||
id: `databaseServer_${databaseServer.id ? databaseServer.id : databaseServer.name}`,
|
||||
label: databaseServer.name,
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { DbServerGraphData } from '../databaseServer/databaseServerService';
|
||||
import { azureResource } from '../../azure-resource';
|
||||
import { ResourceServiceBase } from '../resourceTreeDataProviderBase';
|
||||
|
||||
export class AzureResourceGroupService extends ResourceServiceBase<DbServerGraphData, azureResource.AzureResourceResourceGroup> {
|
||||
|
||||
protected get query(): string {
|
||||
return 'ResourceContainers | where type=="microsoft.resources/subscriptions/resourcegroups"';
|
||||
}
|
||||
|
||||
protected convertResource(resource: DbServerGraphData): azureResource.AzureResourceResourceGroup {
|
||||
return {
|
||||
id: resource.id,
|
||||
name: resource.name
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -3,16 +3,16 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { AzureResource, TreeItem } from 'azdata';
|
||||
import * as azdata from 'azdata';
|
||||
import * as msRest from '@azure/ms-rest-js';
|
||||
|
||||
import { azureResource } from '../azure-resource';
|
||||
import { ApiWrapper } from '../../apiWrapper';
|
||||
import { IAzureResourceService, AzureSqlResource } from '../interfaces';
|
||||
import { IAzureResourceService } from '../interfaces';
|
||||
import { AzureResourceErrorMessageUtil } from '../utils';
|
||||
import { ResourceGraphClient } from '@azure/arm-resourcegraph';
|
||||
|
||||
export abstract class ResourceTreeDataProviderBase<T extends AzureSqlResource> implements azureResource.IAzureResourceTreeDataProvider {
|
||||
export abstract class ResourceTreeDataProviderBase<T extends azureResource.AzureResource> implements azureResource.IAzureResourceTreeDataProvider {
|
||||
|
||||
public constructor(
|
||||
protected _resourceService: IAzureResourceService<T>,
|
||||
@@ -20,7 +20,7 @@ export abstract class ResourceTreeDataProviderBase<T extends AzureSqlResource> i
|
||||
) {
|
||||
}
|
||||
|
||||
public getTreeItem(element: azureResource.IAzureResourceNode): TreeItem | Thenable<TreeItem> {
|
||||
public getTreeItem(element: azureResource.IAzureResourceNode): azdata.TreeItem | Thenable<azdata.TreeItem> {
|
||||
return element.treeItem;
|
||||
}
|
||||
|
||||
@@ -45,14 +45,14 @@ export abstract class ResourceTreeDataProviderBase<T extends AzureSqlResource> i
|
||||
}
|
||||
|
||||
private async getResources(element: azureResource.IAzureResourceNode): Promise<T[]> {
|
||||
const tokens = await this._apiWrapper.getSecurityToken(element.account, AzureResource.ResourceManagement);
|
||||
const tokens = await this._apiWrapper.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) || <T[]>[];
|
||||
return resources;
|
||||
}
|
||||
|
||||
protected abstract getTreeItemForResource(resource: T): TreeItem;
|
||||
protected abstract getTreeItemForResource(resource: T): azdata.TreeItem;
|
||||
|
||||
protected abstract createContainerNode(): azureResource.IAzureResourceNode;
|
||||
}
|
||||
@@ -89,10 +89,14 @@ export async function queryGraphResources<T extends GraphData>(resourceClient: R
|
||||
return allResources;
|
||||
}
|
||||
|
||||
export abstract class ResourceServiceBase<T extends GraphData, U extends AzureSqlResource> implements IAzureResourceService<U> {
|
||||
export abstract class ResourceServiceBase<T extends GraphData, U extends azureResource.AzureResource> implements IAzureResourceService<U> {
|
||||
constructor() {
|
||||
}
|
||||
|
||||
/**
|
||||
* The query to use - see https://docs.microsoft.com/azure/governance/resource-graph/concepts/query-language
|
||||
* for more information on the supported syntax and tables/properties
|
||||
*/
|
||||
protected abstract get query(): string;
|
||||
|
||||
public async getResources(subscription: azureResource.AzureResourceSubscription, credential: msRest.ServiceClientCredentials): Promise<U[]> {
|
||||
|
||||
@@ -7,12 +7,12 @@ import { ExtensionContext } from 'vscode';
|
||||
import { ApiWrapper } from '../../../apiWrapper';
|
||||
|
||||
import { azureResource } from '../../azure-resource';
|
||||
import { IAzureResourceService, AzureResourceDatabaseServer } from '../../interfaces';
|
||||
import { IAzureResourceService } from '../../interfaces';
|
||||
import { SqlInstanceTreeDataProvider as SqlInstanceTreeDataProvider } from './sqlInstanceTreeDataProvider';
|
||||
|
||||
export class SqlInstanceProvider implements azureResource.IAzureResourceProvider {
|
||||
public constructor(
|
||||
private _service: IAzureResourceService<AzureResourceDatabaseServer>,
|
||||
private _service: IAzureResourceService<azureResource.AzureResourceDatabaseServer>,
|
||||
private _apiWrapper: ApiWrapper,
|
||||
private _extensionContext: ExtensionContext
|
||||
) {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { AzureResourceDatabaseServer } from '../../interfaces';
|
||||
import { azureResource } from '../../azure-resource';
|
||||
import { ResourceServiceBase, GraphData } from '../resourceTreeDataProviderBase';
|
||||
|
||||
interface SqlInstanceGraphData extends GraphData {
|
||||
@@ -15,13 +15,13 @@ interface SqlInstanceGraphData extends GraphData {
|
||||
|
||||
const instanceQuery = 'where type == "microsoft.sql/managedinstances"';
|
||||
|
||||
export class SqlInstanceResourceService extends ResourceServiceBase<SqlInstanceGraphData, AzureResourceDatabaseServer> {
|
||||
export class SqlInstanceResourceService extends ResourceServiceBase<SqlInstanceGraphData, azureResource.AzureResourceDatabaseServer> {
|
||||
|
||||
protected get query(): string {
|
||||
return instanceQuery;
|
||||
}
|
||||
|
||||
protected convertResource(resource: SqlInstanceGraphData): AzureResourceDatabaseServer {
|
||||
protected convertResource(resource: SqlInstanceGraphData): azureResource.AzureResourceDatabaseServer {
|
||||
return {
|
||||
id: resource.id,
|
||||
name: resource.name,
|
||||
|
||||
@@ -11,16 +11,16 @@ const localize = nls.loadMessageBundle();
|
||||
import { AzureResourceItemType } from '../../constants';
|
||||
import { ApiWrapper } from '../../../apiWrapper';
|
||||
import { generateGuid } from '../../utils';
|
||||
import { IAzureResourceService, AzureResourceDatabaseServer } from '../../interfaces';
|
||||
import { IAzureResourceService } from '../../interfaces';
|
||||
import { ResourceTreeDataProviderBase } from '../resourceTreeDataProviderBase';
|
||||
import { azureResource } from '../../azure-resource';
|
||||
|
||||
export class SqlInstanceTreeDataProvider extends ResourceTreeDataProviderBase<AzureResourceDatabaseServer> {
|
||||
export class SqlInstanceTreeDataProvider extends ResourceTreeDataProviderBase<azureResource.AzureResourceDatabaseServer> {
|
||||
private static readonly containerId = 'azure.resource.providers.sqlInstanceContainer';
|
||||
private static readonly containerLabel = localize('azure.resource.providers.sqlInstanceContainerLabel', "SQL Managed Instances");
|
||||
|
||||
public constructor(
|
||||
databaseServerService: IAzureResourceService<AzureResourceDatabaseServer>,
|
||||
databaseServerService: IAzureResourceService<azureResource.AzureResourceDatabaseServer>,
|
||||
apiWrapper: ApiWrapper,
|
||||
private _extensionContext: ExtensionContext
|
||||
) {
|
||||
@@ -28,7 +28,7 @@ export class SqlInstanceTreeDataProvider extends ResourceTreeDataProviderBase<Az
|
||||
}
|
||||
|
||||
|
||||
protected getTreeItemForResource(databaseServer: AzureResourceDatabaseServer): TreeItem {
|
||||
protected getTreeItemForResource(databaseServer: azureResource.AzureResourceDatabaseServer): TreeItem {
|
||||
return {
|
||||
id: `sqlInstance_${databaseServer.id ? databaseServer.id : databaseServer.name}`,
|
||||
label: databaseServer.name,
|
||||
|
||||
@@ -13,10 +13,10 @@ import { azureResource } from '../../../../azureResource/azure-resource';
|
||||
import { ApiWrapper } from '../../../../apiWrapper';
|
||||
import { AzureResourceDatabaseTreeDataProvider } from '../../../../azureResource/providers/database/databaseTreeDataProvider';
|
||||
import { AzureResourceItemType } from '../../../../azureResource/constants';
|
||||
import { IAzureResourceService, AzureResourceDatabase } from '../../../../azureResource/interfaces';
|
||||
import { IAzureResourceService } from '../../../../azureResource/interfaces';
|
||||
|
||||
// Mock services
|
||||
let mockDatabaseService: TypeMoq.IMock<IAzureResourceService<AzureResourceDatabase>>;
|
||||
let mockDatabaseService: TypeMoq.IMock<IAzureResourceService<azureResource.AzureResourceDatabase>>;
|
||||
let mockApiWrapper: TypeMoq.IMock<ApiWrapper>;
|
||||
let mockExtensionContext: TypeMoq.IMock<vscode.ExtensionContext>;
|
||||
|
||||
@@ -62,15 +62,17 @@ mockTokens[mockTenantId] = {
|
||||
tokenType: 'Bearer'
|
||||
};
|
||||
|
||||
const mockDatabases: AzureResourceDatabase[] = [
|
||||
const mockDatabases: azureResource.AzureResourceDatabase[] = [
|
||||
{
|
||||
name: 'mock database 1',
|
||||
id: 'mock-id-1',
|
||||
serverName: 'mock database server 1',
|
||||
serverFullName: 'mock database server full name 1',
|
||||
loginName: 'mock login'
|
||||
},
|
||||
{
|
||||
name: 'mock database 2',
|
||||
id: 'mock-id-2',
|
||||
serverName: 'mock database server 2',
|
||||
serverFullName: 'mock database server full name 2',
|
||||
loginName: 'mock login'
|
||||
@@ -79,7 +81,7 @@ const mockDatabases: AzureResourceDatabase[] = [
|
||||
|
||||
describe('AzureResourceDatabaseTreeDataProvider.info', function (): void {
|
||||
beforeEach(() => {
|
||||
mockDatabaseService = TypeMoq.Mock.ofType<IAzureResourceService<AzureResourceDatabase>>();
|
||||
mockDatabaseService = TypeMoq.Mock.ofType<IAzureResourceService<azureResource.AzureResourceDatabase>>();
|
||||
mockApiWrapper = TypeMoq.Mock.ofType<ApiWrapper>();
|
||||
mockExtensionContext = TypeMoq.Mock.ofType<vscode.ExtensionContext>();
|
||||
});
|
||||
@@ -97,7 +99,7 @@ describe('AzureResourceDatabaseTreeDataProvider.info', function (): void {
|
||||
|
||||
describe('AzureResourceDatabaseTreeDataProvider.getChildren', function (): void {
|
||||
beforeEach(() => {
|
||||
mockDatabaseService = TypeMoq.Mock.ofType<IAzureResourceService<AzureResourceDatabase>>();
|
||||
mockDatabaseService = TypeMoq.Mock.ofType<IAzureResourceService<azureResource.AzureResourceDatabase>>();
|
||||
mockApiWrapper = TypeMoq.Mock.ofType<ApiWrapper>();
|
||||
mockExtensionContext = TypeMoq.Mock.ofType<vscode.ExtensionContext>();
|
||||
|
||||
|
||||
@@ -13,10 +13,10 @@ import { azureResource } from '../../../../azureResource/azure-resource';
|
||||
import { ApiWrapper } from '../../../../apiWrapper';
|
||||
import { AzureResourceDatabaseServerTreeDataProvider } from '../../../../azureResource/providers/databaseServer/databaseServerTreeDataProvider';
|
||||
import { AzureResourceItemType } from '../../../../azureResource/constants';
|
||||
import { IAzureResourceService, AzureResourceDatabaseServer } from '../../../../azureResource/interfaces';
|
||||
import { IAzureResourceService } from '../../../../azureResource/interfaces';
|
||||
|
||||
// Mock services
|
||||
let mockDatabaseServerService: TypeMoq.IMock<IAzureResourceService<AzureResourceDatabaseServer>>;
|
||||
let mockDatabaseServerService: TypeMoq.IMock<IAzureResourceService<azureResource.AzureResourceDatabaseServer>>;
|
||||
let mockApiWrapper: TypeMoq.IMock<ApiWrapper>;
|
||||
let mockExtensionContext: TypeMoq.IMock<vscode.ExtensionContext>;
|
||||
|
||||
@@ -62,15 +62,17 @@ mockTokens[mockTenantId] = {
|
||||
tokenType: 'Bearer'
|
||||
};
|
||||
|
||||
const mockDatabaseServers: AzureResourceDatabaseServer[] = [
|
||||
const mockDatabaseServers: azureResource.AzureResourceDatabaseServer[] = [
|
||||
{
|
||||
name: 'mock database server 1',
|
||||
id: 'mock-id-1',
|
||||
fullName: 'mock database server full name 1',
|
||||
loginName: 'mock login',
|
||||
defaultDatabaseName: 'master'
|
||||
},
|
||||
{
|
||||
name: 'mock database server 2',
|
||||
id: 'mock-id-2',
|
||||
fullName: 'mock database server full name 2',
|
||||
loginName: 'mock login',
|
||||
defaultDatabaseName: 'master'
|
||||
@@ -79,7 +81,7 @@ const mockDatabaseServers: AzureResourceDatabaseServer[] = [
|
||||
|
||||
describe('AzureResourceDatabaseServerTreeDataProvider.info', function (): void {
|
||||
beforeEach(() => {
|
||||
mockDatabaseServerService = TypeMoq.Mock.ofType<IAzureResourceService<AzureResourceDatabaseServer>>();
|
||||
mockDatabaseServerService = TypeMoq.Mock.ofType<IAzureResourceService<azureResource.AzureResourceDatabaseServer>>();
|
||||
mockApiWrapper = TypeMoq.Mock.ofType<ApiWrapper>();
|
||||
mockExtensionContext = TypeMoq.Mock.ofType<vscode.ExtensionContext>();
|
||||
});
|
||||
@@ -97,7 +99,7 @@ describe('AzureResourceDatabaseServerTreeDataProvider.info', function (): void {
|
||||
|
||||
describe('AzureResourceDatabaseServerTreeDataProvider.getChildren', function (): void {
|
||||
beforeEach(() => {
|
||||
mockDatabaseServerService = TypeMoq.Mock.ofType<IAzureResourceService<AzureResourceDatabaseServer>>();
|
||||
mockDatabaseServerService = TypeMoq.Mock.ofType<IAzureResourceService<azureResource.AzureResourceDatabaseServer>>();
|
||||
mockApiWrapper = TypeMoq.Mock.ofType<ApiWrapper>();
|
||||
mockExtensionContext = TypeMoq.Mock.ofType<vscode.ExtensionContext>();
|
||||
|
||||
@@ -139,7 +141,7 @@ describe('AzureResourceDatabaseServerTreeDataProvider.getChildren', function ():
|
||||
should(child.account).equal(mockAccount);
|
||||
should(child.subscription).equal(mockSubscription);
|
||||
should(child.tenantId).equal(mockTenantId);
|
||||
should(child.treeItem.id).equal(`databaseServer_${databaseServer.name}`);
|
||||
should(child.treeItem.id).equal(`databaseServer_${databaseServer.id}`);
|
||||
should(child.treeItem.label).equal(databaseServer.name);
|
||||
should(child.treeItem.collapsibleState).equal(vscode.TreeItemCollapsibleState.Collapsed);
|
||||
should(child.treeItem.contextValue).equal(AzureResourceItemType.databaseServer);
|
||||
|
||||
Reference in New Issue
Block a user