-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathTryUseExistingWorkspaceRegistryStep.ts
More file actions
66 lines (54 loc) · 3.46 KB
/
TryUseExistingWorkspaceRegistryStep.ts
File metadata and controls
66 lines (54 loc) · 3.46 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
/*---------------------------------------------------------------------------------------------
* 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 } from "@azure/arm-containerregistry";
import { AzureWizardExecuteStep, nonNullProp } from "@microsoft/vscode-azext-utils";
import { type Progress } from "vscode";
import { ext } from "../../../../../extensionVariables";
import { type SetTelemetryProps } from "../../../../../telemetry/SetTelemetryProps";
import { type DeployWorkspaceProjectTelemetryProps as TelemetryProps } from "../../../../../telemetry/deployWorkspaceProjectTelemetryProps";
import { localize } from "../../../../../utils/localize";
import { AcrListStep } from "../../../../image/imageSource/containerRegistry/acr/AcrListStep";
import { type DeploymentConfigurationSettings } from "../../../settings/DeployWorkspaceProjectSettingsV2";
import { dwpSettingUtilsV2 } from "../../../settings/dwpSettingUtilsV2";
import { type WorkspaceDeploymentConfigurationContext } from "../WorkspaceDeploymentConfigurationContext";
type TryUseExistingWorkspaceRegistryContext = WorkspaceDeploymentConfigurationContext & SetTelemetryProps<TelemetryProps>;
export class TryUseExistingWorkspaceRegistryStep<T extends TryUseExistingWorkspaceRegistryContext> extends AzureWizardExecuteStep<T> {
public priority: number = 220; /** Todo: Figure out a good priority level */
public async execute(context: T, progress: Progress<{ message?: string | undefined; increment?: number | undefined }>): Promise<void> {
const settings: DeploymentConfigurationSettings[] | undefined = await dwpSettingUtilsV2.getWorkspaceDeploymentConfigurations(nonNullProp(context, 'rootFolder'));
if (!settings?.length) {
return;
}
if (context.deploymentConfigurationSettings) {
// In the case where we were already verifying, it looks a little smoother if we keep the execution looking like a continuation of the previous step
progress.report({ message: localize(`verifyingContainerRegistry`, 'Verifying container registry') });
} else {
progress.report({ message: localize('searchingAvailableRegistries', 'Searching available registries...') });
}
const registries: Registry[] = await AcrListStep.getRegistries(context);
const registryMap: Map<string, Registry> = new Map();
for (const registry of registries) {
if (!registry.name) {
continue;
}
registryMap.set(registry.name, registry);
}
for (const setting of settings) {
if (!setting.containerRegistry) {
continue;
}
if (registryMap.has(setting.containerRegistry)) {
context.registry = registryMap.get(setting.containerRegistry);
context.telemetry.properties.defaultedRegistry = 'true';
ext.outputChannel.appendLog(localize('useExistingWorkspaceAcrSuccess', 'Searched workspace settings and found an existing container registry "{0}" to leverage.', context.registry?.name));
break;
}
}
context.telemetry.properties.defaultedRegistry = 'false';
}
public shouldExecute(context: T): boolean {
return !context.registry;
}
}