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 3 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
168 changes: 107 additions & 61 deletions package-lock.json

Large diffs are not rendered by default.

37 changes: 34 additions & 3 deletions 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,10 +404,11 @@
"@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",
"@microsoft/vscode-azext-azureutils": "^1.0.1",
"@microsoft/vscode-azext-utils": "^1.2.0",
"@azure/storage-blob": "^12.4.1",
"@microsoft/vscode-azext-azureutils": "^2.0.0",
"@microsoft/vscode-azext-serviceconnector": "file:../vscode-azuretools/serviceconnector/microsoft-vscode-azext-serviceconnector-0.0.1.tgz",
"@microsoft/vscode-azext-utils": "^2.0.0",
"@microsoft/vscode-azureresources-api": "^2.0.2",
"@octokit/rest": "^18.5.2",
"buffer": "^6.0.3",
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..."
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { AzureWizardPromptStep, IAzureQuickPickItem, nonNullProp, nonNullValue }
import { localize } from "../../utils/localize";
import { IStreamLogsContext } from "./IStreamLogsContext";

export class ContainerListStep extends AzureWizardPromptStep<IStreamLogsContext> {
export class ReplicaContainerListStep extends AzureWizardPromptStep<IStreamLogsContext> {
public async prompt(context: IStreamLogsContext): Promise<void> {
const placeHolder: string = localize('selectContainer', 'Select a container');
context.container = (await context.ui.showQuickPick(this.getPicks(context), { placeHolder })).data;
Expand Down
4 changes: 2 additions & 2 deletions src/commands/logStream/startStreamingLogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { ContainerAppItem } from "../../tree/ContainerAppItem";
import { createActivityContext } from "../../utils/activityUtils";
import { localize } from "../../utils/localize";
import { pickContainerApp } from "../../utils/pickContainerApp";
import { ContainerListStep } from "./ContainerListStep";
import { IStreamLogsContext } from "./IStreamLogsContext";
import { ReplicaContainerListStep } from "./ReplicaContainerListStep";
import { ReplicaListStep } from "./ReplicaListStep";
import { RevisionListStep } from "./RevisionListStep";
import { logStreamRequest } from "./logStreamRequest";
Expand All @@ -35,7 +35,7 @@ export async function startStreamingLogs(context: IActionContext, item?: Pick<Co
const promptSteps: AzureWizardPromptStep<IStreamLogsContext>[] = [
new RevisionListStep(),
new ReplicaListStep(),
new ContainerListStep(),
new ReplicaContainerListStep(),
];

const wizard: AzureWizard<IStreamLogsContext> = new AzureWizard(wizardContext, {
Expand Down
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/ContainerListStep.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 ContainerListStep extends AzureWizardPromptStep<IServiceConnectorContext> {
public async prompt(context: IServiceConnectorContext): Promise<void> {
const placeHolder: string = localize('selectContainer', '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 = this.getPicks(context);
if (picks.length === 1) {
context.scope = picks[0].data;
}
}

private getPicks(context: IServiceConnectorContext): IAzureQuickPickItem<string>[] {
const containers = nonNullValue(context.containerApp?.template?.containers);
return containers.map(c => {
return {
label: nonNullValue(c.name),
data: nonNullValue(c.name)
}
})
}
}
10 changes: 10 additions & 0 deletions src/commands/serviceConnector/IServiceConnectorContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*---------------------------------------------------------------------------------------------
* 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 { IContainerAppContext } from "../createContainerApp/IContainerAppContext";

export interface IServiceConnectorContext extends ICreateLinkerContext, IContainerAppContext {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: A possible cleaner looking alternative (if you don't end up adding any properties):

export type IServiceConnectorContext = ICreateLinkerContext & IContainerAppContext;

On a side note, I'm more and more agreeing with Alex on not liking the I prefix for context interfaces/types (that's not a change request, more of just a general musing 🙂).

}
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 { ContainerListStep } from "./ContainerListStep";
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 ContainerListStep(),
];

await createLinker(activityContext, { id: containerApp.id, subscription }, promptSteps);
}
32 changes: 32 additions & 0 deletions src/commands/serviceConnector/deleteServiceConnector.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { ICreateLinkerContext, deleteLinker } 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 { ContainerListStep } from "./ContainerListStep";
import { IServiceConnectorContext } from "./IServiceConnectorContext";


export async function deleteServiceConnector(context: ICreateLinkerContext, item?: ContainerAppItem): Promise<void> {
item ??= await pickContainerApp(context);
const { subscription, containerApp } = item;

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

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

await deleteLinker(activityContext, { id: containerApp.id, subscription }, promptSteps);
}
31 changes: 31 additions & 0 deletions src/commands/serviceConnector/validateServiceConnector.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, validateLinker } 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 { ContainerListStep } from "./ContainerListStep";
import { IServiceConnectorContext } from "./IServiceConnectorContext";

export async function validateServiceConnector(context: ICreateLinkerContext, item?: ContainerAppItem): Promise<void> {
item ??= await pickContainerApp(context);
const { subscription, containerApp } = item;

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

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

await validateLinker(activityContext, { id: containerApp.id, subscription }, promptSteps);
}
2 changes: 0 additions & 2 deletions src/utils/azureClients.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ export function createContainerRegistryClient(context: AzExtClientContext, regis
const clientContext = parseClientContext(context);
// @azure/container-registry doesn't support ADAL tokens at all. If it sees `signRequest` is defined
// it errors, but we don't actually need `signRequest` because this is a T2 package
Copy link
Member

Choose a reason for hiding this comment

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

You can remove this comment now 😃

const credential = clientContext.credentials as { signRequest: unknown };
credential.signRequest = undefined;

return new ContainerRegistryClient(`https://${registry.loginServer}`, clientContext.credentials,
{ audience: KnownContainerRegistryAudience.AzureResourceManagerPublicCloud });
Expand Down