11const joi = require ( 'joi' ) ;
22const { probeServerJoi } = require ( '../../lib/config/configItems.joi' ) ;
3-
43const { MAX_QUEUED_DEFAULT } = require ( '../../lib/constants' ) . backbeatConsumer ;
54
6- const authSchema = joi . object ( {
7- type : joi . string ( ) ,
8- ssl : joi . boolean ( ) ,
9- protocol : joi . string ( ) ,
5+ const sslSchema = joi . object ( {
6+ ssl : joi . boolean ( ) . default ( false ) ,
107 ca : joi . string ( ) ,
118 client : joi . string ( ) ,
129 key : joi . string ( ) ,
1310 keyPassword : joi . string ( ) ,
14- keytab : joi . string ( ) ,
15- principal : joi . string ( ) ,
16- serviceName : joi . string ( ) ,
1711} ) ;
1812
13+ const saslAuthSchema = sslSchema . append ( {
14+ protocol : joi . string ( ) . valid ( 'SASL_PLAINTEXT' , 'SASL_SSL' ) . required ( ) ,
15+ } ) ;
16+
17+ const kerberosAuthSchema = saslAuthSchema . append ( {
18+ type : joi . string ( ) . valid ( 'kerberos' ) . required ( ) ,
19+ keytab : joi . string ( ) . required ( ) ,
20+ principal : joi . string ( ) . required ( ) ,
21+ serviceName : joi . string ( ) . required ( ) ,
22+ } ) ;
23+
24+ const basicAuthSchema = saslAuthSchema . append ( {
25+ type : joi . string ( ) . valid ( 'basic' ) . required ( ) ,
26+ credentialsFile : joi . string ( ) . required ( ) ,
27+ } ) ;
28+
29+ const credentialsFileSchema = joi . object ( {
30+ username : joi . string ( ) . required ( ) ,
31+ password : joi . string ( ) . required ( ) ,
32+ } ) ;
33+
34+ const authSchema = joi . alternatives ( ) . try ( sslSchema , kerberosAuthSchema , basicAuthSchema ) . default ( { } ) ;
35+
1936const destinationSchema = joi . object ( {
2037 resource : joi . string ( ) . required ( ) ,
2138 type : joi . string ( ) . required ( ) ,
2239 host : joi . string ( ) . required ( ) ,
2340 port : joi . number ( ) . optional ( ) ,
2441 internalTopic : joi . string ( ) ,
2542 topic : joi . string ( ) . required ( ) ,
26- auth : authSchema . default ( { } ) ,
43+ auth : authSchema ,
2744 requiredAcks : joi . number ( ) . when ( 'type' , {
2845 is : joi . string ( ) . not ( 'kafka' ) ,
2946 then : joi . forbidden ( ) ,
@@ -41,11 +58,11 @@ const joiSchema = joi.object({
4158 monitorNotificationFailures : joi . boolean ( ) . default ( true ) ,
4259 notificationFailedTopic : joi . string ( ) . optional ( ) ,
4360 zookeeperPath : joi . string ( ) . optional ( ) ,
44- queueProcessor : {
61+ queueProcessor : joi . object ( {
4562 groupId : joi . string ( ) . required ( ) ,
4663 concurrency : joi . number ( ) . greater ( 0 ) . default ( 1000 ) ,
4764 maxQueued : joi . number ( ) . greater ( 0 ) . default ( MAX_QUEUED_DEFAULT ) ,
48- } ,
65+ } ) ,
4966 destinations : joi . array ( ) . items ( destinationSchema ) . default ( [ ] ) ,
5067 // TODO: BB-625 reset to being required after supporting probeserver in S3C
5168 // for bucket notification proceses
@@ -62,4 +79,8 @@ function configValidator(backbeatConfig, extConfig) {
6279 return validatedConfig ;
6380}
6481
65- module . exports = configValidator ;
82+ module . exports = {
83+ NotificationConfigValidator : configValidator ,
84+ authSchema,
85+ credentialsFileSchema,
86+ } ;
0 commit comments