Prepare auditor to print a present role
This commit is contained in:
@@ -69,8 +69,8 @@ class Mrsk::Commander
|
||||
Mrsk::Commands::Accessory.new(config, name: name)
|
||||
end
|
||||
|
||||
def auditor
|
||||
@auditor ||= Mrsk::Commands::Auditor.new(config)
|
||||
def auditor(role: nil)
|
||||
Mrsk::Commands::Auditor.new(config, role: role)
|
||||
end
|
||||
|
||||
def builder
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
require "active_support/core_ext/time/conversions"
|
||||
|
||||
class Mrsk::Commands::Auditor < Mrsk::Commands::Base
|
||||
attr_reader :role
|
||||
|
||||
def initialize(config, role: nil)
|
||||
super(config)
|
||||
@role = role
|
||||
end
|
||||
|
||||
# Runs remotely
|
||||
def record(line)
|
||||
append \
|
||||
@@ -25,11 +32,15 @@ class Mrsk::Commands::Auditor < Mrsk::Commands::Base
|
||||
end
|
||||
|
||||
def tagged_record_line(line)
|
||||
"'#{recorded_at_tag} #{performer_tag} #{line}'"
|
||||
quote [recorded_at_tag, performer_tag, role_tag, line].compact.join(" ")
|
||||
end
|
||||
|
||||
def tagged_broadcast_line(line)
|
||||
"'#{performer_tag} #{line}'"
|
||||
quote [performer_tag, role_tag, line].compact.join(" ")
|
||||
end
|
||||
|
||||
def role_tag
|
||||
"[#{role}]" if role
|
||||
end
|
||||
|
||||
def performer_tag
|
||||
@@ -39,4 +50,8 @@ class Mrsk::Commands::Auditor < Mrsk::Commands::Base
|
||||
def recorded_at_tag
|
||||
"[#{Time.now.to_fs(:db)}]"
|
||||
end
|
||||
|
||||
def quote(tagged_line)
|
||||
"'#{tagged_line}'"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -22,6 +22,14 @@ class CommandsAuditorTest < ActiveSupport::TestCase
|
||||
new_command.record("app removed container").join(" ")
|
||||
end
|
||||
|
||||
test "record with role" do
|
||||
@role = "web"
|
||||
|
||||
assert_match \
|
||||
/echo '.* \[web\] app removed container' >> mrsk-app-audit.log/,
|
||||
new_command.record("app removed container").join(" ")
|
||||
end
|
||||
|
||||
test "broadcast" do
|
||||
assert_match \
|
||||
/bin\/audit_broadcast '\[.*\] app removed container'/,
|
||||
@@ -30,6 +38,6 @@ class CommandsAuditorTest < ActiveSupport::TestCase
|
||||
|
||||
private
|
||||
def new_command
|
||||
Mrsk::Commands::Auditor.new(Mrsk::Configuration.new(@config, destination: @destination, version: "123"))
|
||||
Mrsk::Commands::Auditor.new(Mrsk::Configuration.new(@config, destination: @destination, version: "123"), role: @role)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user