Class: Foreplay::Engine::Secrets
- Inherits:
-
Object
- Object
- Foreplay::Engine::Secrets
- Defined in:
- lib/foreplay/engine/secrets.rb
Instance Attribute Summary collapse
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#secret_locations ⇒ Object
readonly
Returns the value of attribute secret_locations.
Instance Method Summary collapse
- #fetch ⇒ Object
- #fetch_from(secret_location) ⇒ Object
-
#initialize(e, sl) ⇒ Secrets
constructor
A new instance of Secrets.
Constructor Details
#initialize(e, sl) ⇒ Secrets
Returns a new instance of Secrets.
4 5 6 7 |
# File 'lib/foreplay/engine/secrets.rb', line 4 def initialize(e, sl) @environment = e @secret_locations = sl end |
Instance Attribute Details
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
2 3 4 |
# File 'lib/foreplay/engine/secrets.rb', line 2 def environment @environment end |
#secret_locations ⇒ Object (readonly)
Returns the value of attribute secret_locations.
2 3 4 |
# File 'lib/foreplay/engine/secrets.rb', line 2 def secret_locations @secret_locations end |
Instance Method Details
#fetch ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/foreplay/engine/secrets.rb', line 9 def fetch return unless secret_locations secrets = {} secret_locations.each do |secret_location| secrets.merge! fetch_from(secret_location) || {} end secrets end |
#fetch_from(secret_location) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/foreplay/engine/secrets.rb', line 21 def fetch_from(secret_location) url = secret_location['url'] || return headers = secret_location['headers'] header_string = headers.map { |k, v| " -H \"#{k}: #{v}\"" }.join if headers.is_a? Hash command = "curl -k -L#{header_string} #{url}".fake_erb secrets_all = YAML.load(`#{command}`) secrets = secrets_all[environment] secrets if secrets.is_a? Hash rescue Psych::SyntaxError nil end |