Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Service Connector #381

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 32 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,21 @@
"command": "containerApps.stopStreamingLogs",
"title": "%containerApps.stopStreamingLogs%",
"category": "Azure Container Apps"
},
{
"command": "containerApps.createServiceConnector",
"title": "%containerApps.createServiceConnector%",
"category": "Azure Container Apps"
},
{
"command": "containerApps.deleteServiceConnector",
"title": "%containerApps.deleteServiceConnector%",
"category": "Azure Container Apps"
},
{
"command": "containerApps.validateServiceConnector",
"title": "%containerApps.validateServiceConnector%",
"category": "Azure Container Apps"
}
],
"menus": {
Expand Down Expand Up @@ -277,6 +292,21 @@
"command": "containerApps.stopStreamingLogs",
"when": "view == azureResourceGroups && viewItem =~ /containerApp[^s]/i",
"group": "4@2"
},
{
"command": "containerApps.createServiceConnector",
"when": "view == azureResourceGroups && viewItem =~ /containerApp[^s]/i",
"group": "4@3"
},
{
"command": "containerApps.deleteServiceConnector",
"when": "view == azureResourceGroups && viewItem =~ /containerApp[^s]/i",
"group": "4@4"
},
{
"command": "containerApps.validateServiceConnector",
"when": "view == azureResourceGroups && viewItem =~ /containerApp[^s]/i",
"group": "4@4"
bwateratmsft marked this conversation as resolved.
Show resolved Hide resolved
}
],
"commandPalette": [
Expand Down Expand Up @@ -374,9 +404,10 @@
"@azure/arm-operationalinsights": "^8.0.0",
"@azure/arm-resources": "^5.0.1",
"@azure/container-registry": "1.0.0-beta.5",
"@azure/storage-blob": "^12.4.1",
"@azure/core-rest-pipeline": "1.10.3",
"@azure/storage-blob": "^12.4.1",
"@microsoft/vscode-azext-azureutils": "^1.0.1",
"@microsoft/vscode-azext-serviceconnector": "file:../vscode-azuretools/serviceconnector/microsoft-vscode-azext-serviceconnector-0.0.1.tgz",
"@microsoft/vscode-azext-utils": "^1.2.0",
"@microsoft/vscode-azureresources-api": "^2.0.2",
"@octokit/rest": "^18.5.2",
Expand Down
5 changes: 4 additions & 1 deletion package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,8 @@
"containerApps.addScaleRule": "Add Scale Rule...",
"containerApps.connectToGitHub": "Connect to GitHub Repository...",
"containerApps.startStreamingLogs": "Start Streaming Logs...",
"containerApps.stopStreamingLogs": "Stop Streaming Logs..."
"containerApps.stopStreamingLogs": "Stop Streaming Logs...",
"containerApps.createServiceConnector": "Create Service Connector...",
"containerApps.deleteServiceConnector": "Delete Service Connector...",
"containerApps.validateServiceConnector": "Validate Service Connector..."
}
8 changes: 8 additions & 0 deletions src/commands/registerCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ import { deactivateRevision } from './revisionCommands/deactivateRevision';
import { restartRevision } from './revisionCommands/restartRevision';
import { addScaleRule } from './scaling/addScaleRule/addScaleRule';
import { editScalingRange } from './scaling/editScalingRange';
import { createServiceConnector } from './serviceConnector/createServiceConnector';
import { deleteServiceConnector } from './serviceConnector/deleteServiceConnector';
import { validateServiceConnector } from './serviceConnector/validateServiceConnector';

