Class: Wip::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/wip/config.rb

Overview

Validated, defaulted access to a parsed wip.yml document.

Constant Summary collapse

DEFAULTS =
{ 'container' => 'app', 'workdir' => '/app', 'interactive' => false,
'remove' => true, 'env' => {}, 'ports' => [], 'volumes' => [] }.freeze
SECRET_PATTERN =
/token|password|secret|credential|auth/i

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw, path = nil) ⇒ Config

Returns a new instance of Config.



11
12
13
14
15
# File 'lib/wip/config.rb', line 11

def initialize(raw, path = nil)
  @raw = stringify(raw)
  @path = path
  validate!
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



9
10
11
# File 'lib/wip/config.rb', line 9

def path
  @path
end

Instance Method Details

#command(name) ⇒ Object



21
22
23
24
25
26
# File 'lib/wip/config.rb', line 21

def command(name)
  entry = commands[name.to_s]
  return unless entry

  defaults.merge('type' => 'exec').merge(entry)
end

#commandsObject



18
# File 'lib/wip/config.rb', line 18

def commands = @raw['commands'] || {}

#defaultsObject



19
# File 'lib/wip/config.rb', line 19

def defaults = DEFAULTS.merge(@raw['defaults'] || {})

#to_h(redact: true) ⇒ Object



28
29
30
31
32
# File 'lib/wip/config.rb', line 28

def to_h(redact: true)
  value = { 'version' => 1, 'wslc' => { 'command' => wslc_command }, 'defaults' => defaults,
            'commands' => commands.transform_values { |entry| defaults.merge('type' => 'exec').merge(entry) } }
  redact ? redact_secrets(value) : value
end

#wslc_commandObject



17
# File 'lib/wip/config.rb', line 17

def wslc_command = @raw.dig('wslc', 'command') || 'auto'