-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathContainerRegistryListStep.ts
More file actions
71 lines (61 loc) · 3.8 KB
/
ContainerRegistryListStep.ts
File metadata and controls
71 lines (61 loc) · 3.8 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
/*---------------------------------------------------------------------------------------------
* 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 ConfirmationViewProperty, type IAzureQuickPickItem, type IWizardOptions } from "@microsoft/vscode-azext-utils";
import { UIKind, env } from "vscode";
import { acrDomain, dockerHubDomain, type SupportedRegistries } from "../../../../constants";
import { localize } from "../../../../utils/localize";
import { AcrListStep } from "./acr/AcrListStep";
import { AcrRepositoriesListStep } from "./acr/AcrRepositoriesListStep";
import { AcrTagListStep } from "./acr/AcrTagListStep";
import { type ContainerRegistryImageSourceContext } from "./ContainerRegistryImageSourceContext";
import { DockerHubContainerRepositoryListStep } from "./dockerHub/DockerHubContainerRepositoryListStep";
import { DockerHubContainerTagListStep } from "./dockerHub/DockerHubContainerTagListStep";
import { DockerHubNamespaceInputStep } from "./dockerHub/DockerHubNamespaceInputStep";
import { RegistryImageInputStep } from "./RegistryImageInputStep";
export class ContainerRegistryListStep extends AzureWizardPromptStep<ContainerRegistryImageSourceContext> {
public hideStepCount: boolean = true;
public pickLabel: string | undefined;
public async prompt(context: ContainerRegistryImageSourceContext): Promise<void> {
const placeHolder: string = localize('selectTag', 'Select a container registry');
const picks: IAzureQuickPickItem<SupportedRegistries | undefined>[] = [];
picks.push({ label: 'Azure Container Registry', data: acrDomain });
if (env.uiKind === UIKind.Desktop) {
// this will fails in vscode.dev due to browser CORS access policies
picks.push({ label: 'Docker Hub Registry', data: dockerHubDomain });
}
// there is a chance that this will fail in vscode.dev due to CORS, but we should still allow the user to enter a custom registry
picks.push({ label: localize('otherPublicRegistry', 'Other public registry'), data: undefined });
const pick: IAzureQuickPickItem<SupportedRegistries | undefined> | undefined = await context.ui.showQuickPick(picks, { placeHolder });
this.pickLabel = pick?.label;
context.registryDomain = pick.data;
}
public shouldPrompt(context: ContainerRegistryImageSourceContext): boolean {
return !context.image && !context.registryDomain;
}
public confirmationViewProperty(_context: ContainerRegistryImageSourceContext): ConfirmationViewProperty {
return {
name: localize('containerRegistryDomain', 'Container Registry Domain'),
value: this.pickLabel ?? '',
contextPropertyName: 'registryDomain'
};
}
public async getSubWizard(context: ContainerRegistryImageSourceContext): Promise<IWizardOptions<ContainerRegistryImageSourceContext> | undefined> {
if (context.image) {
return undefined;
}
const promptSteps: AzureWizardPromptStep<ContainerRegistryImageSourceContext>[] = [];
switch (context.registryDomain) {
case acrDomain:
promptSteps.push(new AcrListStep({ suppressCreate: true }), new AcrRepositoriesListStep(), new AcrTagListStep());
break;
case dockerHubDomain:
promptSteps.push(new DockerHubNamespaceInputStep(), new DockerHubContainerRepositoryListStep(), new DockerHubContainerTagListStep());
break;
default:
promptSteps.push(new RegistryImageInputStep());
}
return { promptSteps };
}
}