Sha256: e3c4aa4e7e25af4eba3be67544c0571648a40f0230414fadf89b00bfa818365c

Contents?: true

Size: 1.45 KB

Versions: 112

Compression:

Stored size: 1.45 KB

Contents

module Gitlab
  module QA
    module Docker
      class Command
        attr_reader :args

        def initialize(cmd = nil, mask_secrets: nil)
          @args = Array(cmd)
          @mask_secrets = Array(mask_secrets)
        end

        def <<(*args)
          tap { @args.concat(args) }
        end

        def volume(from, to, opt = :z)
          tap { @args.push("--volume #{from}:#{to}:#{opt}") }
        end

        def name(identity)
          tap { @args.push("--name #{identity}") }
        end

        def env(name, value)
          tap { @args.push(%(--env #{name}="#{value}")) }
        end

        def to_s
          "docker #{@args.join(' ')}"
        end

        # Returns a masked string form of a Command
        #
        # @example
        #   Command.new('a docker command', mask_secrets: 'command').mask_secrets #=> 'a docker *****'
        #   Command.new('a docker command', mask_secrets: %w[docker command]).mask_secrets #=> 'a ***** *****'
        #
        # @return [String] The masked command string
        def mask_secrets
          @mask_secrets.each_with_object(to_s) { |secret, s| s.gsub!(secret, '*****') }
        end

        def ==(other)
          to_s == other.to_s
        end

        def execute!(&block)
          Docker::Shellout.new(self).execute!(&block)
        end

        def self.execute(cmd, mask_secrets: nil, &block)
          new(cmd, mask_secrets: mask_secrets).execute!(&block)
        end
      end
    end
  end
end

Version data entries

112 entries across 112 versions & 1 rubygems

Version Path
gitlab-qa-7.1.0 lib/gitlab/qa/docker/command.rb
gitlab-qa-7.0.5 lib/gitlab/qa/docker/command.rb
gitlab-qa-7.0.4 lib/gitlab/qa/docker/command.rb
gitlab-qa-7.0.3 lib/gitlab/qa/docker/command.rb
gitlab-qa-7.0.2 lib/gitlab/qa/docker/command.rb
gitlab-qa-7.0.1 lib/gitlab/qa/docker/command.rb
gitlab-qa-7.0.0 lib/gitlab/qa/docker/command.rb
gitlab-qa-6.23.0 lib/gitlab/qa/docker/command.rb
gitlab-qa-6.22.1 lib/gitlab/qa/docker/command.rb
gitlab-qa-6.22.0 lib/gitlab/qa/docker/command.rb
gitlab-qa-6.21.4 lib/gitlab/qa/docker/command.rb
gitlab-qa-6.21.3 lib/gitlab/qa/docker/command.rb
gitlab-qa-6.21.2 lib/gitlab/qa/docker/command.rb
gitlab-qa-6.21.1 lib/gitlab/qa/docker/command.rb
gitlab-qa-6.21.0 lib/gitlab/qa/docker/command.rb
gitlab-qa-6.20.1 lib/gitlab/qa/docker/command.rb
gitlab-qa-6.20.0 lib/gitlab/qa/docker/command.rb
gitlab-qa-6.19.0 lib/gitlab/qa/docker/command.rb
gitlab-qa-6.18.2 lib/gitlab/qa/docker/command.rb
gitlab-qa-6.18.1 lib/gitlab/qa/docker/command.rb