diff --git a/src/classes/localConnection.ts b/src/classes/localConnection.ts index 42f9ce6d..633153e1 100644 --- a/src/classes/localConnection.ts +++ b/src/classes/localConnection.ts @@ -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; } @@ -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]; + } + }); +} diff --git a/src/extension.ts b/src/extension.ts index 32b9783f..79521307 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -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 { diff --git a/src/extensionVariables.ts b/src/extensionVariables.ts index 83ce62fc..1579e8a6 100644 --- a/src/extensionVariables.ts +++ b/src/extensionVariables.ts @@ -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 { @@ -438,4 +439,6 @@ export namespace ext { colorHex: "#15A7CD", }, ]; + + export let customAuthApi: CustomAuth | null = null; } diff --git a/src/models/customAuth.ts b/src/models/customAuth.ts new file mode 100644 index 00000000..8d17bd4c --- /dev/null +++ b/src/models/customAuth.ts @@ -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; +}