Class: VaultConsul::ConfigHandler

Inherits:
Psych::TreeBuilder
  • Object
show all
Defined in:
lib/vault-consul/config_handler.rb

Instance Method Summary collapse

Instance Method Details

#scalar(value, anchor, tag, plain, quoted, style) ⇒ Object

Raises:



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/vault-consul/config_handler.rb', line 4

def scalar value, anchor, tag, plain, quoted, style
  vault_regex = /vault:/
  consul_regex = /consul:/
  env_regex = /env:/
  translated = if value.match(vault_regex)
                 vault_tag = value.gsub(vault_regex, '')
                 vault_tag_holder = vault_tag.split('.')
                 vault_key = vault_tag_holder[0]
                 json_key = vault_tag_holder[1]
                 VaultConsul.read_vault(vault_key, json_key)
               elsif value.match(consul_regex)
                 consul_key = value.gsub(consul_regex, '')
                 VaultConsul.read_consul(consul_key)
               elsif value.match(env_regex)
                 ENV[value.gsub(env_regex, '')]
               else
                 value
               end

  raise ConfigError, "Missing config: #{value}" if translated.nil? || translated == ''
  super translated, anchor, tag, plain, quoted, style
end