Add SASL mechanism option in Kafka (#1525)

*  add SASL mechasnim option in Kafka

* add toggle for authentication in kafka credentials

*  Revery default value

Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
This commit is contained in:
Ahsan Virani 2021-03-11 14:25:02 +01:00 committed by GitHub
parent 0712334679
commit 71e21c2dae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 58 additions and 2 deletions

View file

@ -28,10 +28,23 @@ export class Kafka implements ICredentialType {
type: 'boolean' as NodePropertyTypes, type: 'boolean' as NodePropertyTypes,
default: true, default: true,
}, },
{
displayName: 'Authentication',
name: 'authentication',
type: 'boolean' as NodePropertyTypes,
default: false,
},
{ {
displayName: 'Username', displayName: 'Username',
name: 'username', name: 'username',
type: 'string' as NodePropertyTypes, type: 'string' as NodePropertyTypes,
displayOptions: {
show: {
authentication: [
true,
],
},
},
default: '', default: '',
description: 'Optional username if authenticated is required.', description: 'Optional username if authenticated is required.',
}, },
@ -39,11 +52,46 @@ export class Kafka implements ICredentialType {
displayName: 'Password', displayName: 'Password',
name: 'password', name: 'password',
type: 'string' as NodePropertyTypes, type: 'string' as NodePropertyTypes,
displayOptions: {
show: {
authentication: [
true,
],
},
},
typeOptions: { typeOptions: {
password: true, password: true,
}, },
default: '', default: '',
description: 'Optional password if authenticated is required.', description: 'Optional password if authenticated is required.',
}, },
{
displayName: 'SASL mechanism',
name: 'saslMechanism',
type: 'options' as NodePropertyTypes,
displayOptions: {
show: {
authentication: [
true,
],
},
},
options: [
{
name: 'plain',
value: 'plain',
},
{
name: 'scram-sha-256',
value: 'scram-sha-256',
},
{
name: 'scram-sha-512',
value: 'scram-sha-512',
},
],
default: 'plain',
description: 'The SASL mechanism.',
},
]; ];
} }

View file

@ -193,10 +193,14 @@ export class Kafka implements INodeType {
ssl, ssl,
}; };
if (credentials.username || credentials.password) { if (credentials.authentication === true) {
if(!(credentials.username && credentials.password)) {
throw new Error('Username and password are required for authentication');
}
config.sasl = { config.sasl = {
username: credentials.username as string, username: credentials.username as string,
password: credentials.password as string, password: credentials.password as string,
mechanism: credentials.saslMechanism as string,
} as SASLOptions; } as SASLOptions;
} }

View file

@ -123,10 +123,14 @@ export class KafkaTrigger implements INodeType {
logLevel: logLevel.ERROR, logLevel: logLevel.ERROR,
}; };
if (credentials.username || credentials.password) { if (credentials.authentication === true) {
if(!(credentials.username && credentials.password)) {
throw new Error('Username and password are required for authentication');
}
config.sasl = { config.sasl = {
username: credentials.username as string, username: credentials.username as string,
password: credentials.password as string, password: credentials.password as string,
mechanism: credentials.saslMechanism as string,
} as SASLOptions; } as SASLOptions;
} }