Class: Gitlab::QA::Docker::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/qa/docker/command.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cmd = nil, mask_secrets: nil) ⇒ Command

Returns a new instance of Command.



7
8
9
10
# File 'lib/gitlab/qa/docker/command.rb', line 7

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

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



5
6
7
# File 'lib/gitlab/qa/docker/command.rb', line 5

def args
  @args
end

Class Method Details

.execute(cmd, mask_secrets: nil, &block) ⇒ Object



51
52
53
# File 'lib/gitlab/qa/docker/command.rb', line 51

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

Instance Method Details

#<<(*args) ⇒ Object



12
13
14
# File 'lib/gitlab/qa/docker/command.rb', line 12

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

#==(other) ⇒ Object



43
44
45
# File 'lib/gitlab/qa/docker/command.rb', line 43

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

#env(name, value) ⇒ Object



24
25
26
# File 'lib/gitlab/qa/docker/command.rb', line 24

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

#execute!(&block) ⇒ Object



47
48
49
# File 'lib/gitlab/qa/docker/command.rb', line 47

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

#mask_secretsString

Returns a masked string form of a Command

Examples:

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 ***** *****'

Returns:

  • (String)

    The masked command string



39
40
41
# File 'lib/gitlab/qa/docker/command.rb', line 39

def mask_secrets
  @mask_secrets.each_with_object(to_s) { |secret, s| s.gsub!(secret, '*****') }
end

#name(identity) ⇒ Object



20
21
22
# File 'lib/gitlab/qa/docker/command.rb', line 20

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

#to_sObject



28
29
30
# File 'lib/gitlab/qa/docker/command.rb', line 28

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

#volume(from, to, opt = :z) ⇒ Object



16
17
18
# File 'lib/gitlab/qa/docker/command.rb', line 16

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