Skip to content

Commit

Permalink
add audit logging from the launcher
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve-Mcl committed Aug 27, 2024
1 parent e0f3063 commit 2eac1e8
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions lib/launcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const path = require('path')
const { log, info, debug, warn, NRlog } = require('./logging/log')
const { copyDir, hasProperty } = require('./utils')
const { States } = require('./states')
const { default: got } = require('got')

const MIN_RESTART_TIME = 10000 // 10 seconds
const MAX_RESTART_COUNT = 5
Expand Down Expand Up @@ -385,6 +386,31 @@ class Launcher {
}
}

async logAuditEvent (event, body) {
const data = {
timestamp: Date.now(),
event
}
if (body && typeof body === 'object') {
if (body.error) {
data.error = {
code: body.error.code || 'unexpected_error',
error: body.error.error || body.error.message || 'Unexpected error'
}
} else {
Object.assign(data, body)
}
}
return got.post(this.auditLogURL, {
json: data,
headers: {
authorization: 'Bearer ' + this.config.token
}
}).catch(_err => {
console.error('Failed to log audit event', _err, event)
})
}

async start () {
if (this.deferredStop) {
await this.deferredStop
Expand Down

0 comments on commit 2eac1e8

Please sign in to comment.