Sha256: 5e9d0fef738539190d9ffdbe6b0c6d1793b0684dd839eb7803e5fc825c065eaa

Contents?: true

Size: 947 Bytes

Versions: 4

Compression:

Stored size: 947 Bytes

Contents

require 'open3'
module Brillo
  module Helpers
    module ExecHelper
      def execute *command
        command_string = Array(command).join(' ')
        log_anonymized command_string
        stdout, stderr, status = Open3.capture3 command_string
        [status.success?, stdout, stderr]
      end

      def execute! *command
        success, stdout, stderr = execute(command)
        if success
          [success, stdout, stderr]
        else
          raise RuntimeError, "#{stdout} #{stderr}"
        end
      end

      private

      def log_anonymized command_string
        command_string = command_string.gsub(/--password=[^\s]+/, "--password={FILTERED}")
        command_string = command_string.gsub(/EC2_ACCESS_KEY=[^\s]+/, "EC2_ACCESS_KEY={FILTERED}")
        command_string = command_string.gsub(/EC2_SECRET_KEY=[^\s]+/, "EC2_SECRET_KEY={FILTERED}")
        logger.info "Running \n\t #{command_string}"
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
brillo-1.1.3 lib/brillo/helpers/exec_helper.rb
brillo-1.1.2 lib/brillo/helpers/exec_helper.rb
brillo-1.1.1 lib/brillo/helpers/exec_helper.rb
brillo-1.1.0 lib/brillo/helpers/exec_helper.rb