|
| 1 | +/*--------------------------------------------------------------------------------------------- |
| 2 | +* Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | +* Licensed under the MIT License. See License.md in the project root for license information. |
| 4 | +*--------------------------------------------------------------------------------------------*/ |
| 5 | + |
| 6 | +import { type StringDictionary } from "@azure/arm-appservice"; |
| 7 | +import { type AppSettingsClientProvider, type IAppSettingsClient } from "@microsoft/vscode-azext-azureappsettings"; |
| 8 | +import { AzExtFsExtra, callWithTelemetryAndErrorHandling, type IActionContext } from "@microsoft/vscode-azext-utils"; |
| 9 | +import * as vscode from 'vscode'; |
| 10 | +import { type ILocalSettingsJson } from "../../../funcConfig/local.settings"; |
| 11 | +import { type LocalProjectTreeItem } from "../../../tree/localProject/LocalProjectTreeItem"; |
| 12 | +import { decryptLocalSettings } from "./decryptLocalSettings"; |
| 13 | +import { encryptLocalSettings } from "./encryptLocalSettings"; |
| 14 | +import { getLocalSettingsFileNoPrompt } from "./getLocalSettingsFile"; |
| 15 | + |
| 16 | +export class LocalSettingsClientProvider implements AppSettingsClientProvider { |
| 17 | + private _node: LocalProjectTreeItem; |
| 18 | + constructor(node: LocalProjectTreeItem) { |
| 19 | + this._node = node; |
| 20 | + } |
| 21 | + |
| 22 | + public async createClient(): Promise<IAppSettingsClient> { |
| 23 | + return new LocalSettingsClient(this._node); |
| 24 | + } |
| 25 | +} |
| 26 | + |
| 27 | +export class LocalSettingsClient implements IAppSettingsClient { |
| 28 | + public fullName: string; |
| 29 | + public isLinux: boolean; |
| 30 | + |
| 31 | + private _node: LocalProjectTreeItem; |
| 32 | + |
| 33 | + constructor(node: LocalProjectTreeItem) { |
| 34 | + this.isLinux = false; |
| 35 | + this._node = node; |
| 36 | + } |
| 37 | + |
| 38 | + public async listApplicationSettings(): Promise<StringDictionary> { |
| 39 | + const result = await callWithTelemetryAndErrorHandling<StringDictionary | undefined>('listApplicationSettings', async (context: IActionContext) => { |
| 40 | + const localSettingsPath: string | undefined = await getLocalSettingsFileNoPrompt(context, this._node.workspaceFolder); |
| 41 | + if (localSettingsPath === undefined) { |
| 42 | + return { properties: {} }; |
| 43 | + } else { |
| 44 | + const localSettingsUri: vscode.Uri = vscode.Uri.file(localSettingsPath); |
| 45 | + |
| 46 | + let localSettings: ILocalSettingsJson = <ILocalSettingsJson>await AzExtFsExtra.readJSON(localSettingsPath); |
| 47 | + if (localSettings.IsEncrypted) { |
| 48 | + await decryptLocalSettings(context, localSettingsUri); |
| 49 | + try { |
| 50 | + localSettings = await AzExtFsExtra.readJSON<ILocalSettingsJson>(localSettingsPath); |
| 51 | + } finally { |
| 52 | + await encryptLocalSettings(context, localSettingsUri); |
| 53 | + } |
| 54 | + } |
| 55 | + return { properties: localSettings.Values }; |
| 56 | + } |
| 57 | + }); |
| 58 | + return result ?? { properties: {} }; |
| 59 | + } |
| 60 | + |
| 61 | + public async updateApplicationSettings(): Promise<StringDictionary> { |
| 62 | + throw new Error('Method not implemented.'); |
| 63 | + } |
| 64 | +} |
0 commit comments