-
Notifications
You must be signed in to change notification settings - Fork 17
Add Create Azure Container Registry command #435
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/commands/deployImage/imageSource/containerRegistry/acr/createAcr/ICreateAcrContext.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Microsoft Corporation. All rights reserved. | ||
| * Licensed under the MIT License. See License.md in the project root for license information. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| import { KnownSkuName, Registry } from "@azure/arm-containerregistry"; | ||
| import { IResourceGroupWizardContext } from "@microsoft/vscode-azext-azureutils"; | ||
| import { ExecuteActivityContext } from "@microsoft/vscode-azext-utils"; | ||
|
|
||
| export interface ICreateAcrContext extends IResourceGroupWizardContext, ExecuteActivityContext { | ||
|
MicroFish91 marked this conversation as resolved.
Outdated
|
||
| newRegistryName?: string; | ||
| sku?: KnownSkuName; | ||
|
MicroFish91 marked this conversation as resolved.
Outdated
|
||
| registry?: Registry; | ||
| } | ||
|
MicroFish91 marked this conversation as resolved.
|
||
32 changes: 32 additions & 0 deletions
32
src/commands/deployImage/imageSource/containerRegistry/acr/createAcr/RegistryCreateStep.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 { ContainerRegistryManagementClient } from "@azure/arm-containerregistry"; | ||
| import { LocationListStep } from "@microsoft/vscode-azext-azureutils"; | ||
| import { AzureWizardExecuteStep, nonNullProp } from "@microsoft/vscode-azext-utils"; | ||
| import { createContainerRegistryManagementClient } from "../../../../../../utils/azureClients"; | ||
| import { ICreateAcrContext } from "./ICreateAcrContext"; | ||
|
|
||
| export class RegistryCreateStep extends AzureWizardExecuteStep<ICreateAcrContext> { | ||
| public priority: number = 150; | ||
|
|
||
| public async execute(context: ICreateAcrContext): Promise<void> { | ||
| const client: ContainerRegistryManagementClient = await createContainerRegistryManagementClient(context); | ||
|
|
||
| context.registry = await client.registries.beginCreateAndWait( | ||
| nonNullProp(context, 'newResourceGroupName'), | ||
| nonNullProp(context, 'newRegistryName'), | ||
| { | ||
| location: (await LocationListStep.getLocation(context)).name, | ||
| sku: { name: nonNullProp(context, 'sku') }, | ||
| adminUserEnabled: true | ||
| } | ||
| ); | ||
| } | ||
|
|
||
| public shouldExecute(context: ICreateAcrContext): boolean { | ||
| return !!context.newRegistryName && !!context.sku; | ||
| } | ||
| } |
47 changes: 47 additions & 0 deletions
47
src/commands/deployImage/imageSource/containerRegistry/acr/createAcr/RegistryNameStep.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * 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.newRegistryName = await context.ui.showInputBox({ | ||
| prompt: localize('registryName', 'Enter a name for the new registry'), | ||
| validateInput: this.validateInput, | ||
| asyncValidationTask: (value: string): Promise<string | undefined> => this.validateNameAvalability(context, value) | ||
| }); | ||
| } | ||
|
|
||
| public shouldPrompt(context: ICreateAcrContext): boolean { | ||
| return !context.newRegistryName; | ||
| } | ||
|
|
||
| private validateInput(name: string | undefined): string | undefined { | ||
| name = name ? name.trim() : ''; | ||
|
|
||
| const { minLength, maxLength } = { minLength: 5, maxLength: 50 }; | ||
| if (name.length < minLength || name.length > maxLength) { | ||
| return localize('validationLengthError', 'The name must be between {0} and {1} characters.', minLength, maxLength); | ||
| } else if (!/^[a-z][a-zA-Z0-9]*$/.test(name)) { | ||
| return localize('validateInputError', `Connection names can only consist of alphanumeric characters.`); | ||
| } | ||
|
|
||
| return undefined; | ||
| } | ||
|
|
||
| private async validateNameAvalability(context: ICreateAcrContext, name: string) { | ||
| 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; | ||
| } | ||
| } |
29 changes: 29 additions & 0 deletions
29
src/commands/deployImage/imageSource/containerRegistry/acr/createAcr/SkuListStep.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Microsoft Corporation. All rights reserved. | ||
| * Licensed under the MIT License. See License.md in the project root for license information. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| import { KnownSkuName } from "@azure/arm-containerregistry"; | ||
| import { AzureWizardPromptStep, IAzureQuickPickItem } from "@microsoft/vscode-azext-utils"; | ||
| import { localize } from "../../../../../../utils/localize"; | ||
| import { ICreateAcrContext } from "./ICreateAcrContext"; | ||
|
|
||
| export class SkuListStep extends AzureWizardPromptStep<ICreateAcrContext> { | ||
| public async prompt(context: ICreateAcrContext): Promise<void> { | ||
| const placeHolder: string = localize("sku", "Select a SKU"); | ||
| const picks: IAzureQuickPickItem<KnownSkuName>[] = [ | ||
| { label: "Basic", data: KnownSkuName.Basic }, | ||
|
MicroFish91 marked this conversation as resolved.
Outdated
|
||
| { label: "Standard", data: KnownSkuName.Standard }, | ||
| { label: "Premium", data: KnownSkuName.Premium }, | ||
| ]; | ||
|
|
||
| context.sku = (await context.ui.showQuickPick(picks, { | ||
| placeHolder, | ||
| suppressPersistence: true | ||
| })).data; | ||
| } | ||
|
|
||
| public shouldPrompt(context: ICreateAcrContext): boolean { | ||
| return !context.sku; | ||
| } | ||
| } | ||
54 changes: 54 additions & 0 deletions
54
src/commands/deployImage/imageSource/containerRegistry/acr/createAcr/createAcr.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Microsoft Corporation. All rights reserved. | ||
| * Licensed under the MIT License. See License.md in the project root for license information. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| import { LocationListStep, ResourceGroupCreateStep } from "@microsoft/vscode-azext-azureutils"; | ||
| import { AzureWizard, AzureWizardExecuteStep, AzureWizardPromptStep, IActionContext, createSubscriptionContext, nonNullValue, subscriptionExperience } from "@microsoft/vscode-azext-utils"; | ||
| import { AzureSubscription } from "@microsoft/vscode-azureresources-api"; | ||
| import { ext } from "../../../../../../extensionVariables"; | ||
| import { createActivityContext } from "../../../../../../utils/activityUtils"; | ||
| import { localize } from "../../../../../../utils/localize"; | ||
| import { ICreateAcrContext } from "./ICreateAcrContext"; | ||
| import { RegistryCreateStep } from "./RegistryCreateStep"; | ||
| import { RegistryNameStep } from "./RegistryNameStep"; | ||
| import { SkuListStep } from "./SkuListStep"; | ||
|
|
||
| export async function createAcr(context: IActionContext, node?: { subscription: AzureSubscription }): Promise<void> { | ||
| const subscription = node?.subscription ?? await subscriptionExperience(context, ext.rgApiV2.resources.azureResourceTreeDataProvider); | ||
|
|
||
| const wizardContext: ICreateAcrContext = { | ||
| ...context, | ||
| ...createSubscriptionContext(subscription), | ||
| ...(await createActivityContext()) | ||
| }; | ||
|
|
||
| const title: string = localize('createAcr', "Create container registry"); | ||
|
MicroFish91 marked this conversation as resolved.
Outdated
|
||
|
|
||
| const promptSteps: AzureWizardPromptStep<ICreateAcrContext>[] = [ | ||
| new RegistryNameStep(), | ||
| new SkuListStep(), | ||
| ]; | ||
|
|
||
| const executeSteps: AzureWizardExecuteStep<ICreateAcrContext>[] = [ | ||
| new ResourceGroupCreateStep(), | ||
|
MicroFish91 marked this conversation as resolved.
|
||
| new RegistryCreateStep(), | ||
| ]; | ||
|
|
||
| LocationListStep.addStep(wizardContext, promptSteps); | ||
|
|
||
|
|
||
| const wizard: AzureWizard<ICreateAcrContext> = new AzureWizard(wizardContext, { | ||
| title, | ||
| promptSteps, | ||
| executeSteps, | ||
| showLoadingPrompt: true | ||
| }); | ||
|
|
||
| await wizard.prompt(); | ||
|
|
||
| wizardContext.newResourceGroupName = nonNullValue(wizardContext.newRegistryName); | ||
| wizardContext.activityTitle = localize('createAcr', 'Create Azure Container Registry "{0}"', wizardContext.newRegistryName); | ||
|
|
||
| await wizard.execute(); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.