Sha256: d6e7d54e79e6ced4dbc8192f411a31c5c9a74565016789b9123ea57cdcbad716
Contents?: true
Size: 1.11 KB
Versions: 1
Compression:
Stored size: 1.11 KB
Contents
require "muchkeys/version" require "muchkeys/errors" require "net/http" module MuchKeys class << self attr_accessor :configuration end def self.configure @configuration ||= Configuration.new yield(configuration) end def self.default_configure configure do end end class Configuration attr_accessor :consul_host # sensible defaults def initialize @consul_host = 'http://localhost:8500' end end def self.fetch_key(key_name) default_configure if !configuration return ENV[key_name] unless ENV[key_name].nil? response = Net::HTTP.get_response(URI(consul_url(key_name))) handle_response(response) fetch_body(response) end def self.consul_url(key_name) converted_key_name = convert_keyname(key_name) "#{configuration.consul_host}/v1/kv/#{converted_key_name}?raw" end def self.fetch_body(response) response.body end def self.handle_response(response_code) case response_code when (400..599) raise MuchKeys::InvalidKey end end def self.convert_keyname(key_name) key_name.gsub('___', '/') end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
muchkeys-0.0.1 | lib/muchkeys.rb |