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 2 commits
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
113 changes: 83 additions & 30 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@5"
}
],
"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
36 changes: 36 additions & 0 deletions src/commands/serviceConnector/ContainerPickStep.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/

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

export class ContainerPickStep extends AzureWizardPromptStep<IServiceConnectorContext> {
Copy link
Member

Choose a reason for hiding this comment

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

Generally this is called a ListStep not a PickStep.

Though I get that there is already a ContainerListStep, I think we should rename things to be more explicit. The ContainerListStep today is technically the ReplicaContainerListStep and has a hard requirement of having a replica defined on the context (which happens in the previous step). So maybe just rename that one and then call this ContainerListStep or TemplateContainerListStep?

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 will rename the other one!

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;
}

public async configureBeforePrompt(context: IServiceConnectorContext): Promise<void> {
const picks = await this.getPicks(context);
if (picks.length === 1) {
context.scope = picks[0].data;
}
}

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)
}
})
}
}
11 changes: 11 additions & 0 deletions src/commands/serviceConnector/IServiceConnectorContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*---------------------------------------------------------------------------------------------
* 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 { 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.

}
31 changes: 31 additions & 0 deletions src/commands/serviceConnector/createServiceConnector.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*---------------------------------------------------------------------------------------------
* 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 { AzureWizardPromptStep } 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 createServiceConnector(context: ICreateLinkerContext, item?: ContainerAppItem): Promise<void> {
item ??= await pickContainerApp(context);
const { subscription, containerApp } = item;

const activityContext = {
...context,
...await createActivityContext(),
containerApp: containerApp,
activityTitle: localize('createServiceConnector', 'Create Service Connector'),
}

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

await createLinker(activityContext, { id: containerApp.id, subscription }, promptSteps);
}
Loading