-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathManagedEnvironmentCreateStep.ts
More file actions
89 lines (78 loc) · 4.78 KB
/
ManagedEnvironmentCreateStep.ts
File metadata and controls
89 lines (78 loc) · 4.78 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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { type ContainerAppsAPIClient } from "@azure/arm-appcontainers";
import { getResourceGroupFromId, LocationListStep } from "@microsoft/vscode-azext-azureutils";
import { activityFailContext, activityFailIcon, activitySuccessContext, activitySuccessIcon, GenericTreeItem } from "@microsoft/vscode-azext-utils";
import { type Progress } from "vscode";
import { managedEnvironmentsAppProvider } from "../../constants";
import { createActivityChildContext } from "../../utils/activity/activityUtils";
import { ExecuteActivityOutputStepBase, type ExecuteActivityOutput } from "../../utils/activity/ExecuteActivityOutputStepBase";
import { createContainerAppsAPIClient, createOperationalInsightsManagementClient } from '../../utils/azureClients';
import { localize } from "../../utils/localize";
import { nonNullProp, nonNullValueAndProp } from "../../utils/nonNull";
import { type IManagedEnvironmentContext } from "./IManagedEnvironmentContext";
export class ManagedEnvironmentCreateStep extends ExecuteActivityOutputStepBase<IManagedEnvironmentContext> {
public priority: number = 250;
protected async executeCore(context: IManagedEnvironmentContext, progress: Progress<{ message?: string | undefined; increment?: number | undefined }>): Promise<void> {
const client: ContainerAppsAPIClient = await createContainerAppsAPIClient(context);
const opClient = await createOperationalInsightsManagementClient(context);
const resourceGroupName = nonNullValueAndProp(context.resourceGroup, 'name');
const managedEnvironmentName = nonNullProp(context, 'newManagedEnvironmentName');
const logAnalyticsWorkspace = nonNullProp(context, 'logAnalyticsWorkspace');
const creating: string = localize('creatingManagedEnvironment', 'Creating environment...');
progress.report({ message: creating });
const sharedKeys = await opClient.sharedKeysOperations.getSharedKeys(
getResourceGroupFromId(nonNullProp(logAnalyticsWorkspace, 'id')),
nonNullProp(logAnalyticsWorkspace, 'name'));
context.managedEnvironment = await client.managedEnvironments.beginCreateOrUpdateAndWait(resourceGroupName, managedEnvironmentName,
{
location: (await LocationListStep.getLocation(context)).name,
appLogsConfiguration: {
"destination": "log-analytics",
"logAnalyticsConfiguration": {
"customerId": logAnalyticsWorkspace.customerId,
"sharedKey": sharedKeys.primarySharedKey
}
},
workloadProfiles: [
{
name: "Consumption",
workloadProfileType: "Consumption"
}
]
}
);
if (!context.activityChildren) {
context.activityResult = {
id: nonNullProp(context.managedEnvironment, 'id'),
name: managedEnvironmentName,
type: managedEnvironmentsAppProvider
};
}
}
public shouldExecute(context: IManagedEnvironmentContext): boolean {
return !context.managedEnvironment;
}
protected createSuccessOutput(context: IManagedEnvironmentContext): ExecuteActivityOutput {
return {
item: new GenericTreeItem(undefined, {
contextValue: createActivityChildContext(['managedEnvironmentCreateStep', activitySuccessContext]),
label: localize('createManagedEnvironment', 'Create container apps environment "{0}"', context.newManagedEnvironmentName),
iconPath: activitySuccessIcon
}),
message: localize('createdManagedEnvironmentSuccess', 'Created container apps environment "{0}".', context.newManagedEnvironmentName)
};
}
protected createFailOutput(context: IManagedEnvironmentContext): ExecuteActivityOutput {
return {
item: new GenericTreeItem(undefined, {
contextValue: createActivityChildContext(['managedEnvironmentCreateStep', activityFailContext]),
label: localize('createManagedEnvironment', 'Create container apps environment "{0}"', context.newManagedEnvironmentName),
iconPath: activityFailIcon
}),
message: localize('createdManagedEnvironmentFail', 'Failed to create container apps environment "{0}".', context.newManagedEnvironmentName)
};
}
}