diff --git a/library/src/containers/Servers/ServerSecurity.tsx b/library/src/containers/Servers/ServerSecurity.tsx index c3899f40a..75fc4548b 100644 --- a/library/src/containers/Servers/ServerSecurity.tsx +++ b/library/src/containers/Servers/ServerSecurity.tsx @@ -28,7 +28,7 @@ export const ServerSecurity: React.FunctionComponent = ({ ) { if (protocol === 'kafka' || protocol === 'kafka-secure') { renderedServerSecurities = ( - + ); } } else { @@ -80,65 +80,34 @@ const ServerSecurityItem: React.FunctionComponent = ({ protocol, }) => { const schemas: React.ReactNodeArray = []; - if (securitySchema && securitySchema.name()) { - schemas.push(Name: {securitySchema.name()}); - } - if (securitySchema && securitySchema.in()) { - schemas.push(In: {securitySchema.in()}); - } - if (securitySchema && securitySchema.scheme()) { - schemas.push(Scheme: {securitySchema.scheme()}); - } - if (securitySchema && securitySchema.bearerFormat()) { - schemas.push(Bearer format: {securitySchema.bearerFormat()}); - } - if (securitySchema && securitySchema.openIdConnectUrl()) { - schemas.push( - - Connect URL - , - ); + if (securitySchema) { + if (securitySchema.name()) { + schemas.push(Name: {securitySchema.name()}); + } + if (securitySchema.in()) { + schemas.push(In: {securitySchema.in()}); + } + if (securitySchema.scheme()) { + schemas.push(Scheme: {securitySchema.scheme()}); + } + if (securitySchema.bearerFormat()) { + schemas.push(Bearer format: {securitySchema.bearerFormat()}); + } + if (securitySchema.openIdConnectUrl()) { + schemas.push( + + Connect URL + , + ); + } } 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 = (
diff --git a/library/src/helpers/server.ts b/library/src/helpers/server.ts index e3cc08f15..5b94046f5 100644 --- a/library/src/helpers/server.ts +++ b/library/src/helpers/server.ts @@ -1,3 +1,5 @@ +import { SecurityScheme } from '@asyncapi/parser'; + export class ServerHelpers { static securityType(value: string) { switch (value) { @@ -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 }; + } }