-
Notifications
You must be signed in to change notification settings - Fork 150
Expand file tree
/
Copy pathSqlServerListStep.ts
More file actions
76 lines (63 loc) · 3.79 KB
/
SqlServerListStep.ts
File metadata and controls
76 lines (63 loc) · 3.79 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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { type Server, type SqlManagementClient } from '@azure/arm-sql';
import { LocationListStep, ResourceGroupListStep, getResourceGroupFromId, uiUtils, type ILocationWizardContext } from '@microsoft/vscode-azext-azureutils';
import { AzureWizardPromptStep, ConfirmPreviousInputStep, nonNullProp, type AzureWizardExecuteStep, type IAzureQuickPickItem, type IWizardOptions } from '@microsoft/vscode-azext-utils';
import { localSettingsDescription } from '../../../../../constants-nls';
import { localize } from '../../../../../localize';
import { createSqlClient } from '../../../../../utils/azureClients';
import { type ISqlDatabaseAzureConnectionWizardContext } from '../ISqlDatabaseConnectionWizardContext';
import { SqlDatabaseListStep } from './SqlDatabaseListStep';
import { SqlServerCreateStep } from './SqlServerCreateStep';
import { SqlServerNameStep } from './SqlServerNameStep';
import { SqlServerPasswordAuthStep } from './SqlServerPasswordAuthStep';
import { SqlServerUsernameAuthStep } from './SqlServerUsernameAuthStep';
export class SqlServerListStep<T extends ISqlDatabaseAzureConnectionWizardContext> extends AzureWizardPromptStep<T> {
public async prompt(context: T): Promise<void> {
const client: SqlManagementClient = await createSqlClient(context);
const servers: Server[] | undefined = await uiUtils.listAllIterator(client.servers.list());
context.sqlServer = (await context.ui.showQuickPick(this.getPicks(context, servers), {
placeHolder: localize('selectSqlServer', 'Select a SQL server.'),
})).data;
if (context.sqlServer?.name) {
context.valuesToMask.push(context.sqlServer.name);
}
if (context.sqlServer && !context.resourceGroup) {
const rgName: string = getResourceGroupFromId(nonNullProp(context.sqlServer, 'id'));
context.resourceGroup = { name: rgName, location: nonNullProp(context.sqlServer, 'location') };
}
}
public shouldPrompt(context: T): boolean {
return !context.sqlServer;
}
public async getSubWizard(context: T): Promise<IWizardOptions<T> | undefined> {
const promptSteps: AzureWizardPromptStep<T>[] = [];
const executeSteps: AzureWizardExecuteStep<T>[] = [];
if (!context.sqlServer) {
promptSteps.push(new ResourceGroupListStep(), new SqlServerNameStep(), new SqlServerUsernameAuthStep(), new SqlServerPasswordAuthStep(), new ConfirmPreviousInputStep('newSqlAdminPassword', { isPassword: true }));
executeSteps.push(new SqlServerCreateStep());
LocationListStep.addStep(context, promptSteps as AzureWizardPromptStep<ILocationWizardContext>[]);
}
if (!context.sqlDatabase) {
promptSteps.push(new SqlDatabaseListStep());
}
return { promptSteps, executeSteps };
}
private async getPicks(context: T, servers: Server[]): Promise<IAzureQuickPickItem<Server | undefined>[]> {
const picks: IAzureQuickPickItem<Server | undefined>[] = [{
label: localize('newSqlServer', '$(plus) Create new SQL server'),
data: undefined,
}];
for (const s of servers) {
const serverName: string = nonNullProp(s, 'name');
picks.push({
label: serverName,
description: serverName === context.suggestedSqlServerLocalSettings ? localSettingsDescription : undefined,
data: s,
});
}
return picks;
}
}