mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-15 02:48:30 -05:00
Add support for CosmosDB - Mongo API (#19386)
* Display cdb nodes to browse azure tree * Update icons * Update node label * Remove console logs * Fix i18n in cosmosDbMongoTreeDataProvider * Disable Mongo provider in azure tree for now * Revert "Disable Mongo provider in azure tree for now" This reverts commit 8b2d2079f43624596a41b82a71a5e40eef1ad4b1. * Fix build issues related to merge * Add COSMOSDB_MONGO in provider extension map * Define providerId string as constant. Rename constants to follow azurecore/ naming conventions (all caps)
This commit is contained in:
@@ -16,6 +16,7 @@ export enum AzureResourceItemType {
|
||||
message = 'azure.resource.itemType.message',
|
||||
azureMonitor = 'azure.resource.itemType.azureMonitor',
|
||||
azureMonitorContainer = 'azure.resource.itemType.azureMonitorContainer',
|
||||
cosmosDBMongoAccount = 'azure.resource.itemType.cosmosDBMongoAccount'
|
||||
}
|
||||
|
||||
export enum AzureResourceServiceNames {
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { ExtensionContext } from 'vscode';
|
||||
|
||||
import { azureResource } from 'azurecore';
|
||||
import { IAzureResourceService } from '../../../interfaces';
|
||||
import { CosmosDbMongoTreeDataProvider } from './cosmosDbMongoTreeDataProvider';
|
||||
|
||||
export class CosmosDbMongoProvider implements azureResource.IAzureResourceProvider {
|
||||
public constructor(
|
||||
private _databaseServerService: IAzureResourceService<azureResource.AzureResourceDatabaseServer>,
|
||||
private _extensionContext: ExtensionContext
|
||||
) {
|
||||
}
|
||||
|
||||
public getTreeDataProvider(): azureResource.IAzureResourceTreeDataProvider {
|
||||
return new CosmosDbMongoTreeDataProvider(this._databaseServerService, this._extensionContext);
|
||||
}
|
||||
|
||||
public get providerId(): string {
|
||||
return 'azure.resource.providers.cosmosDbMongo';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
import { ResourceServiceBase, GraphData } from '../../resourceTreeDataProviderBase';
|
||||
import { azureResource } from 'azurecore';
|
||||
|
||||
|
||||
interface DbServerGraphData extends GraphData {
|
||||
properties: {
|
||||
fullyQualifiedDomainName: string;
|
||||
administratorLogin: string;
|
||||
};
|
||||
}
|
||||
|
||||
const serversQuery = `where type == "${azureResource.AzureResourceType.cosmosDbAccount}" and kind == "MongoDB"`;
|
||||
|
||||
export class CosmosDbMongoService extends ResourceServiceBase<DbServerGraphData, azureResource.AzureResourceDatabaseServer> {
|
||||
|
||||
protected get query(): string {
|
||||
return serversQuery;
|
||||
}
|
||||
|
||||
protected convertResource(resource: DbServerGraphData): azureResource.AzureResourceDatabaseServer {
|
||||
return {
|
||||
id: resource.id,
|
||||
name: resource.name,
|
||||
fullName: resource.properties.fullyQualifiedDomainName,
|
||||
loginName: resource.properties.administratorLogin,
|
||||
defaultDatabaseName: '',
|
||||
tenant: resource.tenantId,
|
||||
subscription: {
|
||||
id: resource.subscriptionId,
|
||||
name: resource.subscriptionName
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { TreeItemCollapsibleState, ExtensionContext } from 'vscode';
|
||||
import * as nls from 'vscode-nls';
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
import { AzureResourceItemType } from '../../../constants';
|
||||
import { generateGuid } from '../../../utils';
|
||||
import { IAzureResourceService } from '../../../interfaces';
|
||||
import { ResourceTreeDataProviderBase } from '../../resourceTreeDataProviderBase';
|
||||
import { azureResource } from 'azurecore';
|
||||
import * as azdata from 'azdata';
|
||||
|
||||
export class CosmosDbMongoTreeDataProvider extends ResourceTreeDataProviderBase<azureResource.AzureResourceDatabaseServer> {
|
||||
private static readonly COSMOSDG_MONGO_PROVIDER_ID = 'COSMOSDB_MONGO';
|
||||
private static readonly CONTAINER_ID = 'azure.resource.providers.databaseServer.treeDataProvider.cosmosDbMongoContainer';
|
||||
private static readonly CONTAINER_LABEL = localize('azure.resource.providers.databaseServer.treeDataProvider.cosmosDbMongoContainerLabel', "CosmosDB for Mongo");
|
||||
|
||||
public constructor(
|
||||
databaseServerService: IAzureResourceService<azureResource.AzureResourceDatabaseServer>,
|
||||
private _extensionContext: ExtensionContext
|
||||
) {
|
||||
super(databaseServerService);
|
||||
}
|
||||
|
||||
protected getTreeItemForResource(databaseServer: azureResource.AzureResourceDatabaseServer, account: azdata.Account): azdata.TreeItem {
|
||||
return {
|
||||
id: `Cosmosdb_${databaseServer.id ? databaseServer.id : databaseServer.name}`,
|
||||
label: `${databaseServer.name} (CosmosDB Mongo API)`,
|
||||
iconPath: {
|
||||
dark: this._extensionContext.asAbsolutePath('resources/dark/cosmosdb_inverse.svg'),
|
||||
light: this._extensionContext.asAbsolutePath('resources/light/cosmosdb.svg')
|
||||
},
|
||||
collapsibleState: TreeItemCollapsibleState.None,
|
||||
contextValue: AzureResourceItemType.cosmosDBMongoAccount,
|
||||
payload: {
|
||||
id: generateGuid(),
|
||||
connectionName: databaseServer.name,
|
||||
serverName: databaseServer.name,
|
||||
userName: databaseServer.loginName,
|
||||
password: '',
|
||||
authenticationType: 'AzureMFA',
|
||||
savePassword: true,
|
||||
groupFullName: '',
|
||||
groupId: '',
|
||||
providerName: CosmosDbMongoTreeDataProvider.COSMOSDG_MONGO_PROVIDER_ID,
|
||||
saveProfile: false,
|
||||
options: {},
|
||||
azureAccount: account.key.accountId,
|
||||
azureTenantId: databaseServer.tenant,
|
||||
azureResourceId: databaseServer.id,
|
||||
azurePortalEndpoint: account.properties.providerSettings.settings.portalEndpoint
|
||||
},
|
||||
childProvider: CosmosDbMongoTreeDataProvider.COSMOSDG_MONGO_PROVIDER_ID,
|
||||
type: azdata.ExtensionNodeType.Server
|
||||
};
|
||||
}
|
||||
|
||||
protected createContainerNode(): azureResource.IAzureResourceNode {
|
||||
return {
|
||||
account: undefined,
|
||||
subscription: undefined,
|
||||
tenantId: undefined,
|
||||
treeItem: {
|
||||
id: CosmosDbMongoTreeDataProvider.CONTAINER_ID,
|
||||
label: CosmosDbMongoTreeDataProvider.CONTAINER_LABEL,
|
||||
iconPath: {
|
||||
dark: this._extensionContext.asAbsolutePath('resources/dark/folder_inverse.svg'),
|
||||
light: this._extensionContext.asAbsolutePath('resources/light/folder.svg')
|
||||
},
|
||||
collapsibleState: TreeItemCollapsibleState.Collapsed,
|
||||
contextValue: AzureResourceItemType.databaseServerContainer
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
3
extensions/azurecore/src/azurecore.d.ts
vendored
3
extensions/azurecore/src/azurecore.d.ts
vendored
@@ -345,7 +345,8 @@ declare module 'azurecore' {
|
||||
postgresServer = 'microsoft.dbforpostgresql/servers',
|
||||
azureArcService = 'microsoft.azuredata/datacontrollers',
|
||||
storageAccount = 'microsoft.storage/storageaccounts',
|
||||
logAnalytics = 'microsoft.operationalinsights/workspaces'
|
||||
logAnalytics = 'microsoft.operationalinsights/workspaces',
|
||||
cosmosDbAccount = 'microsoft.documentdb/databaseaccounts'
|
||||
}
|
||||
|
||||
export interface IAzureResourceProvider extends azdata.DataProvider {
|
||||
|
||||
@@ -37,6 +37,8 @@ import { SqlInstanceArcProvider } from './azureResource/providers/sqlinstanceArc
|
||||
import { SqlInstanceArcResourceService } from './azureResource/providers/sqlinstanceArc/sqlInstanceArcService';
|
||||
import { PostgresServerArcProvider } from './azureResource/providers/postgresArcServer/postgresServerProvider';
|
||||
import { PostgresServerArcService } from './azureResource/providers/postgresArcServer/postgresServerService';
|
||||
import { CosmosDbMongoProvider } from './azureResource/providers/cosmosdb/mongo/cosmosDbMongoProvider';
|
||||
import { CosmosDbMongoService } from './azureResource/providers/cosmosdb/mongo/cosmosDbMongoService';
|
||||
import * as azurecore from 'azurecore';
|
||||
import * as azureResourceUtils from './azureResource/utils';
|
||||
import * as utils from './utils';
|
||||
@@ -134,6 +136,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<azurec
|
||||
new AzureResourceDatabaseProvider(new AzureResourceDatabaseService(), extensionContext),
|
||||
new SqlInstanceProvider(new SqlInstanceResourceService(), extensionContext),
|
||||
new PostgresServerProvider(new PostgresServerService(), extensionContext),
|
||||
new CosmosDbMongoProvider(new CosmosDbMongoService(), extensionContext)
|
||||
];
|
||||
if (arcFeaturedEnabled) {
|
||||
providers.push(
|
||||
|
||||
Reference in New Issue
Block a user