-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathRegistryNameStep.ts
More file actions
38 lines (33 loc) · 2.12 KB
/
RegistryNameStep.ts
File metadata and controls
38 lines (33 loc) · 2.12 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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { ContainerRegistryManagementClient, RegistryNameStatus } from "@azure/arm-containerregistry";
import { AzureWizardPromptStep } from "@microsoft/vscode-azext-utils";
import { createContainerRegistryManagementClient } from "../../../../../../utils/azureClients";
import { localize } from "../../../../../../utils/localize";
import { ICreateAcrContext } from "./ICreateAcrContext";
export class RegistryNameStep extends AzureWizardPromptStep<ICreateAcrContext> {
public async prompt(context: ICreateAcrContext): Promise<void> {
context.registryName = await context.ui.showInputBox({
prompt: localize('registryName', 'Enter a name for the new registry'),
validateInput: async (value: string | undefined): Promise<string | undefined> => await this.validateInput(context, value)
})
}
public shouldPrompt(context: ICreateAcrContext): boolean {
return !context.registryName;
}
private async validateInput(context: ICreateAcrContext, name: string | undefined): Promise<string | undefined> {
name = name ? name.trim() : '';
if (!/^[a-z][a-zA-Z0-9]*$/.test(name)) {
return localize('validateInputError', `Connection names can only consist of alphanumeric characters.`); //make it between 5 and 50 character
} else {
const client: ContainerRegistryManagementClient = await createContainerRegistryManagementClient(context);
const nameResponse: RegistryNameStatus = await client.registries.checkNameAvailability({ name: name, type: "Microsoft.ContainerRegistry/registries" });
if (nameResponse.nameAvailable === false) {
return localize('validateInputError', `The registry name ${name} is already in use.`);
}
}
return undefined;
}
}