From 9a59dfa522055a0530403ae148a6d5c807f70f5f Mon Sep 17 00:00:00 2001 From: Pedro Sousa Barreto Date: Tue, 21 May 2024 16:51:29 +0100 Subject: [PATCH] feat(nodejs-kafka-client-lib): Added authentication to kafka client (protocol config) --- packages/nodejs-kafka-client-lib/README.md | 1 + packages/nodejs-kafka-client-lib/src/raw/raw_types.ts | 1 + packages/nodejs-kafka-client-lib/src/raw/rdkafka_raw_consumer.ts | 1 + packages/nodejs-kafka-client-lib/src/raw/rdkafka_raw_producer.ts | 1 + 4 files changed, 4 insertions(+) diff --git a/packages/nodejs-kafka-client-lib/README.md b/packages/nodejs-kafka-client-lib/README.md index eababbc..7c238b5 100644 --- a/packages/nodejs-kafka-client-lib/README.md +++ b/packages/nodejs-kafka-client-lib/README.md @@ -74,6 +74,7 @@ import {MLKafkaJsonProducer, MLKafkaJsonProducerOptions} from "@mojaloop/platfor const logger: ConsoleLogger = new ConsoleLogger(); const authOptions: IRawAuthenticationOptions = { + protocol: "sasl_plaintext", mechanism: "SCRAM-SHA-256", username: "kafka", password: "password" diff --git a/packages/nodejs-kafka-client-lib/src/raw/raw_types.ts b/packages/nodejs-kafka-client-lib/src/raw/raw_types.ts index b5d27d1..4667dea 100644 --- a/packages/nodejs-kafka-client-lib/src/raw/raw_types.ts +++ b/packages/nodejs-kafka-client-lib/src/raw/raw_types.ts @@ -72,6 +72,7 @@ export declare interface IRawMessageProducer { } export declare interface IRawAuthenticationOptions { + protocol: "plaintext" | "ssl" | "sasl_plaintext" | "sasl_ssl"; mechanism: "PLAIN" | "GSSAPI" | "SCRAM-SHA-256" | "SCRAM-SHA-512", username: string, password: string diff --git a/packages/nodejs-kafka-client-lib/src/raw/rdkafka_raw_consumer.ts b/packages/nodejs-kafka-client-lib/src/raw/rdkafka_raw_consumer.ts index 4868524..b647669 100644 --- a/packages/nodejs-kafka-client-lib/src/raw/rdkafka_raw_consumer.ts +++ b/packages/nodejs-kafka-client-lib/src/raw/rdkafka_raw_consumer.ts @@ -198,6 +198,7 @@ export class MLKafkaRawConsumer extends EventEmitter implements IRawMessageConsu // authentication options if(this._options.authentication != undefined) { + this._globalConfig["security.protocol"] = this._options.authentication.protocol; this._globalConfig["sasl.mechanism"] = this._options.authentication.mechanism; this._globalConfig["sasl.username"] = this._options.authentication.username; this._globalConfig["sasl.password"] = this._options.authentication.password; diff --git a/packages/nodejs-kafka-client-lib/src/raw/rdkafka_raw_producer.ts b/packages/nodejs-kafka-client-lib/src/raw/rdkafka_raw_producer.ts index 9344fa2..794d5fe 100644 --- a/packages/nodejs-kafka-client-lib/src/raw/rdkafka_raw_producer.ts +++ b/packages/nodejs-kafka-client-lib/src/raw/rdkafka_raw_producer.ts @@ -165,6 +165,7 @@ export class MLKafkaRawProducer extends EventEmitter implements IRawMessageProdu // authentication options if(this._options.authentication != undefined) { + this._globalConfig["security.protocol"] = this._options.authentication.protocol; this._globalConfig["sasl.mechanism"] = this._options.authentication.mechanism; this._globalConfig["sasl.username"] = this._options.authentication.username; this._globalConfig["sasl.password"] = this._options.authentication.password;