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