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
49 50 51 52 53 54 |
# File 'lib/wip/config.rb', line 49 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
32 |
# File 'lib/wip/config.rb', line 32 def compose = @raw['compose'] |
#compose? ⇒ Boolean
33 |
# File 'lib/wip/config.rb', line 33 def compose? = mode == 'compose' |
#compose_command ⇒ Object
37 |
# File 'lib/wip/config.rb', line 37 def compose_command = compose && compose['command'] |
#compose_file ⇒ Object
35 |
# File 'lib/wip/config.rb', line 35 def compose_file = compose && compose['file'] |
#compose_project ⇒ Object
36 |
# File 'lib/wip/config.rb', line 36 def compose_project = compose && compose['project'] |
#compose_service ⇒ Object
34 |
# File 'lib/wip/config.rb', line 34 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.
29 |
# File 'lib/wip/config.rb', line 29 def container = presence(@raw['container']) || 'app' |
#dependencies ⇒ Object
25 26 27 28 |
# 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. |
#dependency(name) ⇒ Object
56 57 58 59 60 61 |
# File 'lib/wip/config.rb', line 56 def dependency(name) entry = dependencies[name.to_s] return unless entry DEPENDENCY_DEFAULTS.merge(entry) end |
#mode ⇒ Object
31 |
# File 'lib/wip/config.rb', line 31 def mode = @raw['mode'] || 'container' |
#network ⇒ Object
30 |
# File 'lib/wip/config.rb', line 30 def network = @raw['network'] |
#primary ⇒ Object
The dependencies: entry container points at, or nil if it isn't defined.
47 |
# File 'lib/wip/config.rb', line 47 def primary = dependency(container) |
#sync ⇒ Object
40 41 42 43 44 |
# File 'lib/wip/config.rb', line 40 def sync return @sync if defined?(@sync) @sync = @raw.key?('sync') ? build_sync : nil end |
#sync? ⇒ Boolean
38 |
# File 'lib/wip/config.rb', line 38 def sync? = !!sync |
#to_h(redact: true) ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'lib/wip/config.rb', line 63 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' |