Skip to content

Commit

Permalink
chore: address review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Dale Lane <[email protected]>
  • Loading branch information
dalelane committed Oct 5, 2021
1 parent cdd3db1 commit be371f4
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 56 deletions.
81 changes: 25 additions & 56 deletions library/src/containers/Servers/ServerSecurity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const ServerSecurity: React.FunctionComponent<Props> = ({
) {
if (protocol === 'kafka' || protocol === 'kafka-secure') {
renderedServerSecurities = (
<ServerSecurityItem protocol={protocol} securitySchema={null} key="" />
<ServerSecurityItem protocol={protocol} securitySchema={null} />
);
}
} else {
Expand Down Expand Up @@ -80,65 +80,34 @@ const ServerSecurityItem: React.FunctionComponent<ServerSecurityItemProps> = ({
protocol,
}) => {
const schemas: React.ReactNodeArray = [];
if (securitySchema && securitySchema.name()) {
schemas.push(<span>Name: {securitySchema.name()}</span>);
}
if (securitySchema && securitySchema.in()) {
schemas.push(<span>In: {securitySchema.in()}</span>);
}
if (securitySchema && securitySchema.scheme()) {
schemas.push(<span>Scheme: {securitySchema.scheme()}</span>);
}
if (securitySchema && securitySchema.bearerFormat()) {
schemas.push(<span>Bearer format: {securitySchema.bearerFormat()}</span>);
}
if (securitySchema && securitySchema.openIdConnectUrl()) {
schemas.push(
<Href href={securitySchema.openIdConnectUrl()} className="underline">
Connect URL
</Href>,
);
if (securitySchema) {
if (securitySchema.name()) {
schemas.push(<span>Name: {securitySchema.name()}</span>);
}
if (securitySchema.in()) {
schemas.push(<span>In: {securitySchema.in()}</span>);
}
if (securitySchema.scheme()) {
schemas.push(<span>Scheme: {securitySchema.scheme()}</span>);
}
if (securitySchema.bearerFormat()) {
schemas.push(<span>Bearer format: {securitySchema.bearerFormat()}</span>);
}
if (securitySchema.openIdConnectUrl()) {
schemas.push(
<Href href={securitySchema.openIdConnectUrl()} className="underline">
Connect URL
</Href>,
);
}
}

let renderedKafkaSecurity;
if (protocol === 'kafka' || protocol === 'kafka-secure') {
let securityProtocol;
let saslMechanism;
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()) {
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;
}
}
const { securityProtocol, saslMechanism } = ServerHelpers.getKafkaSecurity(
protocol,
securitySchema,
);

renderedKafkaSecurity = (
<div className="px-4 py-2 ml-2 mb-2 border border-gray-400 bg-gray-100 rounded">
Expand Down
47 changes: 47 additions & 0 deletions library/src/helpers/server.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { SecurityScheme } from '@asyncapi/parser';

export class ServerHelpers {
static securityType(value: string) {
switch (value) {
Expand Down Expand Up @@ -44,4 +46,49 @@ export class ServerHelpers {
return 'Implicit';
}
}

static getKafkaSecurity(
protocol: string,
securitySchema: SecurityScheme | null,
) {
let securityProtocol;
let saslMechanism;
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()) {
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 { securityProtocol, saslMechanism };
}
}

0 comments on commit be371f4

Please sign in to comment.