-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy patheditContainer.ts
More file actions
70 lines (62 loc) · 3.59 KB
/
editContainer.ts
File metadata and controls
70 lines (62 loc) · 3.59 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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { type Revision } from "@azure/arm-appcontainers";
import { AzureWizard, createSubscriptionContext, type IActionContext, type ISubscriptionContext } from "@microsoft/vscode-azext-utils";
import { type ContainerAppModel } from "../../tree/ContainerAppItem";
import { type ContainerItem } from "../../tree/containers/ContainerItem";
import { ContainersItem } from "../../tree/containers/ContainersItem";
import { createActivityContext } from "../../utils/activityUtils";
import { getManagedEnvironmentFromContainerApp } from "../../utils/getResourceUtils";
import { getVerifyProvidersStep } from "../../utils/getVerifyProvidersStep";
import { localize } from "../../utils/localize";
import { pickContainer } from "../../utils/pickItem/pickContainer";
import { getParentResourceFromItem, isTemplateItemEditable, TemplateItemNotEditableError } from "../../utils/revisionDraftUtils";
import { ImageSourceListStep } from "../image/imageSource/ImageSourceListStep";
import { RevisionDraftDeployPromptStep } from "../revisionDraft/RevisionDraftDeployPromptStep";
import { type ContainerEditContext } from "./ContainerEditContext";
import { ContainerEditDraftStep } from "./ContainerEditDraftStep";
import { RegistryAndSecretsUpdateStep } from "./RegistryAndSecretsUpdateStep";
// Edits both the 'image' and 'environmentVariables' portion of the container profile (draft)
export async function editContainer(context: IActionContext, node?: ContainersItem | ContainerItem): Promise<void> {
const item: ContainerItem | ContainersItem = node ?? await pickContainer(context, { autoSelectDraft: true });
const { containerApp, subscription } = item;
if (!isTemplateItemEditable(item)) {
throw new TemplateItemNotEditableError(item);
}
const subscriptionContext: ISubscriptionContext = createSubscriptionContext(subscription);
const parentResource: ContainerAppModel | Revision = getParentResourceFromItem(item);
let containersIdx: number;
if (ContainersItem.isContainersItem(item)) {
// The 'editContainer' command should only show up on a 'ContainersItem' when it only has one container, else the command would show up on the 'ContainerItem'
containersIdx = 0;
} else {
containersIdx = item.containersIdx;
}
const wizardContext: ContainerEditContext = {
...context,
...subscriptionContext,
...await createActivityContext(true),
subscription,
managedEnvironment: await getManagedEnvironmentFromContainerApp({ ...context, ...subscriptionContext }, containerApp),
containerApp,
containersIdx,
};
wizardContext.telemetry.properties.revisionMode = containerApp.revisionsMode;
const wizard: AzureWizard<ContainerEditContext> = new AzureWizard(wizardContext, {
title: localize('editContainer', 'Edit container profile for container app "{0}" (draft)', parentResource.name),
promptSteps: [
new ImageSourceListStep(),
new RevisionDraftDeployPromptStep(),
],
executeSteps: [
getVerifyProvidersStep<ContainerEditContext>(),
new RegistryAndSecretsUpdateStep(),
new ContainerEditDraftStep(item),
],
showLoadingPrompt: true,
});
await wizard.prompt();
await wizard.execute();
}