-
Notifications
You must be signed in to change notification settings - Fork 97
Expand file tree
/
Copy pathazureConnectorWizard.ts
More file actions
122 lines (108 loc) · 5.17 KB
/
azureConnectorWizard.ts
File metadata and controls
122 lines (108 loc) · 5.17 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { ResourceGroupListStep } from '@microsoft/vscode-azext-azureutils';
import { AzureWizard, AzureWizardExecuteStep, AzureWizardPromptStep } from '@microsoft/vscode-azext-utils';
import type { IActionContext, IAzureQuickPickItem, IWizardOptions } from '@microsoft/vscode-azext-utils';
import type { IProjectWizardContext } from '@microsoft/vscode-extension-logic-apps';
import * as path from 'path';
import type { Progress } from 'vscode';
import {
defaultMsiAudience,
workflowAuthenticationMethodKey,
workflowLocationKey,
workflowManagementBaseURIKey,
workflowResourceGroupNameKey,
workflowsDynamicConnectionDefaultAuthAudienceKey,
workflowSubscriptionIdKey,
workflowTenantIdKey,
} from '../../../constants';
import { ext } from '../../../extensionVariables';
import { localize } from '../../../localize';
import { addOrUpdateLocalAppSettings } from '../../utils/appSettings/localSettings';
import { AuthenticationMethodSelectionStep, type AuthenticationMethodType } from './authenticationMethodStep';
export interface IAzureConnectorsContext extends IActionContext, IProjectWizardContext {
credentials: any;
subscriptionId: any;
resourceGroup: any;
enabled: boolean;
tenantId: any;
environment: any;
authenticationMethod?: AuthenticationMethodType;
MSIenabled?: boolean;
}
//TODO: Update to be in webview after ignite redesign is done
export function createAzureWizard(wizardContext: IAzureConnectorsContext, projectPath: string): AzureWizard<IAzureConnectorsContext> {
return new AzureWizard(wizardContext, {
promptSteps: [new GetSubscriptionDetailsStep(projectPath), new AuthenticationMethodSelectionStep<IAzureConnectorsContext>()],
executeSteps: [new SaveAzureContext(projectPath)],
});
}
class GetSubscriptionDetailsStep extends AzureWizardPromptStep<IAzureConnectorsContext> {
private _projectPath: string;
constructor(projectPath: string) {
super();
this._projectPath = projectPath;
}
public async prompt(context: IAzureConnectorsContext): Promise<void> {
const placeHolder: string = localize(
'enableAzureResource',
`Enable connectors in Azure for Logic App ${path.basename(this._projectPath)}`
);
const picks: IAzureQuickPickItem<string>[] = [
{ label: localize('useConnectorsFromAzure', 'Use connectors from Azure'), data: 'yes' },
{ label: localize('skipConnectorsFromAzure', 'Skip for now'), data: 'no' },
];
context.enabled = (await context.ui.showQuickPick(picks, { placeHolder })).data === 'yes';
}
public shouldPrompt(context: IAzureConnectorsContext): boolean {
return context.enabled === undefined;
}
public async getSubWizard(context: IAzureConnectorsContext): Promise<IWizardOptions<IAzureConnectorsContext> | undefined> {
if (context.enabled) {
const azurePromptSteps: AzureWizardPromptStep<IActionContext>[] = [];
const subscriptionPromptStep: AzureWizardPromptStep<IActionContext> | undefined =
await ext.azureAccountTreeItem.getSubscriptionPromptStep(context);
if (subscriptionPromptStep) {
azurePromptSteps.push(subscriptionPromptStep);
}
azurePromptSteps.push(new ResourceGroupListStep());
return { promptSteps: azurePromptSteps };
}
return undefined;
}
}
class SaveAzureContext extends AzureWizardExecuteStep<IAzureConnectorsContext> {
public priority = 100;
private _projectPath: string;
constructor(projectPath: string) {
super();
this._projectPath = projectPath;
}
public async execute(
context: IAzureConnectorsContext,
_progress: Progress<{ message?: string | undefined; increment?: number | undefined }>
): Promise<void> {
const valuesToUpdateInSettings: Record<string, string> = {};
if (context.enabled === false) {
valuesToUpdateInSettings[workflowSubscriptionIdKey] = '';
} else {
const { resourceGroup, subscriptionId, tenantId, environment } = context;
valuesToUpdateInSettings[workflowTenantIdKey] = tenantId;
valuesToUpdateInSettings[workflowSubscriptionIdKey] = subscriptionId;
valuesToUpdateInSettings[workflowResourceGroupNameKey] = resourceGroup?.name || '';
valuesToUpdateInSettings[workflowLocationKey] = resourceGroup?.location || '';
valuesToUpdateInSettings[workflowManagementBaseURIKey] = environment.resourceManagerEndpointUrl;
// Save the authentication method to local settings
if (context.authenticationMethod) {
valuesToUpdateInSettings[workflowAuthenticationMethodKey] = context.authenticationMethod;
valuesToUpdateInSettings[workflowsDynamicConnectionDefaultAuthAudienceKey] = defaultMsiAudience;
}
}
await addOrUpdateLocalAppSettings(context, this._projectPath, valuesToUpdateInSettings);
}
public shouldExecute(context: IAzureConnectorsContext): boolean {
return context.enabled === false || !!context.subscriptionId || !!context.resourceGroup;
}
}