-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathIngressPromptStep.ts
More file actions
89 lines (73 loc) · 4.27 KB
/
IngressPromptStep.ts
File metadata and controls
89 lines (73 loc) · 4.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { AzureWizardPromptStep, type AzureWizardExecuteStep, type ConfirmationViewProperty, type IWizardOptions } from "@microsoft/vscode-azext-utils";
import { ext } from "../../extensionVariables";
import { localize } from "../../utils/localize";
import { type IngressContext } from "./IngressContext";
import { DisableIngressStep } from "./disableIngress/DisableIngressStep";
import { TargetPortInputStep } from "./editTargetPort/TargetPortInputStep";
import { getDefaultPort } from "./editTargetPort/getDefaultPort";
import { EnableIngressStep } from "./enableIngress/EnableIngressStep";
import { IngressVisibilityStep } from "./enableIngress/IngressVisibilityStep";
import { tryGetDockerfileExposePorts } from "./tryGetDockerfileExposePorts";
export class IngressPromptStep extends AzureWizardPromptStep<IngressContext> {
public async prompt(context: IngressContext): Promise<void> {
context.enableIngress = (await context.ui.showQuickPick([{ label: localize('enable', 'Enable'), data: true }, { label: localize('disable', 'Disable'), data: false }],
{ placeHolder: localize('enableIngress', 'Enable ingress for applications that need an HTTP endpoint.') })).data;
}
public async configureBeforePrompt(context: IngressContext): Promise<void> {
await tryConfigureIngressUsingDockerfile(context);
}
public shouldPrompt(context: IngressContext): boolean {
return context.enableIngress === undefined;
}
public confirmationViewProperty(context: IngressContext): ConfirmationViewProperty {
return {
name: localize('enableIngress', 'Ingress'),
value: context.enableIngress ? localize('enabled', 'Enabled') : localize('disabled', 'Disabled'),
contextPropertyName: 'enableIngress'
};
}
public async getSubWizard(context: IngressContext): Promise<IWizardOptions<IngressContext> | undefined> {
const promptSteps: AzureWizardPromptStep<IngressContext>[] = [];
const executeSteps: AzureWizardExecuteStep<IngressContext>[] = [];
if (context.enableIngress) {
promptSteps.push(new IngressVisibilityStep(), new TargetPortInputStep());
}
// Execute steps for amending existing container apps; skip if not yet created
if (context.containerApp) {
executeSteps.push(context.enableIngress ? new EnableIngressStep() : new DisableIngressStep());
}
context.telemetry.properties.enableIngress = context.enableIngress ? 'true' : 'false';
return { promptSteps, executeSteps };
}
}
export async function tryConfigureIngressUsingDockerfile(context: IngressContext): Promise<void> {
if (!context.dockerfilePath) {
return;
}
context.dockerfileExposePorts = await tryGetDockerfileExposePorts(context.dockerfilePath);
context.telemetry.properties.dockerfileExposePortRangeCount = context.dockerfileExposePorts ? String(context.dockerfileExposePorts.length) : '0';
if (context.alwaysPromptIngress) {
return;
}
if (context.dockerfileExposePorts) {
context.enableIngress = true;
context.enableExternal = context.containerApp?.configuration?.ingress?.external ?? true;
context.targetPort = getDefaultPort(context);
} else {
context.enableIngress = false;
context.enableExternal = false;
}
const currentExternalEnabled: boolean | undefined = context.containerApp?.configuration?.ingress?.external;
const currentTargetPort: number | undefined = context.containerApp?.configuration?.ingress?.targetPort;
if (currentExternalEnabled === context.enableExternal && currentTargetPort === context.targetPort) {
return;
}
ext.outputChannel.appendLog(context.enableIngress ?
localize('ingressEnabledLabel', 'Detected ingress on port {0} using Dockerfile configuration.', context.targetPort) :
localize('ingressDisabledLabel', 'Detected no ingress using Dockerfile configuration.')
);
}