Skip to content

Commit

Permalink
feat: add essential Kafka client security config (#174)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* chore: address review comments

A few minor fixes

Signed-off-by: Dale Lane <[email protected]>

Co-authored-by: Maciej Urbańczyk <[email protected]>
  • Loading branch information
dalelane and magicmatatjahu authored Oct 6, 2021
1 parent 0932391 commit 12d520f
Showing 1 changed file with 78 additions and 3 deletions.
81 changes: 78 additions & 3 deletions components/Servers.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function Server({ serverName, server, asyncapi }) {
<Table headers={headers} rowRenderer={rowRenderer} data={[server]} />
</Text>
<ServerVariables variables={server.variables()} />
<ServerSecurity security={server.security()} asyncapi={asyncapi} />
<ServerSecurity protocol={server.protocol()} security={server.security()} asyncapi={asyncapi} />
</>
);
}
Expand Down Expand Up @@ -65,7 +65,10 @@ function ServerVariables({ variables }) {
);
}

function ServerSecurity({ security, asyncapi }) {
function ServerSecurity({ protocol, security, asyncapi }) {
if (protocol === 'kafka' || protocol === 'kafka-secure') {
return <KafkaServerSecurity protocol={protocol} security={security} asyncapi={asyncapi} />
}
if (!security) {
return null;
}
Expand All @@ -85,7 +88,79 @@ function ServerSecurity({ security, asyncapi }) {
const key = Object.keys(s.json())[0];
return components.securityScheme(key);
});


return (
<Text>
<Header type={4}>Security Requirements</Header>
<Table headers={securityHeader} rowRenderer={securityRenderer} data={securityData} />
</Text>
);
}

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 (
<Text>
<Header type={4}>Security Requirements</Header>
Expand Down

0 comments on commit 12d520f

Please sign in to comment.