-
Notifications
You must be signed in to change notification settings - Fork 149
Expand file tree
/
Copy pathLocalAppSettingListStep.ts
More file actions
97 lines (91 loc) · 6.41 KB
/
LocalAppSettingListStep.ts
File metadata and controls
97 lines (91 loc) · 6.41 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
90
91
92
93
94
95
96
97
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { type AzureWizardExecuteStep, type AzureWizardPromptStep, type IAzureQuickPickItem, type ISubscriptionActionContext, type IWizardOptions } from '@microsoft/vscode-azext-utils';
import * as path from 'path';
import { localSettingsFileName } from '../../../constants';
import { ext } from '../../../extensionVariables';
import { type BindingSettingValue } from '../../../funcConfig/function';
import { getLocalSettingsJson, type ILocalSettingsJson } from '../../../funcConfig/local.settings';
import { localize } from '../../../localize';
import { ResourceType } from '../../../templates/IBindingTemplate';
import { type IEventHubsConnectionWizardContext } from '../../appSettings/connectionSettings/eventHubs/IEventHubsConnectionWizardContext';
import { getBindingSetting, type FunctionV2WizardContext, type IFunctionWizardContext } from '../../createFunction/IFunctionWizardContext';
import { EventHubsNamespaceListStep } from '../../createFunction/durableSteps/netherite/EventHubsNamespaceListStep';
import { BindingSettingStepBase } from './BindingSettingStepBase';
import { LocalAppSettingCreateStep } from './LocalAppSettingCreateStep';
import { LocalAppSettingNameStep } from './LocalAppSettingNameStep';
import { LocalAppSettingValueStep } from './LocalAppSettingValueStep';
import { StorageTypePromptStep } from './StorageTypePromptStep';
import { CosmosDBConnectionCreateStep } from './cosmosDB/CosmosDBConnectionCreateStep';
import { CosmosDBListStep } from './cosmosDB/CosmosDBListStep';
import { EventHubAuthRuleListStep } from './eventHub/EventHubAuthRuleListStep';
import { EventHubConnectionCreateStep } from './eventHub/EventHubConnectionCreateStep';
import { EventHubListStep } from './eventHub/EventHubListStep';
import { ServiceBusConnectionCreateStep } from './serviceBus/ServiceBusConnectionCreateStep';
import { ServiceBusListStep } from './serviceBus/ServiceBusListStep';
const showHiddenValuesItem = { label: localize('showHiddenValues', '$(eye) Show hidden values'), data: 'hiddenValues' }
const hideHiddenValuesItem = { label: localize('hideHiddenValues', '$(eye-closed) Hide hidden values'), data: 'hiddenValues' }
export class LocalAppSettingListStep extends BindingSettingStepBase {
private _showHiddenValues: boolean = false;
public async promptCore(context: IFunctionWizardContext): Promise<BindingSettingValue> {
const localSettingsPath: string = path.join(context.projectPath, localSettingsFileName);
const settings: ILocalSettingsJson = await getLocalSettingsJson(context, localSettingsPath);
const existingSettings: [string, string][] = settings.Values ? Object.entries(settings.Values) : [];
let result: string | undefined;
const placeHolder: string = localize('selectAppSetting', 'Select the app setting with your {1} string from "{0}"', localSettingsFileName, this._setting.label);
do {
let picks: IAzureQuickPickItem<string | undefined>[] = [{ label: localize('newAppSetting', '$(plus) Create new local app setting'), data: undefined }];
picks = picks.concat(existingSettings.map((s: [string, string]) => { return { data: s[0], label: s[0], description: this._showHiddenValues ? s[1] : '******' }; }));
if (picks.length > 1) {
// don't add hidden values item if there are no existing settings
picks.push(this._showHiddenValues ? hideHiddenValuesItem : showHiddenValuesItem);
}
result = (await context.ui.showQuickPick(picks, { placeHolder })).data;
if (result === 'hiddenValues') {
this._showHiddenValues = !this._showHiddenValues;
picks.pop();
} else {
return result;
}
} while (true);
}
public async getSubWizard(context: IFunctionWizardContext): Promise<IWizardOptions<IFunctionWizardContext & FunctionV2WizardContext> | undefined> {
if (!getBindingSetting(context, this._setting)) {
const azurePromptSteps: AzureWizardPromptStep<IFunctionWizardContext & ISubscriptionActionContext & IEventHubsConnectionWizardContext>[] = [];
const azureExecuteSteps: AzureWizardExecuteStep<IFunctionWizardContext & ISubscriptionActionContext & IEventHubsConnectionWizardContext>[] = [];
switch (this._resourceType) {
case ResourceType.DocumentDB:
azurePromptSteps.push(new CosmosDBListStep());
azureExecuteSteps.push(new CosmosDBConnectionCreateStep(this._setting));
break;
case ResourceType.Storage:
azurePromptSteps.push(new StorageTypePromptStep(this._setting));
break;
case ResourceType.ServiceBus:
azurePromptSteps.push(new ServiceBusListStep());
azureExecuteSteps.push(new ServiceBusConnectionCreateStep(this._setting));
break;
case ResourceType.EventHub:
azurePromptSteps.push(new EventHubsNamespaceListStep(), new EventHubListStep(), new EventHubAuthRuleListStep());
azureExecuteSteps.push(new EventHubConnectionCreateStep(this._setting));
break;
default:
// Unsupported resource type - prompt user to enter connection string manually
const valueKey: string = this._setting.name.toLowerCase() + '_value';
return {
promptSteps: [new LocalAppSettingNameStep(this._setting), new LocalAppSettingValueStep(valueKey)],
executeSteps: [new LocalAppSettingCreateStep(this._setting, valueKey)]
};
}
const subscriptionPromptStep: AzureWizardPromptStep<ISubscriptionActionContext> | undefined = await ext.azureAccountTreeItem.getSubscriptionPromptStep(context);
if (subscriptionPromptStep) {
azurePromptSteps.unshift(subscriptionPromptStep);
}
return { promptSteps: azurePromptSteps, executeSteps: azureExecuteSteps };
} else {
return undefined;
}
}
}