Module: Mrsk::Utils
Instance Method Summary collapse
-
#argumentize(argument, attributes, redacted: false) ⇒ Object
Return a list of shell arguments using the same named argument against the passed attributes (hash or array).
-
#argumentize_env_with_secrets(env) ⇒ Object
Return a list of shell arguments using the same named argument against the passed attributes, but redacts and expands secrets.
-
#redact(arg) ⇒ Object
Copied from SSHKit::Backend::Abstract#redact to be available inside Commands classes.
Instance Method Details
#argumentize(argument, attributes, redacted: false) ⇒ Object
Return a list of shell arguments using the same named argument against the passed attributes (hash or array).
5 6 7 8 9 10 11 12 13 |
# File 'lib/mrsk/utils.rb', line 5 def argumentize(argument, attributes, redacted: false) Array(attributes).flat_map do |k, v| if v.present? [ argument, redacted ? redact("#{k}=#{v}") : "#{k}=#{v}" ] else [ argument, k ] end end end |
#argumentize_env_with_secrets(env) ⇒ Object
Return a list of shell arguments using the same named argument against the passed attributes, but redacts and expands secrets.
17 18 19 20 21 22 23 |
# File 'lib/mrsk/utils.rb', line 17 def argumentize_env_with_secrets(env) if (secrets = env["secret"]).present? argumentize("-e", secrets.to_h { |key| [ key, ENV.fetch(key) ] }, redacted: true) + argumentize("-e", env["clear"]) else argumentize "-e", env.fetch("clear", env) end end |
#redact(arg) ⇒ Object
Copied from SSHKit::Backend::Abstract#redact to be available inside Commands classes
26 27 28 |
# File 'lib/mrsk/utils.rb', line 26 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 end |