-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add local settings node under local project in workspace view (#4367)
* add local settings node * change * update appsettings package
- Loading branch information
Showing
5 changed files
with
91 additions
and
9 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/commands/appSettings/localSettings/LocalSettingsClient.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.md in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { type StringDictionary } from "@azure/arm-appservice"; | ||
import { type AppSettingsClientProvider, type IAppSettingsClient } from "@microsoft/vscode-azext-azureappsettings"; | ||
import { AzExtFsExtra, callWithTelemetryAndErrorHandling, type IActionContext } from "@microsoft/vscode-azext-utils"; | ||
import * as vscode from 'vscode'; | ||
import { type ILocalSettingsJson } from "../../../funcConfig/local.settings"; | ||
import { type LocalProjectTreeItem } from "../../../tree/localProject/LocalProjectTreeItem"; | ||
import { decryptLocalSettings } from "./decryptLocalSettings"; | ||
import { encryptLocalSettings } from "./encryptLocalSettings"; | ||
import { getLocalSettingsFileNoPrompt } from "./getLocalSettingsFile"; | ||
|
||
export class LocalSettingsClientProvider implements AppSettingsClientProvider { | ||
private _node: LocalProjectTreeItem; | ||
constructor(node: LocalProjectTreeItem) { | ||
this._node = node; | ||
} | ||
|
||
public async createClient(): Promise<IAppSettingsClient> { | ||
return new LocalSettingsClient(this._node); | ||
} | ||
} | ||
|
||
export class LocalSettingsClient implements IAppSettingsClient { | ||
public fullName: string; | ||
public isLinux: boolean; | ||
private _node: LocalProjectTreeItem; | ||
|
||
constructor(node: LocalProjectTreeItem) { | ||
this.isLinux = false; | ||
this.fullName = 'local'; | ||
this._node = node; | ||
} | ||
|
||
public async listApplicationSettings(): Promise<StringDictionary> { | ||
const result = await callWithTelemetryAndErrorHandling<StringDictionary | undefined>('listApplicationSettings', async (context: IActionContext) => { | ||
const localSettingsPath: string | undefined = await getLocalSettingsFileNoPrompt(context, this._node.workspaceFolder); | ||
if (localSettingsPath === undefined) { | ||
return { properties: {} }; | ||
} else { | ||
const localSettingsUri: vscode.Uri = vscode.Uri.file(localSettingsPath); | ||
|
||
let localSettings: ILocalSettingsJson = <ILocalSettingsJson>await AzExtFsExtra.readJSON(localSettingsPath); | ||
if (localSettings.IsEncrypted) { | ||
await decryptLocalSettings(context, localSettingsUri); | ||
try { | ||
localSettings = await AzExtFsExtra.readJSON<ILocalSettingsJson>(localSettingsPath); | ||
} finally { | ||
await encryptLocalSettings(context, localSettingsUri); | ||
} | ||
} | ||
return { properties: localSettings.Values }; | ||
} | ||
}); | ||
return result ?? { properties: {} }; | ||
} | ||
|
||
public async updateApplicationSettings(): Promise<StringDictionary> { | ||
throw new Error('Method not implemented.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters