Skip to content

Commit 90c302b

Browse files
authored
Merge pull request #527 from KxSystems/ee-auth
Custom authentication for kdb+ connections
2 parents 60bf5f4 + 89fad38 commit 90c302b

File tree

4 files changed

+77
-0
lines changed

4 files changed

+77
-0
lines changed

src/classes/localConnection.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,26 @@ export class LocalConnection {
6161
options.password = creds[1];
6262
}
6363
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+
}
83+
6484
this.options = options;
6585
this.connected = false;
6686
}
@@ -367,3 +387,21 @@ export class LocalConnection {
367387
callback(err, this);
368388
}
369389
}
390+
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];
405+
}
406+
});
407+
}

src/extension.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,13 @@ export async function activate(context: ExtensionContext) {
738738
.update("yaml.schemas", actualSchema, ConfigurationTarget.Global);
739739
});
740740
}
741+
const authExtension = extensions.getExtension("KX.kdb-auth");
742+
if (authExtension) {
743+
const api = await authExtension.activate();
744+
if ("auth" in api) {
745+
ext.customAuthApi = api;
746+
}
747+
}
741748
}
742749

743750
export async function deactivate(): Promise<void> {

src/extensionVariables.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import { InsightsConnection } from "./classes/insightsConnection";
3939
import { DataSourceFiles } from "./models/dataSource";
4040
import { ConnectionLabel, LabelColors, Labels } from "./models/labels";
4141
import { kdbAuthMap } from "./models/connectionsModels";
42+
import { CustomAuth } from "./models/customAuth";
4243

4344
// eslint-disable-next-line @typescript-eslint/no-namespace
4445
export namespace ext {
@@ -438,4 +439,6 @@ export namespace ext {
438439
colorHex: "#15A7CD",
439440
},
440441
];
442+
443+
export let customAuthApi: CustomAuth | null = null;
441444
}

src/models/customAuth.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (c) 1998-2025 Kx Systems Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
5+
* License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
10+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* specific language governing permissions and limitations under the License.
12+
*/
13+
14+
export interface CustomAuthParams {
15+
label: string;
16+
kdb?: {
17+
host?: string;
18+
port?: number;
19+
user?: string;
20+
password?: string;
21+
socketNoDelay?: boolean;
22+
socketTimeout?: number;
23+
unixSocket?: string;
24+
};
25+
}
26+
27+
export interface CustomAuth {
28+
auth: (options: CustomAuthParams) => CustomAuthParams;
29+
}

0 commit comments

Comments
 (0)