-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[REVIEW] Reviewing implementation #7
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,13 @@ | ||
const AuditLogService = require('./service') | ||
|
||
// the default depth of 2 is not enough to see the full logs | ||
require('util').inspect.defaultOptions.depth = 3 | ||
const { inspect } = require('util') | ||
const colors = process.stdout.isTTY | ||
|
||
module.exports = class AuditLog2Console extends AuditLogService { | ||
async init() { | ||
// call AuditLogService's init | ||
await super.init() | ||
|
||
this.on('*', function (req) { | ||
const { event, data } = req | ||
|
||
console.log(`[audit-log] - ${event}:`, data) | ||
console.log('[audit-log] -', event, inspect(data,{colors,depth:3})) | ||
sjvans marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}) | ||
await super.init() | ||
sjvans marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,54 @@ | ||
const cds = require('@sap/cds') | ||
|
||
// REVISIT: cds.OutboxService or technique to avoid extending OutboxService | ||
const OutboxService = require('@sap/cds/libx/_runtime/messaging/Outbox') | ||
|
||
const ANONYMOUS = 'anonymous' | ||
|
||
const _augment = data => { | ||
data.id = data.id || cds.utils.uuid() | ||
data.tenant = data.tenant || cds.context.tenant || ANONYMOUS | ||
data.user = data.user || cds.context.user?.id || ANONYMOUS | ||
data.timestamp = data.timestamp || cds.context.timestamp | ||
return data | ||
} | ||
// REVISIT: cds.OutboxService or technique to avoid extending OutboxService | ||
// REVISIT: OutboxService should not be base class but a decorator | ||
|
||
module.exports = class AuditLogService extends OutboxService { | ||
async emit(first, second) { | ||
let { event, data } = typeof first === 'object' ? first : { event: first, data: second } | ||
if (data.event && data.data) ({ event, data } = data) | ||
data = _augment(data) | ||
|
||
async emit(event, data) { | ||
|
||
// REVISIT: That should not be neccessary, as the * handlers react on both .emit or .send / handled by the outbox, if at all. | ||
// immediate or deferred? | ||
if (!this.options.outbox) return this.send(event, data) | ||
|
||
if (typeof event === 'object') ({ event, data } = event) // We shouldn't neccessarily need that | ||
if (data.event && data.data) ({ event, data } = data) // REVISIT: Why is that? | ||
data = _augment(data) | ||
|
||
try { | ||
// this will open a new (detached!) tx -> preserve user | ||
// REVISIT: Why do we need a new root tx? | ||
sjvans marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// REVISIT: Why do we construct a new cds.Request? -> done in base class | ||
sjvans marked this conversation as resolved.
Show resolved
Hide resolved
|
||
await this.tx(() => super.send(new cds.Request({ event, data }))) | ||
} catch (e) { | ||
// REVISIT: Who throws ERR_ASSERTION | ||
sjvans marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (e.code === 'ERR_ASSERTION') e.unrecoverable = true | ||
throw e | ||
} | ||
} | ||
|
||
async send(event, data) { | ||
if (data.event && data.data) ({ event, data } = data) | ||
|
||
if (typeof event === 'object') ({ event, data } = event) // We shouldn't neccessarily need that | ||
if (data.event && data.data) ({ event, data } = data) // REVISIT: Why is that? | ||
return super.send(event, _augment(data)) | ||
} | ||
|
||
/* | ||
* new api (await audit.log/logSync(event, data)) | ||
*/ | ||
|
||
log(event, data = {}) { | ||
log(event, data) { | ||
return this.emit(event, data) | ||
} | ||
|
||
logSync(event, data = {}) { | ||
logSync(event, data) { | ||
return this.send(event, data) | ||
} | ||
|
||
/* | ||
* compat api (await audit.<event>(data)) | ||
*/ | ||
|
||
dataAccessLog(data = {}) { | ||
return this.emit('SensitiveDataRead', data) | ||
} | ||
|
||
dataModificationLog(data = {}) { | ||
return this.emit('PersonalDataModified', data) | ||
} | ||
} | ||
|
||
configChangeLog(data = {}) { | ||
// REVISIT: event name | ||
return this.emit('ConfigurationModified', data) | ||
} | ||
|
||
securityLog(data = {}) { | ||
// REVISIT: event name | ||
return this.emit('SecurityEvent', data) | ||
} | ||
const _augment = data => { | ||
sjvans marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let ctx = cds.context | ||
if (!data.id) data.id = cds.utils.uuid() | ||
if (!data.tenant) data.tenant = ctx.tenant //|| ANONYMOUS | ||
if (!data.user) data.user = ctx.user?.id //|| ANONYMOUS | ||
if (!data.timestamp) data.timestamp = ctx.timestamp | ||
return data | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cds.env.requires['audit-log']
is false, but acds.connect.to('audit-log')
still works, so audit-logging is not "deactivated" (calculated in any case is an additional issue)...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
connect does
cds.requires || cds.requires.kinds