Class: Wip::Config
- Inherits:
-
Object
- Object
- Wip::Config
- Defined in:
- lib/wip/config.rb
Overview
Validated, defaulted access to a parsed wip.yml document.
Constant Summary collapse
- DEPENDENCY_DEFAULTS =
Applied to every dependencies: entry, primary container included — there is no separate, differently-shaped bucket for "the one you exec into."
{ 'workdir' => nil, 'interactive' => false, 'remove' => true, 'env' => {}, 'ports' => [], 'volumes' => [] }.freeze
- SECRET_PATTERN =
/token|password|secret|credential|auth/i- MODES =
Which orchestration path
up/down/sync/etc. take. Explicit rather than inferred from acompose:block's presence, so a config reader doesn't have to know that rule to predict which mode wip runs in. %w[container compose].freeze
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #command(name) ⇒ Object
- #commands ⇒ Object
- #compose ⇒ Object
- #compose? ⇒ Boolean
- #compose_command ⇒ Object
- #compose_file ⇒ Object
- #compose_project ⇒ Object
- #compose_service ⇒ Object
-
#container ⇒ Object
Which dependencies: entry
up/down/exec/run/build/commands:target by default — the one container wip itself considers "the app." Everything else in dependencies: is a sidecar wip only starts and stops. - #dependencies ⇒ Object
- #dependency(name) ⇒ Object
-
#initialize(raw, path = nil) ⇒ Config
constructor
A new instance of Config.
- #mode ⇒ Object
- #network ⇒ Object
-
#primary ⇒ Object
The dependencies: entry
containerpoints at, or nil if it isn't defined. - #sync ⇒ Object
- #sync? ⇒ Boolean
- #to_h(redact: true) ⇒ Object
- #wslc_command ⇒ Object
Constructor Details
#initialize(raw, path = nil) ⇒ Config
Returns a new instance of Config.
17 18 19 20 21 |
# File 'lib/wip/config.rb', line 17 def initialize(raw, path = nil) @raw = stringify(raw) @path = path validate! end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
15 16 17 |
# File 'lib/wip/config.rb', line 15 def path @path end |
Instance Method Details
#command(name) ⇒ Object
52 53 54 55 56 57 |
# File 'lib/wip/config.rb', line 52 def command(name) entry = commands[name.to_s] return unless entry (primary || {}).merge('type' => 'exec').merge(entry) end |
#commands ⇒ Object
24 |
# File 'lib/wip/config.rb', line 24 def commands = @raw['commands'] || {} |
#compose ⇒ Object
35 |
# File 'lib/wip/config.rb', line 35 def compose = @raw['compose'] |
#compose? ⇒ Boolean
36 |
# File 'lib/wip/config.rb', line 36 def compose? = mode == 'compose' |
#compose_command ⇒ Object
40 |
# File 'lib/wip/config.rb', line 40 def compose_command = compose && compose['command'] |
#compose_file ⇒ Object
38 |
# File 'lib/wip/config.rb', line 38 def compose_file = compose && compose['file'] |
#compose_project ⇒ Object
39 |
# File 'lib/wip/config.rb', line 39 def compose_project = compose && compose['project'] |
#compose_service ⇒ Object
37 |
# File 'lib/wip/config.rb', line 37 def compose_service = compose && compose['service'] |
#container ⇒ Object
Which dependencies: entry up/down/exec/run/build/commands: target
by default — the one container wip itself considers "the app." Everything
else in dependencies: is a sidecar wip only starts and stops. No default:
guessing a name here (the old default was "app") either matches by luck or
fails in a way that doesn't point at the real problem (a differently-named
entry), so a project with any dependencies: must say which one explicitly.
32 |
# File 'lib/wip/config.rb', line 32 def container = presence(@raw['container']) |
#dependencies ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/wip/config.rb', line 25 def dependencies = @raw['dependencies'] || {} # Which dependencies: entry `up`/`down`/`exec`/`run`/`build`/`commands:` target # by default — the one container wip itself considers "the app." Everything # else in dependencies: is a sidecar wip only starts and stops. No default: # guessing a name here (the old default was "app") either matches by luck or # fails in a way that doesn't point at the real problem (a differently-named # entry), so a project with any dependencies: must say which one explicitly. |
#dependency(name) ⇒ Object
59 60 61 62 63 64 |
# File 'lib/wip/config.rb', line 59 def dependency(name) entry = dependencies[name.to_s] return unless entry DEPENDENCY_DEFAULTS.merge(entry) end |
#mode ⇒ Object
34 |
# File 'lib/wip/config.rb', line 34 def mode = @raw['mode'] || 'container' |
#network ⇒ Object
33 |
# File 'lib/wip/config.rb', line 33 def network = @raw['network'] |
#primary ⇒ Object
The dependencies: entry container points at, or nil if it isn't defined.
50 |
# File 'lib/wip/config.rb', line 50 def primary = dependency(container) |
#sync ⇒ Object
43 44 45 46 47 |
# File 'lib/wip/config.rb', line 43 def sync return @sync if defined?(@sync) @sync = @raw.key?('sync') ? build_sync : nil end |
#sync? ⇒ Boolean
41 |
# File 'lib/wip/config.rb', line 41 def sync? = !!sync |
#to_h(redact: true) ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/wip/config.rb', line 66 def to_h(redact: true) value = { 'version' => 1, 'wslc' => { 'command' => wslc_command }, 'mode' => mode, 'container' => container, 'network' => network, 'dependencies' => dependencies, 'compose' => compose, 'sync' => sync&.to_h, 'commands' => commands.transform_values do |entry| (primary || {}).merge('type' => 'exec').merge(entry) end } redact ? redact_secrets(value) : value end |
#wslc_command ⇒ Object
23 |
# File 'lib/wip/config.rb', line 23 def wslc_command = @raw.dig('wslc', 'command') || 'auto' |