Skip to content

Commit e6a5051

Browse files
fix gh bug 154 "Set credential" command should allow user provided values for data source kind and query file path (#162)
1 parent 748fcc9 commit e6a5051

File tree

5 files changed

+96
-21
lines changed

5 files changed

+96
-21
lines changed

src/commands/LifecycleCommands.ts

Lines changed: 83 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@ export class LifecycleCommands implements IDisposable {
10521052
});
10531053

10541054
const connectorQueryFiles: vscode.Uri[] = await vscode.workspace.findFiles(
1055-
"**/*.query.pq",
1055+
"**/*.{query,test}.pq",
10561056
"**/{bin,obj}/**",
10571057
1e2,
10581058
);
@@ -1075,6 +1075,10 @@ export class LifecycleCommands implements IDisposable {
10751075
label: one,
10761076
}));
10771077

1078+
items.push({
1079+
label: extensionI18n["PQSdk.lifecycle.command.choose.customizedDataSourceKind.label"],
1080+
});
1081+
10781082
const picked: vscode.QuickPickItem = await input.showQuickPick({
10791083
title,
10801084
step: 1,
@@ -1085,9 +1089,17 @@ export class LifecycleCommands implements IDisposable {
10851089
});
10861090

10871091
state.DataSourceKind = picked.label;
1088-
} else {
1089-
// we did not get a list of data source candidates,
1090-
// thus have to allow users inputting freely
1092+
}
1093+
1094+
if (
1095+
!state.DataSourceKind ||
1096+
state.DataSourceKind ===
1097+
extensionI18n["PQSdk.lifecycle.command.choose.customizedDataSourceKind.label"]
1098+
) {
1099+
// we did not have the DataSourceKind populated,
1100+
// or it was set to customized dataSourceKind label
1101+
// then we should allow users to input arbitrarily
1102+
// eslint-disable-next-line require-atomic-updates
10911103
state.DataSourceKind = await input.showInputBox({
10921104
title,
10931105
step: 1,
@@ -1114,22 +1126,75 @@ export class LifecycleCommands implements IDisposable {
11141126
input: MultiStepInput,
11151127
state: Partial<CreateAuthState>,
11161128
): Promise<InputStep | void> {
1117-
const items: vscode.QuickPickItem[] = connectorQueryFiles.map((one: vscode.Uri) => ({
1118-
label: vscode.workspace.asRelativePath(one),
1119-
detail: one.fsPath,
1120-
}));
1129+
if (connectorQueryFiles.length) {
1130+
const items: vscode.QuickPickItem[] = connectorQueryFiles.map((one: vscode.Uri) => ({
1131+
label: vscode.workspace.asRelativePath(one),
1132+
detail: one.fsPath,
1133+
}));
11211134

1122-
const picked: vscode.QuickPickItem = await input.showQuickPick({
1123-
title,
1124-
step: 2,
1125-
totalSteps: 3,
1126-
placeholder: extensionI18n["PQSdk.lifecycle.command.choose.connectorFile"],
1127-
activeItem: items[0],
1128-
items,
1129-
});
1135+
items.push({
1136+
label: extensionI18n["PQSdk.lifecycle.command.choose.customizedQueryFilePath.label"],
1137+
detail: extensionI18n["PQSdk.lifecycle.command.choose.customizedQueryFilePath.detail"],
1138+
});
11301139

1131-
// eslint-disable-next-line require-atomic-updates
1132-
state.PathToQueryFile = picked.detail;
1140+
const picked: vscode.QuickPickItem = await input.showQuickPick({
1141+
title,
1142+
step: 2,
1143+
totalSteps: 3,
1144+
placeholder: extensionI18n["PQSdk.lifecycle.command.choose.queryFile"],
1145+
activeItem: items[0],
1146+
items,
1147+
});
1148+
1149+
// eslint-disable-next-line require-atomic-updates
1150+
state.PathToQueryFile = picked.detail;
1151+
}
1152+
1153+
if (
1154+
!state.PathToQueryFile ||
1155+
state.PathToQueryFile ===
1156+
extensionI18n["PQSdk.lifecycle.command.choose.customizedQueryFilePath.detail"]
1157+
) {
1158+
// we did not have the PathToQueryFile populated,
1159+
// or it was set to customized PathToQueryFile detail
1160+
// then we should allow users to input arbitrarily
1161+
// eslint-disable-next-line require-atomic-updates
1162+
state.PathToQueryFile = await input.showInputBox({
1163+
title,
1164+
step: 2,
1165+
totalSteps: 3,
1166+
value: "",
1167+
prompt: extensionI18n["PQSdk.lifecycle.command.choose.queryFilePath.label"],
1168+
ignoreFocusOut: true,
1169+
validate: (key: string) =>
1170+
Promise.resolve(
1171+
key.length
1172+
? undefined
1173+
: extensionI18n["PQSdk.lifecycle.error.empty.PathToQueryFilePath"],
1174+
),
1175+
});
1176+
1177+
// we also need to populate the state.PathToConnectorFile
1178+
// since the PathToQueryFilePath might be another query file
1179+
state.PathToConnectorFile = path.dirname(state.PathToQueryFile);
1180+
1181+
// need to populate the PathToConnectorFile to re-verify
1182+
// eslint-disable-next-line require-atomic-updates
1183+
state.PathToConnectorFile = await input.showInputBox({
1184+
title,
1185+
step: 2,
1186+
totalSteps: 3,
1187+
value: state.PathToConnectorFile,
1188+
prompt: extensionI18n["PQSdk.lifecycle.command.choose.extensionFilePath.label"],
1189+
ignoreFocusOut: true,
1190+
validate: (key: string) =>
1191+
Promise.resolve(
1192+
key.length
1193+
? undefined
1194+
: extensionI18n["PQSdk.lifecycle.error.empty.PathToConnectorFile"],
1195+
),
1196+
});
1197+
}
11331198

11341199
progress.report({ increment: 10 });
11351200

src/common/PQTestService.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ export interface ExtensionInfo {
102102
export interface CreateAuthState {
103103
DataSourceKind: string;
104104
AuthenticationKind: string;
105+
PathToConnectorFile?: string;
105106
PathToQueryFile: string;
106107
// for the key template
107108
$$KEY$$?: string;

src/i18n/extension.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,13 @@
3232
"PQSdk.lifecycle.command.generate.credentials.title": "Generating credential",
3333
"PQSdk.lifecycle.command.generate.credentials.result": "GenerateCredentialTemplate {result} ",
3434
"PQSdk.lifecycle.command.choose.dataSourceKind.label": "Data source kind",
35+
"PQSdk.lifecycle.command.choose.customizedDataSourceKind.label": "Input a data source kind",
3536
"PQSdk.lifecycle.command.choose.dataSourceKind": "Choose the data source kind",
36-
"PQSdk.lifecycle.command.choose.connectorFile": "Choose a connector file",
37+
"PQSdk.lifecycle.command.choose.queryFile": "Choose a query/test file",
38+
"PQSdk.lifecycle.command.choose.extensionFilePath.label": "Extension file path",
39+
"PQSdk.lifecycle.command.choose.queryFilePath.label": "Query/test file path",
40+
"PQSdk.lifecycle.command.choose.customizedQueryFilePath.label": "Input a query/test file path",
41+
"PQSdk.lifecycle.command.choose.customizedQueryFilePath.detail": "Arbitrary query/test file path using the credential",
3742
"PQSdk.lifecycle.command.choose.auth": "Choose an authentication method",
3843
"PQSdk.lifecycle.command.choose.authKind.prompt": "Authentication key value",
3944
"PQSdk.lifecycle.command.set.credentials.result": "SetCredential {result} ",
@@ -61,6 +66,8 @@
6166
"PQSdk.lifecycle.warning.pqtest.set.failed": "SDK Tools location has not been configured",
6267
"PQSdk.lifecycle.warning.pqtest.required": "SDK Tools location must be provided before continuing",
6368
"PQSdk.lifecycle.error.empty.dataSourceKind": "Data source kind cannot be empty",
69+
"PQSdk.lifecycle.error.empty.PathToConnectorFile": "Extension file path cannot be empty",
70+
"PQSdk.lifecycle.error.empty.PathToQueryFilePath": "Query/test file path cannot be empty",
6471
"PQSdk.lifecycle.error.empty.project.name": "A project name value must be set before continuing",
6572
"PQSdk.lifecycle.error.invalid.project.name": "Only alphanumeric are allowed.",
6673
"PQSdk.lifecycle.error.invalid.empty.value": "Value {valueName} cannot be empty.",

src/pqTestConnector/PqServiceHostClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ export class PqServiceHostClient implements IPQTestService, IDisposable {
776776
params: [
777777
{
778778
SessionId: this.sessionId,
779-
PathToConnector: getFirstWorkspaceFolder()?.uri.fsPath,
779+
PathToConnector: createAuthState.PathToConnectorFile || getFirstWorkspaceFolder()?.uri.fsPath,
780780
PathToQueryFile: resolveSubstitutedValues(createAuthState.PathToQueryFile),
781781
// DataSourceKind: createAuthState.DataSourceKind,
782782
AuthenticationKind: createAuthState.AuthenticationKind,

src/pqTestConnector/PqTestExecutableTaskQueue.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,9 @@ export class PqTestExecutableTaskQueue implements IPQTestService, IDisposable {
584584
return this.doEnqueueOneTask<GenericResult>({
585585
operation: "set-credential",
586586
additionalArgs,
587-
pathToConnector: resolveSubstitutedValues(ExtensionConfigurations.DefaultExtensionLocation),
587+
pathToConnector:
588+
createAuthState.PathToConnectorFile ||
589+
resolveSubstitutedValues(ExtensionConfigurations.DefaultExtensionLocation),
588590
pathToQueryFile: resolveSubstitutedValues(createAuthState.PathToQueryFile),
589591
stdinStr: payloadStr,
590592
});

0 commit comments

Comments
 (0)