Merge pull request #1519 from basecamp/escape-audit-line
Escape the audit line
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
class Kamal::Commands::Auditor < Kamal::Commands::Base
|
||||
attr_reader :details
|
||||
delegate :escape_shell_value, to: Kamal::Utils
|
||||
|
||||
def initialize(config, **details)
|
||||
super(config)
|
||||
@@ -9,11 +10,8 @@ class Kamal::Commands::Auditor < Kamal::Commands::Base
|
||||
# Runs remotely
|
||||
def record(line, **details)
|
||||
combine \
|
||||
[ :mkdir, "-p", config.run_directory ],
|
||||
append(
|
||||
[ :echo, audit_tags(**details).except(:version, :service_version, :service).to_s, line ],
|
||||
audit_log_file
|
||||
)
|
||||
make_run_directory,
|
||||
append([ :echo, escape_shell_value(audit_line(line, **details)) ], audit_log_file)
|
||||
end
|
||||
|
||||
def reveal
|
||||
@@ -30,4 +28,12 @@ class Kamal::Commands::Auditor < Kamal::Commands::Base
|
||||
def audit_tags(**details)
|
||||
tags(**self.details, **details)
|
||||
end
|
||||
|
||||
def make_run_directory
|
||||
[ :mkdir, "-p", config.run_directory ]
|
||||
end
|
||||
|
||||
def audit_line(line, **details)
|
||||
"#{audit_tags(**details).except(:version, :service_version, :service)} #{line}"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -20,8 +20,7 @@ class CommandsAuditorTest < ActiveSupport::TestCase
|
||||
assert_equal [
|
||||
:mkdir, "-p", ".kamal", "&&",
|
||||
:echo,
|
||||
"[#{@recorded_at}] [#{@performer}]",
|
||||
"app removed container",
|
||||
"\"[#{@recorded_at}] [#{@performer}] app removed container\"",
|
||||
">>", ".kamal/app-audit.log"
|
||||
], @auditor.record("app removed container")
|
||||
end
|
||||
@@ -31,8 +30,7 @@ class CommandsAuditorTest < ActiveSupport::TestCase
|
||||
assert_equal [
|
||||
:mkdir, "-p", ".kamal", "&&",
|
||||
:echo,
|
||||
"[#{@recorded_at}] [#{@performer}] [staging]",
|
||||
"app removed container",
|
||||
"\"[#{@recorded_at}] [#{@performer}] [staging] app removed container\"",
|
||||
">>", ".kamal/app-staging-audit.log"
|
||||
], auditor.record("app removed container")
|
||||
end
|
||||
@@ -43,8 +41,7 @@ class CommandsAuditorTest < ActiveSupport::TestCase
|
||||
assert_equal [
|
||||
:mkdir, "-p", ".kamal", "&&",
|
||||
:echo,
|
||||
"[#{@recorded_at}] [#{@performer}] [web]",
|
||||
"app removed container",
|
||||
"\"[#{@recorded_at}] [#{@performer}] [web] app removed container\"",
|
||||
">>", ".kamal/app-audit.log"
|
||||
], auditor.record("app removed container")
|
||||
end
|
||||
@@ -54,8 +51,7 @@ class CommandsAuditorTest < ActiveSupport::TestCase
|
||||
assert_equal [
|
||||
:mkdir, "-p", ".kamal", "&&",
|
||||
:echo,
|
||||
"[#{@recorded_at}] [#{@performer}] [value]",
|
||||
"app removed container",
|
||||
"\"[#{@recorded_at}] [#{@performer}] [value] app removed container\"",
|
||||
">>", ".kamal/app-audit.log"
|
||||
], @auditor.record("app removed container", detail: "value")
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user