-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathStartingResourcesLogStep.ts
More file actions
95 lines (82 loc) · 4.34 KB
/
StartingResourcesLogStep.ts
File metadata and controls
95 lines (82 loc) · 4.34 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { type ContainerApp, type ManagedEnvironment } from "@azure/arm-appcontainers";
import { type ResourceGroup } from "@azure/arm-resources";
import { LocationListStep, type ILocationWizardContext } from "@microsoft/vscode-azext-azureutils";
import { ActivityChildItem, ActivityChildType, activityInfoIcon, AzureWizardPromptStep, createContextValue, type ExecuteActivityContext, type IActionContext } from "@microsoft/vscode-azext-utils";
import { activityInfoContext } from "../constants";
import { ext } from "../extensionVariables";
import { localize } from "../utils/localize";
type StartingResourcesLogContext = IActionContext & Partial<ExecuteActivityContext> & ILocationWizardContext & {
resourceGroup?: ResourceGroup,
managedEnvironment?: ManagedEnvironment,
containerApp?: ContainerApp
};
const startingResourcesContext: string = 'startingResourcesLogStepItem';
/**
* Use to display primary Azure resource data to the output and activity log
* i.e. resource group, managed environment, container app, location
*/
export class StartingResourcesLogStep<T extends StartingResourcesLogContext> extends AzureWizardPromptStep<T> {
public hideStepCount: boolean = true;
protected hasLogged: boolean = false;
/**
* Implement if you require additional context loading before resource logging
*/
protected configureStartingResources?(context: T): void | Promise<void>;
public async configureBeforePrompt(context: T): Promise<void> {
if (this.hasLogged) {
return;
}
await this.configureStartingResources?.(context);
await this.logStartingResources(context);
}
public async prompt(): Promise<void> {
// Don't prompt, just use to log starting resources
}
public shouldPrompt(): boolean {
return false;
}
protected async logStartingResources(context: T): Promise<void> {
if (context.resourceGroup) {
context.activityChildren?.push(
new ActivityChildItem({
contextValue: createContextValue([startingResourcesContext, activityInfoContext]),
label: localize('useResourceGroup', 'Use resource group "{0}"', context.resourceGroup.name),
activityType: ActivityChildType.Info,
iconPath: activityInfoIcon
})
);
ext.outputChannel.appendLog(localize('usingResourceGroup', 'Using resource group "{0}".', context.resourceGroup.name));
}
if (context.managedEnvironment) {
context.activityChildren?.push(
new ActivityChildItem({
label: localize('useManagedEnvironment', 'Use managed environment "{0}"', context.managedEnvironment.name),
contextValue: createContextValue([startingResourcesContext, activityInfoContext]),
activityType: ActivityChildType.Info,
iconPath: activityInfoIcon
}),
);
ext.outputChannel.appendLog(localize('usingManagedEnvironment', 'Using managed environment "{0}".', context.managedEnvironment.name));
}
if (context.containerApp) {
context.activityChildren?.push(
new ActivityChildItem({
label: localize('useContainerApp', 'Use container app "{0}"', context.containerApp.name),
contextValue: createContextValue([startingResourcesContext, activityInfoContext]),
activityType: ActivityChildType.Info,
iconPath: activityInfoIcon,
}),
);
ext.outputChannel.appendLog(localize('usingContainerApp', 'Using container app "{0}".', context.containerApp.name));
}
if (LocationListStep.hasLocation(context)) {
const location: string = (await LocationListStep.getLocation(context)).name;
ext.outputChannel.appendLog(localize('usingLocation', 'Using location: "{0}".', location));
}
this.hasLogged = true;
}
}