From f3e7ad3f21eb3545cbdaf023534d7a3d943a966e Mon Sep 17 00:00:00 2001 From: Paras Date: Wed, 4 Oct 2023 11:58:59 +0530 Subject: [PATCH 1/3] fix: if-else statement code --- library/src/helpers/server.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/library/src/helpers/server.ts b/library/src/helpers/server.ts index eb6bcf9ca..c5e9d2f9d 100644 --- a/library/src/helpers/server.ts +++ b/library/src/helpers/server.ts @@ -59,13 +59,12 @@ export class ServerHelpers { } else { securityProtocol = 'PLAINTEXT'; } + } else if (securitySchema) { + securityProtocol = 'SASL_SSL'; } else { - if (securitySchema) { - securityProtocol = 'SASL_SSL'; - } else { - securityProtocol = 'SSL'; - } + securityProtocol = 'SSL'; } + if (securitySchema) { switch (securitySchema.type()) { case 'plain': From 9ca99c7e9ae721c023fc53bf177bf4015604d830 Mon Sep 17 00:00:00 2001 From: Paras Date: Wed, 4 Oct 2023 15:37:22 +0530 Subject: [PATCH 2/3] enhanced code --- library/src/helpers/server.ts | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/library/src/helpers/server.ts b/library/src/helpers/server.ts index c5e9d2f9d..76e9984f4 100644 --- a/library/src/helpers/server.ts +++ b/library/src/helpers/server.ts @@ -53,17 +53,15 @@ export class ServerHelpers { ) { let securityProtocol; let saslMechanism; - if (protocol === 'kafka') { - if (securitySchema) { - securityProtocol = 'SASL_PLAINTEXT'; - } else { - securityProtocol = 'PLAINTEXT'; - } - } else if (securitySchema) { - securityProtocol = 'SASL_SSL'; - } else { - securityProtocol = 'SSL'; - } + + securityProtocol = + protocol === 'kafka' + ? securitySchema + ? 'SASL_PLAINTEXT' + : 'PLAINTEXT' + : securitySchema + ? 'SASL_SSL' + : 'SSL'; if (securitySchema) { switch (securitySchema.type()) { From 6fdab206eed971c60129dd9c3f0fdbef997902e8 Mon Sep 17 00:00:00 2001 From: Paras Date: Thu, 12 Oct 2023 11:32:46 +0530 Subject: [PATCH 3/3] removed the ternary expression --- library/src/helpers/server.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/library/src/helpers/server.ts b/library/src/helpers/server.ts index 76e9984f4..61c2212cd 100644 --- a/library/src/helpers/server.ts +++ b/library/src/helpers/server.ts @@ -54,14 +54,17 @@ export class ServerHelpers { let securityProtocol; let saslMechanism; - securityProtocol = - protocol === 'kafka' - ? securitySchema - ? 'SASL_PLAINTEXT' - : 'PLAINTEXT' - : securitySchema - ? 'SASL_SSL' - : 'SSL'; + if (protocol === 'kafka') { + if (securitySchema) { + securityProtocol = 'SASL_PLAINTEXT'; + } else { + securityProtocol = 'PLAINTEXT'; + } + } else if (securitySchema) { + securityProtocol = 'SASL_SSL'; + } else { + securityProtocol = 'SSL'; + } if (securitySchema) { switch (securitySchema.type()) {