export function registerCommands(): void {
// managed environments
Expand Down Expand Up @@ -62,6 +65,11 @@ export function registerCommands(): void {
registerCommandWithTreeNodeUnwrapping('containerApps.startStreamingLogs', startStreamingLogs);
registerCommandWithTreeNodeUnwrapping('containerApps.stopStreamingLogs', stopStreamingLogs);

// service connector
registerCommandWithTreeNodeUnwrapping('containerApps.createServiceConnector', createServiceConnector);
registerCommandWithTreeNodeUnwrapping('containerApps.deleteServiceConnector', deleteServiceConnector);
registerCommandWithTreeNodeUnwrapping('containerApps.validateServiceConnector', validateServiceConnector);

// Suppress "Report an Issue" button for all errors in favor of the command
registerErrorHandler(c => c.errorHandling.suppressReportIssue = true);
registerReportIssueCommand('containerApps.reportIssue');
Expand Down
26 changes: 26 additions & 0 deletions src/commands/serviceConnector/ContainerPickStep.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { AzureWizardPromptStep, IActionContext, IAzureQuickPickItem, nonNullValue } from "@microsoft/vscode-azext-utils";
import { localize } from "../../utils/localize";
import { IServiceConnectorContext } from "./IServiceConnectorContext";

export class ContainerPickStep extends AzureWizardPromptStep<IActionContext> {
bwateratmsft marked this conversation as resolved.
Show resolved Hide resolved
public async prompt(context: IServiceConnectorContext): Promise<void> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a note, you don't have to change it, adding public here is optional. TS assumes things are public by default.

I saw Phil H. doing this and I like it better because it shortens line widths and makes things a bit cleaner.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer keeping public to keep things explicit. Time for a cage match!

const placeHolder: string = localize('selectStream', 'Select a container');
context.scope = (await context.ui.showQuickPick(this.getPicks(context), { placeHolder })).data;
}

public shouldPrompt(context: IServiceConnectorContext): boolean {
return !context.scope
bwateratmsft marked this conversation as resolved.
Show resolved Hide resolved
}

private async getPicks(context: IServiceConnectorContext): Promise<IAzureQuickPickItem<string>[]> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't need to be async.

const containers = nonNullValue(context.containerApp.template?.containers);
return containers.map(c => {
return { label: nonNullValue(c.name), data: nonNullValue(c.name) }
bwateratmsft marked this conversation as resolved.
Show resolved Hide resolved
})
}
}
14 changes: 14 additions & 0 deletions src/commands/serviceConnector/IServiceConnectorContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { ICreateLinkerContext } from "@microsoft/vscode-azext-serviceconnector";
import { ExecuteActivityContext } from "@microsoft/vscode-azext-utils";
import { ContainerAppModel } from "../../tree/ContainerAppItem";

export interface IServiceConnectorContext extends ICreateLinkerContext {
containerApp: ContainerAppModel;
Copy link
Contributor

@MicroFish91 MicroFish91 Jun 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could extend from IContainerAppContext (on main branch) which includes the containerApp and subscription.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I extended from the ICreateLinkerContext since I needed the scope.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, IStreamLogsContext and IAddScaleRuleWizardContext could as well though IContainerAppContext has containerApp as an optional property. Not sure if that gunks things up a bit.

Copy link
Contributor

@MicroFish91 MicroFish91 Jun 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I extended from the ICreateLinkerContext since I needed the scope.

Is there a reason we shouldn't extend from both?

Yeah, IStreamLogsContext and IAddScaleRuleWizardContext could as well though IContainerAppContext has containerApp as an optional property. Not sure if that gunks things up a bit.

Yeah, there are a few contexts that probably still need to be migrated to extend from IContainerAppContext since it was only recently added. Scale rules is definitely one of those.

}

export type IServiceConnectorWithActivityContext = IServiceConnectorContext & ExecuteActivityContext;
43 changes: 43 additions & 0 deletions src/commands/serviceConnector/createServiceConnector.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { ICreateLinkerContext, createLinker } from "@microsoft/vscode-azext-serviceconnector";
import { AzureWizard, AzureWizardPromptStep, createSubscriptionContext, nonNullValue } from "@microsoft/vscode-azext-utils";
import { ContainerAppItem } from "../../tree/ContainerAppItem";
import { createActivityContext } from "../../utils/activityUtils";
import { localize } from "../../utils/localize";
import { pickContainerApp } from "../../utils/pickContainerApp";
import { ContainerPickStep } from "./ContainerPickStep";
import { IServiceConnectorWithActivityContext } from "./IServiceConnectorContext";

