-
Notifications
You must be signed in to change notification settings - Fork 149
Expand file tree
/
Copy pathAzureConnectionCreateStepBase.ts
More file actions
42 lines (34 loc) · 2.12 KB
/
AzureConnectionCreateStepBase.ts
File metadata and controls
42 lines (34 loc) · 2.12 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.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { AzureWizardExecuteStep } from '@microsoft/vscode-azext-utils';
import { type Progress } from 'vscode';
import { setLocalAppSetting } from '../../../funcConfig/local.settings';
import { localize } from '../../../localize';
import { type IBindingSetting } from '../../../templates/IBindingTemplate';
import { type ParsedInput } from '../../../templates/script/parseScriptTemplatesV2';
import { setBindingSetting, type IFunctionWizardContext } from '../../createFunction/IFunctionWizardContext';
export interface IConnection {
name: string;
connectionString: string;
}
export abstract class AzureConnectionCreateStepBase<T extends IFunctionWizardContext> extends AzureWizardExecuteStep<T> {
public priority: number = 200;
private readonly _setting: IBindingSetting | ParsedInput;
private readonly _resourceType: string;
constructor(setting: IBindingSetting | ParsedInput) {
super();
this._setting = setting;
this._resourceType = (setting as IBindingSetting).resourceType ?? (setting as ParsedInput).resource ?? '';
}
public abstract getConnection(context: T): Promise<IConnection>;
public async execute(context: T, progress: Progress<{ message?: string | undefined; increment?: number | undefined }>): Promise<void> {
progress.report({ message: localize('retrieving', 'Retrieving connection string...') });
const result: IConnection = await this.getConnection(context);
let appSettingKey: string = `${result.name}_${this._resourceType.toUpperCase()}`;
appSettingKey = appSettingKey.replace(/[^a-z0-9_\.]/gi, ''); // remove invalid chars
setBindingSetting(context, this._setting, appSettingKey);
await setLocalAppSetting(context, context.projectPath, appSettingKey, result.connectionString);
}
}