From f8563c5a8751e0bbe498e9f980c669b19eadb169 Mon Sep 17 00:00:00 2001 From: Dale Lane Date: Fri, 8 Mar 2024 17:02:30 +0000 Subject: [PATCH] fix: populate env.json with valid Kafka bootstrap addresses The generator was putting the "kafka-secure://" protocol prefix in the bootstrap address for generated Kafka apps, which the Kafka client library rejects as an invalid URL. This commit uses the hostname if it is available (v3 docs) but falls back to using the url otherwise (v2 docs). Signed-off-by: Dale Lane --- components/Common.js | 3 ++- test/Kafka.test.js | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/components/Common.js b/components/Common.js index 83d0c24..77e00d1 100644 --- a/components/Common.js +++ b/components/Common.js @@ -109,6 +109,7 @@ public void close() { export function EnvJson({ asyncapi, params }) { const server = asyncapi.allServers().get(params.server); const url = server.url(); + const hostname = server.host() || server.url(); const protocol = server.protocol(); let user = params.user; let password = params.password; @@ -153,7 +154,7 @@ export function EnvJson({ asyncapi, params }) { return ` { "KAFKA_ENDPOINTS": [{ - "BOOTSTRAP_ADDRESS": "${url}", + "BOOTSTRAP_ADDRESS": "${hostname}", "APP_USER": "${user}", "APP_PASSWORD": "${password}" }] diff --git a/test/Kafka.test.js b/test/Kafka.test.js index 062379d..1dd3b8b 100644 --- a/test/Kafka.test.js +++ b/test/Kafka.test.js @@ -43,6 +43,11 @@ describe('kafka integration tests using the generator', () => { for (const expectedLine of expectedConnectionHelperLines) { expect(connectionHelper.includes(expectedLine)).toBe(true); } + const connectionEnv = readFileSync(path.join(OUTPUT_DIR, 'env.json'), 'utf-8'); + const foundStreetlightsScram = connectionEnv.includes('"BOOTSTRAP_ADDRESS": "test.mykafkacluster.org:18092"'); + const foundStreetlightsMtls = connectionEnv.includes('"BOOTSTRAP_ADDRESS": "test.mykafkacluster.org:28092"'); + const foundRecordLabelKafka = connectionEnv.includes('"BOOTSTRAP_ADDRESS": "my-kafka-hostname:9092"'); + expect(foundStreetlightsScram || foundStreetlightsMtls || foundRecordLabelKafka).toBe(true); return true; };