@@ -65,15 +65,15 @@ async function request(options, data) {
65
65
}
66
66
67
67
function _validateCertificate ( req , res , next ) {
68
- this . LOG . debug ( 'event broker trying to authenticate via mTLS' )
68
+ this . LOG . _debug && this . LOG . debug ( 'event broker trying to authenticate via mTLS' )
69
69
70
70
if ( req . headers [ 'x-ssl-client-verify' ] !== '0' ) {
71
- this . LOG . info ( 'cf did not validate client certificate.' )
71
+ this . LOG . _debug && this . LOG . debug ( 'cf did not validate client certificate.' )
72
72
return res . status ( 401 ) . json ( { message : 'Unauthorized' } )
73
73
}
74
74
75
75
if ( ! req . headers [ 'x-forwarded-client-cert' ] ) {
76
- this . LOG . info ( 'no certificate in xfcc header.' )
76
+ this . LOG . _debug && this . LOG . debug ( 'no certificate in xfcc header.' )
77
77
return res . status ( 401 ) . json ( { message : 'Unauthorized' } )
78
78
}
79
79
@@ -90,34 +90,34 @@ function _validateCertificate(req, res, next) {
90
90
this . auth . validationCert . subject . CN !== clientCert . subject . CN ||
91
91
this . auth . validationCert . subject . CN !== cfSubject
92
92
) {
93
- this . LOG . info ( 'certificate subject does not match' )
93
+ this . LOG . _debug && this . LOG . debug ( 'certificate subject does not match' )
94
94
return res . status ( 401 ) . json ( { message : 'Unauthorized' } )
95
95
}
96
- this . LOG . debug ( 'incoming Subject CN is valid.' )
96
+ this . LOG . _debug && this . LOG . debug ( 'incoming Subject CN is valid.' )
97
97
98
98
if ( this . auth . validationCert . issuer . CN !== clientCert . issuer . CN ) {
99
- this . LOG . info ( 'Certificate issuer subject does not match' )
99
+ this . LOG . _debug && this . LOG . debug ( 'Certificate issuer subject does not match' )
100
100
return res . status ( 401 ) . json ( { message : 'Unauthorized' } )
101
101
}
102
- this . LOG . debug ( 'incoming issuer subject CN is valid.' )
102
+ this . LOG . _debug && this . LOG . debug ( 'incoming issuer subject CN is valid.' )
103
103
104
104
if ( this . auth . validationCert . issuer . O !== clientCert . issuer . O ) {
105
- this . LOG . info ( 'Certificate issuer org does not match' )
105
+ this . LOG . _debug && this . LOG . debug ( 'Certificate issuer org does not match' )
106
106
return res . status ( 401 ) . json ( { message : 'Unauthorized' } )
107
107
}
108
- this . LOG . debug ( 'incoming Issuer Org is valid.' )
108
+ this . LOG . _debug && this . LOG . debug ( 'incoming Issuer Org is valid.' )
109
109
110
110
if ( this . auth . validationCert . issuer . OU !== clientCert . issuer . OU ) {
111
- this . LOG . info ( 'certificate issuer OU does not match' )
111
+ this . LOG . _debug && this . LOG . debug ( 'certificate issuer OU does not match' )
112
112
return res . status ( 401 ) . json ( { message : 'Unauthorized' } )
113
113
}
114
- this . LOG . debug ( 'certificate issuer OU is valid.' )
114
+ this . LOG . _debug && this . LOG . debug ( 'certificate issuer OU is valid.' )
115
115
116
116
const valid_from = new Date ( clientCert . valid_from )
117
117
const valid_to = new Date ( clientCert . valid_to )
118
118
const now = new Date ( Date . now ( ) )
119
119
if ( valid_from <= now && valid_to >= now ) {
120
- this . LOG . debug ( 'certificate validation completed' )
120
+ this . LOG . _debug && this . LOG . debug ( 'certificate validation completed' )
121
121
next ( )
122
122
} else {
123
123
this . LOG . error ( 'Certificate expired' )
@@ -249,15 +249,13 @@ class EventBroker extends cds.MessagingService {
249
249
} ,
250
250
agent : this . agent
251
251
}
252
- if ( this . LOG . _debug ) {
253
- this . LOG . debug ( 'HTTP headers:' , JSON . stringify ( options . headers ) )
254
- this . LOG . debug ( 'HTTP body:' , JSON . stringify ( msg . data ) )
255
- }
252
+ this . LOG . _debug && this . LOG . debug ( 'HTTP headers:' , JSON . stringify ( options . headers ) )
253
+ this . LOG . _debug && this . LOG . debug ( 'HTTP body:' , JSON . stringify ( msg . data ) )
256
254
// what about headers?
257
255
// TODO: Clarify if we should send `{ data, ...headers }` vs. `data` + HTTP headers (`ce-*`)
258
256
// Disadvantage with `data` + HTTP headers is that they're case insensitive -> information loss, but they're 'closer' to the cloudevents standard
259
257
await request ( options , { data : msg . data , ...headers } ) // TODO: fetch does not work with mTLS as of today, requires another module. see https://github.com/nodejs/node/issues/48977
260
- if ( this . LOG . _info ) this . LOG . info ( 'Emit' , { topic : msg . event } )
258
+ this . LOG . info ( 'Emit' , { topic : msg . event } )
261
259
} catch ( e ) {
262
260
this . LOG . error ( 'Emit failed:' , e . message )
263
261
throw e
@@ -340,7 +338,7 @@ class EventBroker extends cds.MessagingService {
340
338
if ( msg . tenant ) context . tenant = msg . tenant
341
339
342
340
await this . tx ( context , tx => tx . emit ( msg ) )
343
- this . LOG . debug ( 'Event processed successfully.' )
341
+ this . LOG . _debug && this . LOG . debug ( 'Event processed successfully.' )
344
342
return res . status ( 200 ) . json ( { message : 'OK' } )
345
343
} catch ( e ) {
346
344
this . LOG . error ( 'ERROR during inbound event processing:' , e )
0 commit comments