Skip to content

Commit

Permalink
serviceconnector: Add database subtypes (#1581)
Browse files Browse the repository at this point in the history
* Add database subtypes

* Change switch case to group

* Requested change
  • Loading branch information
motm32 authored Sep 18, 2023
1 parent 386c874 commit 5d93609
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
5 changes: 5 additions & 0 deletions serviceconnector/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ export type TargetServiceType = {

export enum TargetServiceTypeName {
Storage = 'Storage',
MongoDB = 'MongoDB',
Cassandra = 'Cassandra',
Gremlin = 'Gremlin, Sql',
NoSQL = 'Sql',
Table = 'Table, Sql',
CosmosDB = 'Cosmos DB',
KeyVault = 'Key Vault',
}
Expand Down
10 changes: 9 additions & 1 deletion serviceconnector/src/createLinker/CosmosDBAccountListStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@ export interface DatabaseAccountJsonResponse {
id: string;
name: string;
kind: string;
properties: {
EnabledApiTypes: string;
}
}

export class CosmosDBAccountListStep extends AzureWizardPromptStep<ICreateLinkerContext>{
public async prompt(context: ICreateLinkerContext): Promise<void> {
const placeHolder: string = vscode.l10n.t('Select a database account');
const accounts = await getCosmosDBDatabaseAccounts(context);
context.databaseAccount = (await context.ui.showQuickPick(this.getPicks(accounts.value), { placeHolder })).data;
const filteredAccounts = filterDatabaseAccounts(accounts.value, context.targetServiceType?.type);
context.databaseAccount = (await context.ui.showQuickPick(this.getPicks(filteredAccounts), { placeHolder })).data;
}

public shouldPrompt(context: ICreateLinkerContext): boolean {
Expand All @@ -40,3 +44,7 @@ async function getCosmosDBDatabaseAccounts(context: ICreateLinkerContext): Promi
const url = `${context.environment.resourceManagerEndpointUrl}subscriptions/${context.subscriptionId}/providers/Microsoft.DocumentDB/databaseAccounts?api-version=2023-03-15`
return (<AzExtPipelineResponse>await sendRequestWithTimeout(context, { url, method: 'GET' }, 5000, context)).parsedBody as DatabaseJsonResponse;
}

function filterDatabaseAccounts(accounts: DatabaseAccountJsonResponse[], kind: string | undefined): DatabaseAccountJsonResponse[] {
return accounts.filter(a => a.properties.EnabledApiTypes === kind);
}
3 changes: 2 additions & 1 deletion serviceconnector/src/createLinker/ICreateLinkerContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import { AuthInfoBase, KnownClientType, LinkerResource } from "@azure/arm-servicelinker";
import { IStorageAccountWizardContext } from "@microsoft/vscode-azext-azureutils";
import { ExecuteActivityContext, ISubscriptionActionContext } from "@microsoft/vscode-azext-utils";
import { ExecuteActivityContext, IAzureQuickPickItem, ISubscriptionActionContext } from "@microsoft/vscode-azext-utils";
import { TargetServiceType } from "../../constants";
import { DatabaseAccountJsonResponse } from "./CosmosDBAccountListStep";
import { KeyVaultAccountJsonResponse } from "./KeyVaultListStep";
Expand All @@ -20,6 +20,7 @@ export interface ICreateLinkerContext extends ISubscriptionActionContext, IStora

//Target service
targetServiceType?: TargetServiceType;
targetService?: IAzureQuickPickItem<TargetServiceType>;
databaseAccount?: DatabaseAccountJsonResponse;
keyVaultAccount?: KeyVaultAccountJsonResponse;

Expand Down
2 changes: 1 addition & 1 deletion serviceconnector/src/createLinker/LinkerCreateStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class LinkerCreateStep extends AzureWizardExecuteStep<ICreateLinkerContex
}

private getSourceResourceId(context: ICreateLinkerContext): string {
switch (context.targetServiceType?.type) {
switch (context.targetService?.group) {
case TargetServiceTypeName.Storage:
return nonNullValue(context.storageAccount?.id);
case TargetServiceTypeName.CosmosDB:
Expand Down
11 changes: 8 additions & 3 deletions serviceconnector/src/createLinker/TargetServiceListStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@ export class TargetServiceListStep extends AzureWizardPromptStep<ICreateLinkerCo
{ label: vscode.l10n.t('Queue'), data: { name: "storageQueue", type: TargetServiceTypeName.Storage, id: '/queueServices/default' }, group: TargetServiceTypeName.Storage },
{ label: vscode.l10n.t('Table'), data: { name: "storageTable", type: TargetServiceTypeName.Storage, id: '/tableServices/default' }, group: TargetServiceTypeName.Storage },
{ label: vscode.l10n.t('File'), data: { name: "storageFile", type: TargetServiceTypeName.Storage, id: '/fileServices/default' }, group: TargetServiceTypeName.Storage },
{ label: vscode.l10n.t('CosmosDB'), data: { name: "cosmosDB", type: TargetServiceTypeName.CosmosDB, id: '/databases' }, group: TargetServiceTypeName.CosmosDB },
{ label: vscode.l10n.t('MongoDB'), data: { name: "mongodb", type: TargetServiceTypeName.MongoDB, id: '/databases' }, group: TargetServiceTypeName.CosmosDB },
{ label: vscode.l10n.t('Cassandra'), data: { name: "cassandra", type: TargetServiceTypeName.Cassandra, id: '/databases' }, group: TargetServiceTypeName.CosmosDB },
{ label: vscode.l10n.t('Apache Gremlin'), data: { name: "gremlin", type: TargetServiceTypeName.Gremlin, id: '/databases' }, group: TargetServiceTypeName.CosmosDB },
{ label: vscode.l10n.t('NoSQL'), data: { name: "sql", type: TargetServiceTypeName.NoSQL, id: '/databases' }, group: TargetServiceTypeName.CosmosDB },
{ label: vscode.l10n.t('Table'), data: { name: "table", type: TargetServiceTypeName.Table, id: '/databases' }, group: TargetServiceTypeName.CosmosDB },
{ label: vscode.l10n.t('Key Vault'), data: { name: "keyVault", type: TargetServiceTypeName.KeyVault, id: '/keyVault' }, group: TargetServiceTypeName.KeyVault },
];

context.targetServiceType = (await context.ui.showQuickPick(picks, { placeHolder, enableGrouping: true })).data
context.targetService = (await context.ui.showQuickPick(picks, { placeHolder, enableGrouping: true }));
context.targetServiceType = context.targetService.data;
}

public shouldPrompt(context: ICreateLinkerContext): boolean {
Expand All @@ -39,7 +44,7 @@ export class TargetServiceListStep extends AzureWizardPromptStep<ICreateLinkerCo
replication: StorageAccountReplication.LRS
};

switch (context.targetServiceType?.type) {
switch (context.targetService?.group) {
case TargetServiceTypeName.Storage:
promptSteps.push(new StorageAccountListStep(storageAccountCreateOptions));
break;
Expand Down

0 comments on commit 5d93609

Please sign in to comment.