Skip to content

Commit

Permalink
Merge pull request #2962 from cloudfoundry/audit-events-in-syslog
Browse files Browse the repository at this point in the history
Use event_presenter for audit events in syslogs
  • Loading branch information
dalvarado authored Sep 14, 2022
2 parents 6ebc911 + 91af449 commit 26beafd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/models/runtime/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def after_save
super
if Config.config.get(:log_audit_events)
logger = Steno.logger('cc.model.event')
logger.info "Audit event: #{type} enacted by #{actor_type} #{actor_username || actor_name} on #{actee_type} #{actee_name}"
logger.info Presenters::V3::EventPresenter.new(self).body.to_json
end
end

Expand Down
5 changes: 4 additions & 1 deletion app/presenters/v3/event_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
module VCAP::CloudController::Presenters::V3
class EventPresenter < BasePresenter
def to_hash
body.merge!({ links: build_links })
end

def body
{
guid: event.guid,
created_at: event.timestamp,
Expand All @@ -13,7 +17,6 @@ def to_hash
data: event.data || {},
space: space,
organization: org,
links: build_links
}
end

Expand Down
13 changes: 9 additions & 4 deletions spec/unit/models/runtime/event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,16 @@ module VCAP::CloudController
actee: 'nimoy',
actee_type: 'vulcan',
actee_name: 'Mr. Spock',
space_guid: space.guid
space: space

}
e = Event.new(required_attrs)
expect(fake_logger).to receive(:info).with('Audit event: audit.test enacted by pork chop on vulcan Mr. Spock')
e.save
event = Event.new(required_attrs)
allow(fake_logger).to receive(:info)

event.save

expect(fake_logger).to have_received(:info).with(/audit.test/)
expect(fake_logger).to have_received(:info).with(/#{event.guid}/)
end
end

Expand Down

0 comments on commit 26beafd

Please sign in to comment.