Sha256: 2ce3e9e428864f19a1513bf71e56364b034546e684f2b64f442bd19e107a039f

Contents?: true

Size: 932 Bytes

Versions: 4

Compression:

Stored size: 932 Bytes

Contents

module Foreplay
  class Engine
    class Secrets
      attr_reader :environment, :secret_locations

      def initialize(e, sl)
        @environment = e
        @secret_locations = sl
      end

      def fetch
        return unless secret_locations

        secrets = {}

        secret_locations.each do |secret_location|
          secrets.merge! fetch_from(secret_location) || {}
        end

        secrets
      end

      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
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
foreplay-0.11.0 lib/foreplay/engine/secrets.rb
foreplay-0.10.3 lib/foreplay/engine/secrets.rb
foreplay-0.10.2 lib/foreplay/engine/secrets.rb
foreplay-0.10.1 lib/foreplay/engine/secrets.rb