Skip to content

Commit 3879a74

Browse files
authored
Merge pull request #529 from KxSystems/ee-auth
Added async to custom auth api
2 parents 90c302b + 4d4a4d3 commit 3879a74

File tree

4 files changed

+26
-40
lines changed

4 files changed

+26
-40
lines changed

src/classes/localConnection.ts

Lines changed: 23 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -60,27 +60,8 @@ export class LocalConnection {
6060
options.user = creds[0];
6161
options.password = creds[1];
6262
}
63-
this.connLabel = connLabel;
64-
65-
if (ext.customAuthApi) {
66-
const { kdb } = ext.customAuthApi.auth({
67-
label: connLabel,
68-
kdb: {
69-
host: options.host,
70-
port: options.port,
71-
user: options.user,
72-
password: options.password,
73-
unixSocket: options.unixSocket,
74-
socketTimeout: options.socketTimeout,
75-
socketNoDelay: options.socketNoDelay,
76-
},
77-
});
78-
79-
if (kdb) {
80-
updateOptions(options, kdb);
81-
}
82-
}
8363

64+
this.connLabel = connLabel;
8465
this.options = options;
8566
this.connected = false;
8667
}
@@ -92,7 +73,9 @@ export class LocalConnection {
9273
public async connect(
9374
callback: nodeq.AsyncValueCallback<LocalConnection>,
9475
): Promise<void> {
95-
nodeq.connect(this.options, (err, conn) => {
76+
const options = await this.getCustomAuthOptions();
77+
78+
nodeq.connect(options, (err, conn) => {
9679
if (err || !conn) {
9780
ext.serverProvider.reload();
9881

@@ -386,22 +369,25 @@ export class LocalConnection {
386369
this.update();
387370
callback(err, this);
388371
}
389-
}
390372

391-
function updateOptions(options: any, kdb: any): void {
392-
const keys = [
393-
"host",
394-
"port",
395-
"user",
396-
"password",
397-
"unixSocket",
398-
"socketTimeout",
399-
"socketNoDelay",
400-
];
401-
402-
keys.forEach((key) => {
403-
if (kdb[key] !== undefined) {
404-
options[key] = kdb[key];
373+
async getCustomAuthOptions(): Promise<nodeq.ConnectionParameters> {
374+
if (ext.customAuth) {
375+
const { kdb } = await ext.customAuth.auth({
376+
label: this.connLabel,
377+
kdb: {
378+
host: this.options.host,
379+
port: this.options.port,
380+
user: this.options.user,
381+
password: this.options.password,
382+
unixSocket: this.options.unixSocket,
383+
socketTimeout: this.options.socketTimeout,
384+
socketNoDelay: this.options.socketNoDelay,
385+
},
386+
});
387+
if (kdb) {
388+
return { ...this.options, ...kdb };
389+
}
405390
}
406-
});
391+
return this.options;
392+
}
407393
}

src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ export async function activate(context: ExtensionContext) {
742742
if (authExtension) {
743743
const api = await authExtension.activate();
744744
if ("auth" in api) {
745-
ext.customAuthApi = api;
745+
ext.customAuth = api;
746746
}
747747
}
748748
}

src/extensionVariables.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,5 +440,5 @@ export namespace ext {
440440
},
441441
];
442442

443-
export let customAuthApi: CustomAuth | null = null;
443+
export let customAuth: CustomAuth | null = null;
444444
}

src/models/customAuth.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ export interface CustomAuthParams {
2525
}
2626

2727
export interface CustomAuth {
28-
auth: (options: CustomAuthParams) => CustomAuthParams;
28+
auth: (options: CustomAuthParams) => Promise<Partial<CustomAuthParams>>;
2929
}

0 commit comments

Comments
 (0)