Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom authentication for kdb+ connections #527

Merged
merged 3 commits into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/classes/localConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,26 @@ export class LocalConnection {
options.password = creds[1];
}
this.connLabel = connLabel;

if (ext.customAuthApi) {
const { kdb } = ext.customAuthApi.auth({
label: connLabel,
kdb: {
host: options.host,
port: options.port,
user: options.user,
password: options.password,
unixSocket: options.unixSocket,
socketTimeout: options.socketTimeout,
socketNoDelay: options.socketNoDelay,
},
});

if (kdb) {
updateOptions(options, kdb);
}
}

this.options = options;
this.connected = false;
}
Expand Down Expand Up @@ -367,3 +387,21 @@ export class LocalConnection {
callback(err, this);
}
}

function updateOptions(options: any, kdb: any): void {
const keys = [
"host",
"port",
"user",
"password",
"unixSocket",
"socketTimeout",
"socketNoDelay",
];

keys.forEach((key) => {
if (kdb[key] !== undefined) {
options[key] = kdb[key];
}
});
}
7 changes: 7 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,13 @@ export async function activate(context: ExtensionContext) {
.update("yaml.schemas", actualSchema, ConfigurationTarget.Global);
});
}
const authExtension = extensions.getExtension("KX.kdb-auth");
if (authExtension) {
const api = await authExtension.activate();
if ("auth" in api) {
ext.customAuthApi = api;
}
}
}

export async function deactivate(): Promise<void> {
Expand Down
3 changes: 3 additions & 0 deletions src/extensionVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { InsightsConnection } from "./classes/insightsConnection";
import { DataSourceFiles } from "./models/dataSource";
import { ConnectionLabel, LabelColors, Labels } from "./models/labels";
import { kdbAuthMap } from "./models/connectionsModels";
import { CustomAuth } from "./models/customAuth";

// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace ext {
Expand Down Expand Up @@ -438,4 +439,6 @@ export namespace ext {
colorHex: "#15A7CD",
},
];

export let customAuthApi: CustomAuth | null = null;
}
29 changes: 29 additions & 0 deletions src/models/customAuth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 1998-2025 Kx Systems Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

export interface CustomAuthParams {
label: string;
kdb?: {
host?: string;
port?: number;
user?: string;
password?: string;
socketNoDelay?: boolean;
socketTimeout?: number;
unixSocket?: string;
};
}

export interface CustomAuth {
auth: (options: CustomAuthParams) => CustomAuthParams;
}