Skip to content

Commit

Permalink
Merge pull request #527 from KxSystems/ee-auth
Browse files Browse the repository at this point in the history
Custom authentication for kdb+ connections
  • Loading branch information
ecmel authored Feb 27, 2025
2 parents 60bf5f4 + 89fad38 commit 90c302b
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 0 deletions.
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;
}

0 comments on commit 90c302b

Please sign in to comment.