Audit details * Audit logs and broadcasts accept `details` whose values are included as log tags and MRSK_* env vars passed to the broadcast command * Commands may return execution options to the CLI in their args list * Introduce `mrsk broadcast` helper for sending audit broadcasts * Report UTC time, not local time, in audit logs. Standardize on ISO 8601 format
46 lines
1.4 KiB
Ruby
46 lines
1.4 KiB
Ruby
require "sshkit"
|
|
require "sshkit/dsl"
|
|
require "active_support/core_ext/hash/deep_merge"
|
|
|
|
class SSHKit::Backend::Abstract
|
|
def capture_with_info(*args, **kwargs)
|
|
capture(*args, **kwargs, verbosity: Logger::INFO)
|
|
end
|
|
|
|
def puts_by_host(host, output, type: "App")
|
|
puts "#{type} Host: #{host}\n#{output}\n\n"
|
|
end
|
|
|
|
# Our execution pattern is for the CLI execute args lists returned
|
|
# from commands, but this doesn't support returning execution options
|
|
# from the command.
|
|
#
|
|
# Support this by using kwargs for CLI options and merging with the
|
|
# args-extracted options.
|
|
module CommandEnvMerge
|
|
private
|
|
|
|
# Override to merge options returned by commands in the args list with
|
|
# options passed by the CLI and pass them along as kwargs.
|
|
def command(*args_and_options)
|
|
options, args = args_and_options.partition { |a| a.is_a? Hash }
|
|
build_command(*args, **options.reduce(:deep_merge))
|
|
end
|
|
|
|
# Destructure options to pluck out env for merge
|
|
def build_command(args, env: nil, **options)
|
|
# Rely on native Ruby kwargs precedence rather than explicit Hash merges
|
|
SSHKit::Command.new(*args, **default_command_options, **options, env: env_for(env))
|
|
end
|
|
|
|
def default_command_options
|
|
{ in: pwd_path, host: @host, user: @user, group: @group }
|
|
end
|
|
|
|
def env_for(env)
|
|
@env.to_h.merge(env.to_h)
|
|
end
|
|
end
|
|
prepend CommandEnvMerge
|
|
end
|