From 51c6d27b290be6d96ec1a1f0c9adc24566cd11c9 Mon Sep 17 00:00:00 2001 From: Dale Lane Date: Sat, 2 Oct 2021 22:01:46 +0100 Subject: [PATCH 1/2] feat: add essential Kafka client security config This commit updates the generated markdown so that it includes the essential Kafka config required for clients. This makes it easier for someone using the markdown doc from an AsyncAPI doc to get started with creating a Kafka client. Signed-off-by: Dale Lane --- components/Servers.js | 85 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 82 insertions(+), 3 deletions(-) diff --git a/components/Servers.js b/components/Servers.js index 41c481cdd..5efc0d417 100644 --- a/components/Servers.js +++ b/components/Servers.js @@ -35,7 +35,7 @@ function Server({ serverName, server, asyncapi }) { - + ); } @@ -65,7 +65,10 @@ function ServerVariables({ variables }) { ); } -function ServerSecurity({ security, asyncapi }) { +function ServerSecurity({ protocol, security, asyncapi }) { + if (isKafka(protocol)) { + return KafkaServerSecurity({ protocol, security, asyncapi }); + } if (!security) { return null; } @@ -85,7 +88,83 @@ function ServerSecurity({ security, asyncapi }) { const key = Object.keys(s.json())[0]; return components.securityScheme(key); }); - + + return ( + +
Security Requirements
+
+ + ); +} + +function isKafka(protocol) { + return (protocol === 'kafka' || protocol === 'kafka-secure'); +} + +function KafkaServerSecurity({ protocol, security, asyncapi }) { + let securityData; + if (security) { + const components = asyncapi.components(); + securityData = security.map(s => { + const key = Object.keys(s.json())[0]; + return components.securityScheme(key); + }); + } + else { + securityData = [null]; + } + + const securityHeader = ['Type', 'Description', 'security.protocol', 'sasl.mechanism']; + + const securityRenderer = (entry) => { + let securityProtocol, saslMechanism; + if (protocol === 'kafka') { + if (entry) { + securityProtocol = 'SASL_PLAINTEXT'; + } + else { + securityProtocol = 'PLAINTEXT'; + } + } + else { + if (entry) { + securityProtocol = 'SASL_SSL'; + } + else { + securityProtocol = 'SSL'; + } + } + if (entry) { + switch (entry.type()) { + case 'plain': + saslMechanism = 'PLAIN'; + break; + case 'scramSha256': + saslMechanism = 'SCRAM-SHA-256'; + break; + case 'scramSha512': + saslMechanism = 'SCRAM-SHA-512'; + break; + case 'oauth2': + saslMechanism = 'OAUTHBEARER'; + break; + case 'gssapi': + saslMechanism = 'GSSAPI'; + break; + case 'X509': + securityProtocol = 'SSL'; + break; + } + } + + return [ + entry && entry.type() || '-', + entry && entry.description() || '-', + securityProtocol || '-', + saslMechanism || '-' + ]; + }; + return (
Security Requirements
From b75dfdc8853bd886db5d16623cb204bef5912e85 Mon Sep 17 00:00:00 2001 From: Dale Lane Date: Tue, 5 Oct 2021 14:56:21 +0100 Subject: [PATCH 2/2] chore: address review comments A few minor fixes Signed-off-by: Dale Lane --- components/Servers.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/components/Servers.js b/components/Servers.js index 5efc0d417..020aa654c 100644 --- a/components/Servers.js +++ b/components/Servers.js @@ -66,8 +66,8 @@ function ServerVariables({ variables }) { } function ServerSecurity({ protocol, security, asyncapi }) { - if (isKafka(protocol)) { - return KafkaServerSecurity({ protocol, security, asyncapi }); + if (protocol === 'kafka' || protocol === 'kafka-secure') { + return } if (!security) { return null; @@ -97,10 +97,6 @@ function ServerSecurity({ protocol, security, asyncapi }) { ); } -function isKafka(protocol) { - return (protocol === 'kafka' || protocol === 'kafka-secure'); -} - function KafkaServerSecurity({ protocol, security, asyncapi }) { let securityData; if (security) { @@ -158,8 +154,8 @@ function KafkaServerSecurity({ protocol, security, asyncapi }) { } return [ - entry && entry.type() || '-', - entry && entry.description() || '-', + (entry && entry.type()) || '-', + (entry && entry.description()) || '-', securityProtocol || '-', saslMechanism || '-' ];