Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add essential Kafka client security config #174

Merged
merged 3 commits into from
Oct 6, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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