-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathManagedEnvironmentCreateStep.ts
More file actions
60 lines (51 loc) · 3.28 KB
/
ManagedEnvironmentCreateStep.ts
File metadata and controls
60 lines (51 loc) · 3.28 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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { ContainerAppsAPIClient } from "@azure/arm-appcontainers";
import { getResourceGroupFromId, LocationListStep } from "@microsoft/vscode-azext-azureutils";
import { AzureWizardExecuteStep } from "@microsoft/vscode-azext-utils";
import { Progress } from "vscode";
import { managedEnvironmentsAppProvider } from "../../constants";
import { ext } from "../../extensionVariables";
import { createContainerAppsAPIClient, createOperationalInsightsManagementClient } from '../../utils/azureClients';
import { localize } from "../../utils/localize";
import { nonNullProp, nonNullValueAndProp } from "../../utils/nonNull";
import { IManagedEnvironmentContext } from "./IManagedEnvironmentContext";
export class ManagedEnvironmentCreateStep extends AzureWizardExecuteStep<IManagedEnvironmentContext> {
public priority: number = 250;
public async execute(context: IManagedEnvironmentContext, progress: Progress<{ message?: string | undefined; increment?: number | undefined }>): Promise<void> {
const client: ContainerAppsAPIClient = await createContainerAppsAPIClient(context);
const opClient = await createOperationalInsightsManagementClient(context);
const rgName = nonNullValueAndProp(context.resourceGroup, 'name');
const logAnalyticsWorkspace = nonNullProp(context, 'logAnalyticsWorkspace');
const creatingKuEnv: string = localize('creatingManagedEnvironment', 'Creating new Container Apps environment "{0}"...', context.newManagedEnvironmentName);
progress.report({ message: creatingKuEnv });
ext.outputChannel.appendLog(creatingKuEnv);
const sharedKeys = await opClient.sharedKeysOperations.getSharedKeys(
getResourceGroupFromId(nonNullProp(logAnalyticsWorkspace, 'id')),
nonNullProp(logAnalyticsWorkspace, 'name'));
context.managedEnvironment = await client.managedEnvironments.beginCreateOrUpdateAndWait(rgName, nonNullProp(context, 'newManagedEnvironmentName'),
{
location: (await LocationListStep.getLocation(context)).name,
appLogsConfiguration: {
"destination": "log-analytics",
"logAnalyticsConfiguration": {
"customerId": nonNullProp(context, 'logAnalyticsWorkspace').customerId,
"sharedKey": sharedKeys.primarySharedKey
}
}
}
);
context.activityResult = {
id: nonNullProp(context.managedEnvironment, 'id'),
name: nonNullProp(context, 'newManagedEnvironmentName'),
type: managedEnvironmentsAppProvider
}
const createdKuEnv: string = localize('createKuEnv', 'Successfully created new Container Apps environment "{0}".', context.newManagedEnvironmentName);
ext.outputChannel.appendLog(createdKuEnv);
}
public shouldExecute(context: IManagedEnvironmentContext): boolean {
return !context.managedEnvironment;
}
}