-
Notifications
You must be signed in to change notification settings - Fork 517
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Back
createAzureRegistry
command (#4029)
* adjusted scheduleRunReuqest to work with new registries tree * delete azure repository command implementation * actually added back delete azure repository * added back delete Azure Registry command * changed registry tree util file name to be more general * added openInAzurePortalCommand * added back create azure registry command * move createAzureClient to azureUtils
- Loading branch information
Showing
12 changed files
with
211 additions
and
43 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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
58 changes: 58 additions & 0 deletions
58
src/tree/registries/Azure/createWizard/AzureRegistryCreateStep.ts
This file contains 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,58 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import type { AzExtLocation } from '@microsoft/vscode-azext-azureutils'; | ||
import { AzureWizardExecuteStep, nonNullProp, parseError } from '@microsoft/vscode-azext-utils'; | ||
import { Progress, l10n } from 'vscode'; | ||
import { ext } from '../../../../extensionVariables'; | ||
import { createAzureContainerRegistryClient } from '../../../../utils/azureUtils'; | ||
import { getAzExtAzureUtils } from '../../../../utils/lazyPackages'; | ||
import { IAzureRegistryWizardContext } from './IAzureRegistryWizardContext'; | ||
|
||
export class AzureRegistryCreateStep extends AzureWizardExecuteStep<IAzureRegistryWizardContext> { | ||
public priority: number = 130; | ||
|
||
public async execute(context: IAzureRegistryWizardContext, progress: Progress<{ message?: string; increment?: number }>): Promise<void> { | ||
const newRegistryName = nonNullProp(context, 'newRegistryName'); | ||
|
||
const client = await createAzureContainerRegistryClient(context.azureSubscription); | ||
|
||
const azExtAzureUtils = await getAzExtAzureUtils(); | ||
const creating: string = l10n.t('Creating registry "{0}"...', newRegistryName); | ||
ext.outputChannel.info(creating); | ||
progress.report({ message: creating }); | ||
|
||
const location: AzExtLocation = await azExtAzureUtils.LocationListStep.getLocation(context); | ||
const locationName: string = nonNullProp(location, 'name'); | ||
const resourceGroup = nonNullProp(context, 'resourceGroup'); | ||
try { | ||
context.registry = await client.registries.beginCreateAndWait( | ||
nonNullProp(resourceGroup, 'name'), | ||
newRegistryName, | ||
{ | ||
sku: { | ||
name: nonNullProp(context, 'newRegistrySku') | ||
}, | ||
location: locationName | ||
} | ||
); | ||
} | ||
catch (err) { | ||
const parsedError = parseError(err); | ||
if (parsedError.errorType === 'MissingSubscriptionRegistration') { | ||
context.errorHandling.suppressReportIssue = true; | ||
} | ||
|
||
throw err; | ||
} | ||
|
||
const created = l10n.t('Successfully created registry "{0}".', newRegistryName); | ||
ext.outputChannel.info(created); | ||
} | ||
|
||
public shouldExecute(context: IAzureRegistryWizardContext): boolean { | ||
return !context.registry; | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/tree/registries/Azure/createWizard/AzureRegistryNameStep.ts
This file contains 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,50 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import type { ContainerRegistryManagementClient } from '@azure/arm-containerregistry'; // These are only dev-time imports so don't need to be lazy | ||
import { AzureNameStep } from '@microsoft/vscode-azext-utils'; | ||
import { l10n } from 'vscode'; | ||
import { getArmContainerRegistry, getAzExtAzureUtils } from '../../../../utils/lazyPackages'; | ||
import { IAzureRegistryWizardContext } from './IAzureRegistryWizardContext'; | ||
|
||
export class AzureRegistryNameStep extends AzureNameStep<IAzureRegistryWizardContext> { | ||
protected async isRelatedNameAvailable(context: IAzureRegistryWizardContext, name: string): Promise<boolean> { | ||
const azExtAzureUtils = await getAzExtAzureUtils(); | ||
return await azExtAzureUtils.ResourceGroupListStep.isNameAvailable(context, name); | ||
} | ||
|
||
public async prompt(context: IAzureRegistryWizardContext): Promise<void> { | ||
const azExtAzureUtils = await getAzExtAzureUtils(); | ||
const armContainerRegistry = await getArmContainerRegistry(); | ||
const client = azExtAzureUtils.createAzureClient(context, armContainerRegistry.ContainerRegistryManagementClient); | ||
context.newRegistryName = (await context.ui.showInputBox({ | ||
placeHolder: l10n.t('Registry name'), | ||
prompt: l10n.t('Provide a registry name'), | ||
/* eslint-disable-next-line @typescript-eslint/promise-function-async */ | ||
validateInput: (name: string) => validateRegistryName(name, client) | ||
})).trim(); | ||
|
||
context.relatedNameTask = this.generateRelatedName(context, context.newRegistryName, azExtAzureUtils.resourceGroupNamingRules); | ||
} | ||
|
||
public shouldPrompt(context: IAzureRegistryWizardContext): boolean { | ||
return !context.newRegistryName; | ||
} | ||
} | ||
|
||
async function validateRegistryName(name: string, client: ContainerRegistryManagementClient): Promise<string | undefined> { | ||
name = name ? name.trim() : ''; | ||
|
||
const min = 5; | ||
const max = 50; | ||
if (name.length < min || name.length > max) { | ||
return l10n.t('The name must be between {0} and {1} characters.', min, max); | ||
} else if (name.match(/[^a-z0-9]/i)) { | ||
return l10n.t('The name can only contain alphanumeric characters.'); | ||
} else { | ||
const nameStatus = await client.registries.checkNameAvailability({ name, type: 'Microsoft.ContainerRegistry/registries' }); | ||
return nameStatus.message; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/tree/registries/Azure/createWizard/AzureRegistrySkuStep.ts
This file contains 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,23 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import type { SkuName as AcrSkuName } from '@azure/arm-containerregistry'; // These are only dev-time imports so don't need to be lazy | ||
import { AzureWizardPromptStep, IAzureQuickPickItem } from '@microsoft/vscode-azext-utils'; | ||
import { l10n } from 'vscode'; | ||
import { IAzureRegistryWizardContext } from './IAzureRegistryWizardContext'; | ||
|
||
export class AzureRegistrySkuStep extends AzureWizardPromptStep<IAzureRegistryWizardContext> { | ||
public async prompt(context: IAzureRegistryWizardContext): Promise<void> { | ||
const skus: AcrSkuName[] = ["Basic", "Standard", "Premium"]; | ||
const picks: IAzureQuickPickItem<AcrSkuName>[] = skus.map(s => { return { label: s, data: s }; }); | ||
|
||
const placeHolder: string = l10n.t('Select a SKU'); | ||
context.newRegistrySku = (await context.ui.showQuickPick(picks, { placeHolder })).data; | ||
} | ||
|
||
public shouldPrompt(context: IAzureRegistryWizardContext): boolean { | ||
return !context.newRegistrySku; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/tree/registries/Azure/createWizard/IAzureRegistryWizardContext.ts
This file contains 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,15 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import type { Registry as AcrRegistry, SkuName as AcrSkuName } from '@azure/arm-containerregistry'; // These are only dev-time imports so don't need to be lazy | ||
import { AzureSubscription } from '@microsoft/vscode-azext-azureauth'; | ||
import { IResourceGroupWizardContext } from '@microsoft/vscode-azext-azureutils'; | ||
|
||
export interface IAzureRegistryWizardContext extends IResourceGroupWizardContext { | ||
newRegistryName?: string; | ||
newRegistrySku?: AcrSkuName; | ||
registry?: AcrRegistry; | ||
readonly azureSubscription: AzureSubscription; | ||
} |
This file contains 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 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