Allow arbitrary docker options for traefik

This commit is contained in:
Stephen van Beek
2023-03-15 15:37:10 +00:00
parent 9843c5e1ce
commit 4c542930c5
4 changed files with 33 additions and 46 deletions

View File

@@ -25,15 +25,21 @@ module Mrsk::Utils
# Returns a list of shell-dashed option arguments. If the value is true, it's treated like a value-less option.
def optionize(args, with: nil)
flattened_args = flatten_args args
options = if with
args.collect { |(key, value)| value == true ? "--#{key}" : "--#{key}#{with}#{escape_shell_value(value)}" }
flattened_args.collect { |(key, value)| value == true ? "--#{key}" : "--#{key}#{with}#{escape_shell_value(value)}" }
else
args.collect { |(key, value)| [ "--#{key}", value == true ? nil : escape_shell_value(value) ] }
flattened_args.collect { |(key, value)| [ "--#{key}", value == true ? nil : escape_shell_value(value) ] }
end
options.flatten.compact
end
# Flattens a one-to-many structure into an array of two-element arrays each containing a key-value pair
def flatten_args(args)
args.flat_map { |key, value| value.respond_to?('map') ? value.map { |entry| [key, entry] }: [[key, value]] }
end
# Copied from SSHKit::Backend::Abstract#redact to be available inside Commands classes
def redact(arg) # Used in execute_command to hide redact() args a user passes in
arg.to_s.extend(SSHKit::Redaction) # to_s due to our inability to extend Integer, etc