-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathTargetPortInputStep.ts
More file actions
36 lines (31 loc) · 1.65 KB
/
TargetPortInputStep.ts
File metadata and controls
36 lines (31 loc) · 1.65 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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { AzureWizardPromptStep } from "@microsoft/vscode-azext-utils";
import { localize } from "../../../utils/localize";
import type { IngressContext } from "../IngressContext";
import { getDefaultPort } from "./getDefaultPort";
export class TargetPortInputStep extends AzureWizardPromptStep<IngressContext> {
public async prompt(context: IngressContext): Promise<void> {
context.targetPort = Number(await context.ui.showInputBox({
prompt: localize('targetPort', 'This is the port your container is listening on that will receive traffic. Set this value to the port number that your container uses.'),
value: String(getDefaultPort(context)),
validateInput: this.validateInput
}));
}
public shouldPrompt(context: IngressContext): boolean {
return !context.targetPort;
}
private validateInput(val: string): string | undefined {
const num = Number(val);
if (isNaN(num)) {
return localize('enterNumber', 'Enter a valid port number')
} else if (!Number.isInteger(num)) {
return localize('integersOnly', 'Enter only whole integer values');
} else if (num < 1 || num > 65535) {
return localize('portRange', 'Enter a number between 1-65535');
}
return undefined;
}
}