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
79 changes: 36 additions & 43 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -406,9 +406,9 @@
"@azure/container-registry": "1.0.0-beta.5",
"@azure/core-rest-pipeline": "1.10.3",
"@azure/storage-blob": "^12.4.1",
"@microsoft/vscode-azext-azureutils": "^1.0.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": "^1.2.0",
"@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
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { AzureWizardPromptStep, IAzureQuickPickItem, nonNullValue } from "@micro
import { localize } from "../../utils/localize";
import { IServiceConnectorContext } from "./IServiceConnectorContext";

export class ContainerPickStep extends AzureWizardPromptStep<IServiceConnectorContext> {
export class ContainerListStep extends AzureWizardPromptStep<IServiceConnectorContext> {
public async prompt(context: IServiceConnectorContext): Promise<void> {
const placeHolder: string = localize('selectStream', 'Select a container');
const placeHolder: string = localize('selectContainer', 'Select a container');
context.scope = (await context.ui.showQuickPick(this.getPicks(context), { placeHolder })).data;
}

Expand All @@ -18,14 +18,14 @@ export class ContainerPickStep extends AzureWizardPromptStep<IServiceConnectorCo
}

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

private async getPicks(context: IServiceConnectorContext): Promise<IAzureQuickPickItem<string>[]> {
const containers = nonNullValue(context.containerApp.template?.containers);
private getPicks(context: IServiceConnectorContext): IAzureQuickPickItem<string>[] {
const containers = nonNullValue(context.containerApp?.template?.containers);
return containers.map(c => {
return {
label: nonNullValue(c.name),
Expand Down
5 changes: 2 additions & 3 deletions src/commands/serviceConnector/IServiceConnectorContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
*--------------------------------------------------------------------------------------------*/

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

export interface IServiceConnectorContext extends ICreateLinkerContext {
containerApp: ContainerAppModel;
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 🙂).

}
4 changes: 2 additions & 2 deletions src/commands/serviceConnector/createServiceConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ 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 { ContainerListStep } from "./ContainerListStep";
import { IServiceConnectorContext } from "./IServiceConnectorContext";

export async function createServiceConnector(context: ICreateLinkerContext, item?: ContainerAppItem): Promise<void> {
Expand All @@ -24,7 +24,7 @@ export async function createServiceConnector(context: ICreateLinkerContext, item
}

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

await createLinker(activityContext, { id: containerApp.id, subscription }, promptSteps);
Expand Down
4 changes: 2 additions & 2 deletions src/commands/serviceConnector/deleteServiceConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ 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 { ContainerListStep } from "./ContainerListStep";
import { IServiceConnectorContext } from "./IServiceConnectorContext";


Expand All @@ -25,7 +25,7 @@ export async function deleteServiceConnector(context: ICreateLinkerContext, item
}

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

await deleteLinker(activityContext, { id: containerApp.id, subscription }, promptSteps);
Expand Down
4 changes: 2 additions & 2 deletions src/commands/serviceConnector/validateServiceConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ 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 { ContainerListStep } from "./ContainerListStep";
import { IServiceConnectorContext } from "./IServiceConnectorContext";

export async function validateServiceConnector(context: ICreateLinkerContext, item?: ContainerAppItem): Promise<void> {
Expand All @@ -24,7 +24,7 @@ export async function validateServiceConnector(context: ICreateLinkerContext, it
}

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

await validateLinker(activityContext, { id: containerApp.id, subscription }, promptSteps);
Expand Down
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