diff --git a/lib/kamal/commands/auditor.rb b/lib/kamal/commands/auditor.rb index 3589643d..9846d8e2 100644 --- a/lib/kamal/commands/auditor.rb +++ b/lib/kamal/commands/auditor.rb @@ -9,7 +9,7 @@ class Kamal::Commands::Auditor < Kamal::Commands::Base # Runs remotely def record(line, **details) combine \ - [ :mkdir, "-p", config.service_directory ], + [ :mkdir, "-p", config.run_directory ], append( [ :echo, audit_tags(**details).except(:version, :service_version, :service).to_s, line ], audit_log_file @@ -22,7 +22,9 @@ class Kamal::Commands::Auditor < Kamal::Commands::Base private def audit_log_file - File.join config.service_directory, "audit.log" + file = [ config.service, config.destination, "audit.log" ].compact.join("-") + + File.join(config.run_directory, file) end def audit_tags(**details) diff --git a/test/cli/main_test.rb b/test/cli/main_test.rb index 0956ba51..7f878e5b 100644 --- a/test/cli/main_test.rb +++ b/test/cli/main_test.rb @@ -305,7 +305,7 @@ class CliMainTest < CliTestCase test "audit" do run_command("audit").tap do |output| - assert_match %r{tail -n 50 \.kamal/apps/app/audit.log on 1.1.1.1}, output + assert_match %r{tail -n 50 \.kamal/app-audit.log on 1.1.1.1}, output assert_match /App Host: 1.1.1.1/, output end end diff --git a/test/commands/auditor_test.rb b/test/commands/auditor_test.rb index d0f66610..2abc8d81 100644 --- a/test/commands/auditor_test.rb +++ b/test/commands/auditor_test.rb @@ -18,22 +18,22 @@ class CommandsAuditorTest < ActiveSupport::TestCase test "record" do assert_equal [ - :mkdir, "-p", ".kamal/apps/app", "&&", + :mkdir, "-p", ".kamal", "&&", :echo, "[#{@recorded_at}] [#{@performer}]", "app removed container", - ">>", ".kamal/apps/app/audit.log" + ">>", ".kamal/app-audit.log" ], @auditor.record("app removed container") end test "record with destination" do new_command(destination: "staging").tap do |auditor| assert_equal [ - :mkdir, "-p", ".kamal/apps/app-staging", "&&", + :mkdir, "-p", ".kamal", "&&", :echo, "[#{@recorded_at}] [#{@performer}] [staging]", "app removed container", - ">>", ".kamal/apps/app-staging/audit.log" + ">>", ".kamal/app-staging-audit.log" ], auditor.record("app removed container") end end @@ -41,22 +41,22 @@ class CommandsAuditorTest < ActiveSupport::TestCase test "record with command details" do new_command(role: "web").tap do |auditor| assert_equal [ - :mkdir, "-p", ".kamal/apps/app", "&&", + :mkdir, "-p", ".kamal", "&&", :echo, "[#{@recorded_at}] [#{@performer}] [web]", "app removed container", - ">>", ".kamal/apps/app/audit.log" + ">>", ".kamal/app-audit.log" ], auditor.record("app removed container") end end test "record with arg details" do assert_equal [ - :mkdir, "-p", ".kamal/apps/app", "&&", + :mkdir, "-p", ".kamal", "&&", :echo, "[#{@recorded_at}] [#{@performer}] [value]", "app removed container", - ">>", ".kamal/apps/app/audit.log" + ">>", ".kamal/app-audit.log" ], @auditor.record("app removed container", detail: "value") end