Sha256: 615f7edbedc324786e9d93aae9094c2ad0d11c8dc208038b12536f9ab95ff78f

Contents?: true

Size: 1.01 KB

Versions: 15

Compression:

Stored size: 1.01 KB

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(/PGPASSWORD=[^\s]+/, "PGPASSWORD={FILTERED}")
        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

15 entries across 15 versions & 1 rubygems

Version Path
brillo-2.1.0 lib/brillo/helpers/exec_helper.rb
brillo-2.0.0 lib/brillo/helpers/exec_helper.rb
brillo-2.0.0.rc4 lib/brillo/helpers/exec_helper.rb
brillo-2.0.0.rc3 lib/brillo/helpers/exec_helper.rb
brillo-2.0.0.rc2 lib/brillo/helpers/exec_helper.rb
brillo-2.0.0.rc1 lib/brillo/helpers/exec_helper.rb
brillo-1.3.1 lib/brillo/helpers/exec_helper.rb
brillo-1.3.1.pre1 lib/brillo/helpers/exec_helper.rb
brillo-1.3.0 lib/brillo/helpers/exec_helper.rb
brillo-1.2.2 lib/brillo/helpers/exec_helper.rb
brillo-1.2.1 lib/brillo/helpers/exec_helper.rb
brillo-1.2.0 lib/brillo/helpers/exec_helper.rb
brillo-1.1.4 lib/brillo/helpers/exec_helper.rb
brillo-1.1.4.pre2 lib/brillo/helpers/exec_helper.rb
brillo-1.1.4.pre1 lib/brillo/helpers/exec_helper.rb