Skip to content

Commit

Permalink
. (#14)
Browse files Browse the repository at this point in the history
Co-authored-by: Johannes Vogel <[email protected]>
  • Loading branch information
David-Kunz and johannes-vogel authored Nov 12, 2024
1 parent 5092827 commit 28fa61b
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions cds-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ class EventBroker extends cds.MessagingService {

this.auth = {} // { kind: 'cert', validationCert?, privateKey? } or { kind: 'ias', ias }

console.log('cds.env.requires:', cds.env.requires)

Check warning on line 138 in cds-plugin.js

View workflow job for this annotation

GitHub Actions / build (22.x)

Unexpected console statement

Check warning on line 138 in cds-plugin.js

View workflow job for this annotation

GitHub Actions / build (20.x)

Unexpected console statement

// determine auth.kind
if (this.options.x509) {
if (!this.options.x509.cert && !this.options.x509.certPath)
Expand All @@ -155,6 +157,8 @@ class EventBroker extends cds.MessagingService {
} else this.auth.kind = 'cert'
}

console.log('this.auth:', this.auth)

Check warning on line 160 in cds-plugin.js

View workflow job for this annotation

GitHub Actions / build (22.x)

Unexpected console statement

Check warning on line 160 in cds-plugin.js

View workflow job for this annotation

GitHub Actions / build (20.x)

Unexpected console statement

if (!this.auth.kind || (this.auth.kind === 'ias' && !this.auth.ias))
throw new Error(`${this.name}: Event Broker requires your app to be bound to an IAS instance.`)

Expand Down Expand Up @@ -331,15 +335,19 @@ class EventBroker extends cds.MessagingService {
Object.assign(msg.headers, headers)
if (this.isMultitenancy) msg.tenant = tenant

// for cds.context.http
msg._ = {}
msg._.req = req
msg._.res = res

const context = { user: cds.User.privileged, _: msg._ }
if (msg.tenant) context.tenant = msg.tenant

await this.tx(context, tx => tx.emit(msg))

await this.tx(context, tx => {
if (cds.context.http?.req?.headers?.authorization) delete cds.context.http.req.headers.authorization // potential destination lookup fails if IAS token is used
return tx.emit(msg)
})

this.LOG.debug('Event processed successfully.')
return res.status(200).json({ message: 'OK' })
} catch (e) {
Expand Down

0 comments on commit 28fa61b

Please sign in to comment.