export async function createServiceConnector(context: ICreateLinkerContext, item?: ContainerAppItem): Promise<void> {
if (!item) {
item = await pickContainerApp(context);
}
bwateratmsft marked this conversation as resolved.
Show resolved Hide resolved
const { subscription, containerApp } = item;

const createServiceTitle: string = localize('createServiceConnector', 'Create Service Connector');
bwateratmsft marked this conversation as resolved.
Show resolved Hide resolved

const wizardContext: IServiceConnectorWithActivityContext = {
activityTitle: createServiceTitle,
...context,
...createSubscriptionContext(subscription),
containerApp: containerApp,
sourceResourceUri: containerApp.id,
...(await createActivityContext())
}

const promptSteps: AzureWizardPromptStep<IServiceConnectorWithActivityContext>[] = [
new ContainerPickStep(),
];

const wizard: AzureWizard<IServiceConnectorWithActivityContext> = new AzureWizard(wizardContext, {
title: localize('createServiceConnector', 'Create Service Connector'),
promptSteps,
});

await wizard.prompt();
await createLinker(wizardContext, nonNullValue(item));
bwateratmsft marked this conversation as resolved.
Show resolved Hide resolved
}
42 changes: 42 additions & 0 deletions src/commands/serviceConnector/deleteServiceConnector.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { deleteLinker } from "@microsoft/vscode-azext-serviceconnector";
import { AzureWizard, AzureWizardPromptStep, IActionContext, createSubscriptionContext } from "@microsoft/vscode-azext-utils";
import { ContainerAppItem } from "../../tree/ContainerAppItem";
import { createActivityContext } from "../../utils/activityUtils";
import { localize } from "../../utils/localize";
import { pickContainerApp } from "../../utils/pickContainerApp";
import { ContainerPickStep } from "./ContainerPickStep";
import { IServiceConnectorContext } from "./IServiceConnectorContext";


export async function deleteServiceConnector(context: IActionContext, item?: ContainerAppItem): Promise<void> {
if (!item) {
item = await pickContainerApp(context);
}
bwateratmsft marked this conversation as resolved.
Show resolved Hide resolved

const { subscription, containerApp } = item;

const wizardContext: IServiceConnectorContext = {
activityTitle: localize('deleteServiceConnector', 'Delete Service Connector'),
...context,
...createSubscriptionContext(subscription),
containerApp: containerApp,
...(await createActivityContext())
}

const promptSteps: AzureWizardPromptStep<IServiceConnectorContext>[] = [
new ContainerPickStep(),
];

const wizard: AzureWizard<IServiceConnectorContext> = new AzureWizard(wizardContext, {
title: localize('deleteServiceConnector', 'Delete Service Connector'),
promptSteps,
});

await wizard.prompt();
await deleteLinker(wizardContext, item);
}
41 changes: 41 additions & 0 deletions src/commands/serviceConnector/validateServiceConnector.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { validateLinker } from "@microsoft/vscode-azext-serviceconnector";
import { AzureWizard, AzureWizardPromptStep, IActionContext, createSubscriptionContext } from "@microsoft/vscode-azext-utils";
import { ContainerAppItem } from "../../tree/ContainerAppItem";
import { createActivityContext } from "../../utils/activityUtils";
import { localize } from "../../utils/localize";
import { pickContainerApp } from "../../utils/pickContainerApp";
import { ContainerPickStep } from "./ContainerPickStep";
import { IServiceConnectorWithActivityContext } from "./IServiceConnectorContext";

export async function validateServiceConnector(context: IActionContext, item?: ContainerAppItem): Promise<void> {
if (!item) {
item = await pickContainerApp(context);
}
bwateratmsft marked this conversation as resolved.
Show resolved Hide resolved

const { subscription, containerApp } = item;

const wizardContext: IServiceConnectorWithActivityContext = {
activityTitle: localize('createServiceConnector', 'Validate Service Connector'),
...context,
...createSubscriptionContext(subscription),
containerApp: containerApp,
...(await createActivityContext())
}

const promptSteps: AzureWizardPromptStep<IServiceConnectorWithActivityContext>[] = [
new ContainerPickStep(),
];

const wizard: AzureWizard<IServiceConnectorWithActivityContext> = new AzureWizard(wizardContext, {
title: localize('deleteServiceConnector', 'Delete Service Connector'),
bwateratmsft marked this conversation as resolved.
Show resolved Hide resolved
promptSteps,
});

await wizard.prompt();
await validateLinker(wizardContext, item);
}