forked from microsoft/vscode-azurefunctions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcopySchedulerConnectionString.ts
More file actions
117 lines (96 loc) · 4.97 KB
/
copySchedulerConnectionString.ts
File metadata and controls
117 lines (96 loc) · 4.97 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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { type IActionContext } from "@microsoft/vscode-azext-utils";
import { type DurableTaskSchedulerClient } from "../../tree/durableTaskScheduler/DurableTaskSchedulerClient";
import { type DurableTaskSchedulerResourceModel } from "../../tree/durableTaskScheduler/DurableTaskSchedulerResourceModel";
import { localize } from "../../localize";
import { ext } from "../../extensionVariables";
import { env, QuickPickItemKind, type QuickPickItem } from "vscode";
export function copySchedulerConnectionStringCommandFactory(schedulerClient: DurableTaskSchedulerClient) {
return async (actionContext: IActionContext, scheduler: DurableTaskSchedulerResourceModel | undefined): Promise<void> => {
if (!scheduler) {
throw new Error(localize('noSchedulerSelectedErrorMessage', 'No scheduler was selected.'));
}
const schedulerJson = await schedulerClient.getScheduler(
scheduler.subscription,
scheduler.resourceGroup,
scheduler.name);
if (!schedulerJson) {
throw new Error(localize('schedulerNotFoundErrorMessage', 'Scheduler does not exist.'));
}
const { endpoint } = schedulerJson.properties;
const noAuthentication: QuickPickItem = {
detail: localize('noAuthenticationDetail', 'No credentials will be used.'),
label: localize('noAuthenticationLabel', 'None')
}
const localDevelopment: QuickPickItem = {
detail: localize('localDevelopmentDetail', 'Use the credentials of the local developer.'),
label: localize('localDevelopmentLabel', 'Local development')
};
const userAssignedManagedIdentity: QuickPickItem = {
detail: localize('userAssignedManagedIdentityDetail', 'Use managed identity credentials for a specific client.'),
label: localize('userAssignedManagedIdentityLabel', 'User-assigned managed identity')
}
const systemAssignedManagedIdentity: QuickPickItem = {
detail: localize('systemAssignedManagedIdentityDetail', 'Use managed identity credentials for a client assigned to a specific Azure resource.'),
label: localize('systemAssignedManagedIdentityLabel', 'System-assigned managed identity')
}
const result = await actionContext.ui.showQuickPick(
[
noAuthentication,
localDevelopment,
userAssignedManagedIdentity,
systemAssignedManagedIdentity
],
{
canPickMany: false,
placeHolder: localize('authenticationTypePlaceholder', 'Select the credentials to be used to connect to the scheduler')
});
let connectionString = `Endpoint=${endpoint};Authentication=`
if (result === noAuthentication) {
connectionString += 'None';
}
else if (result === localDevelopment) {
connectionString += 'DefaultAzure';
}
else {
connectionString += 'ManagedIdentity';
if (result === userAssignedManagedIdentity) {
connectionString += ';ClientID=<ClientID>';
}
}
const taskHubs = await schedulerClient.getSchedulerTaskHubs(
scheduler.subscription,
scheduler.resourceGroup,
scheduler.name);
if (taskHubs.length > 0) {
const noTaskHubItem: QuickPickItem = {
detail: localize('noTaskHubDetail', 'Do not connect to a specific task hub.'),
label: localize('noTaskHubLabel', 'None')
}
const taskHubItems: QuickPickItem[] =
taskHubs.map(taskHub => ({ label: taskHub.name }));
const taskHubResult = await actionContext.ui.showQuickPick(
[
noTaskHubItem,
{
kind: QuickPickItemKind.Separator,
label: localize('taskHubSepratorLabel', 'Task Hubs')
},
...taskHubItems
],
{
canPickMany: false,
placeHolder: localize('taskHubSelectionPlaceholder', 'Select a task hub to connect to')
});
if (taskHubResult && taskHubResult !== noTaskHubItem) {
connectionString += `;TaskHub=${taskHubResult.label}`;
}
}
await env.clipboard.writeText(connectionString);
ext.outputChannel.show();
ext.outputChannel.appendLog(localize('schedulerConnectionStringCopiedMessage', 'Connection string copied to clipboard: {0}', connectionString));
}
}