-
Notifications
You must be signed in to change notification settings - Fork 149
Expand file tree
/
Copy pathLocalSettingsAddStep.ts
More file actions
42 lines (38 loc) · 2.45 KB
/
LocalSettingsAddStep.ts
File metadata and controls
42 lines (38 loc) · 2.45 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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { activitySuccessContext, activitySuccessIcon, AzExtFsExtra, AzureWizardExecuteStep, createUniversallyUniqueContextValue, GenericTreeItem, nonNullProp } from "@microsoft/vscode-azext-utils";
import { ext } from "../../extensionVariables";
import { localize } from "../../localize";
import { getLocalSettingsFile } from "../appSettings/localSettings/getLocalSettingsFile";
import { type AddMIConnectionsContext } from "./AddMIConnectionsContext";
import { getLocalSettingsJson } from "./ConnectionsListStep";
export class LocalSettingsAddStep extends AzureWizardExecuteStep<AddMIConnectionsContext> {
public priority: number = 125;
public async execute(context: AddMIConnectionsContext): Promise<void> {
// If right clicking on a connection we will have the connections to convert but not the local settings path
if (!context.localSettingsPath) {
const message: string = localize('selectLocalSettings', 'Select the local settings file to add connections to.');
context.localSettingsPath = await getLocalSettingsFile(context, message);
}
const localSettings = await getLocalSettingsJson(context, context.localSettingsPath);
if (localSettings.Values) {
for (const connection of nonNullProp(context, 'connectionsToAdd')) {
localSettings.Values[connection.name] = connection.value;
context.activityChildren?.push(
new GenericTreeItem(undefined, {
contextValue: createUniversallyUniqueContextValue(['useExistingResourceGroupInfoItem', activitySuccessContext]),
label: localize('addedLocalSetting', 'Add Local setting "{0}"', connection.name),
iconPath: activitySuccessIcon
})
);
}
await AzExtFsExtra.writeJSON(nonNullProp(context, 'localSettingsPath'), localSettings);
await ext.rgApi.workspaceResourceTree.refresh(context);
}
}
public shouldExecute(context: AddMIConnectionsContext): boolean {
return !context.functionapp && !!context.connections
}
}