Class: Escher::Keypool
- Inherits:
-
Object
- Object
- Escher::Keypool
- Defined in:
- lib/escher-keypool.rb,
lib/escher/version.rb
Constant Summary collapse
- VERSION =
'0.0.1'
Instance Method Summary collapse
- #get_active_key(service_id) ⇒ Object
- #get_key_db ⇒ Object
-
#initialize ⇒ Keypool
constructor
A new instance of Keypool.
Constructor Details
#initialize ⇒ Keypool
Returns a new instance of Keypool.
8 9 10 |
# File 'lib/escher-keypool.rb', line 8 def initialize @keys = JSON.parse(ENV['KEY_POOL']) end |
Instance Method Details
#get_active_key(service_id) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/escher-keypool.rb', line 14 def get_active_key(service_id) key_id_env_key = service_id.upcase + '_KEYID' key_id = ENV[key_id_env_key] if not key_id raise "the " + key_id_env_key + " environment variable is not found" end service_keys = @keys.select { |key| key['keyId'].start_with?(key_id) } if service_keys.length == 0 raise "key not found for " + service_id end candidate_keys = service_keys.select { |key| key['acceptOnly'] == 0 } if candidate_keys.length == 0 raise "active key not found for " + service_id end if candidate_keys.length > 1 raise "ambigous active key for " + service_id end { api_key_id: candidate_keys[0]['keyId'], api_secret: candidate_keys[0]['secret'] } end |
#get_key_db ⇒ Object
40 41 42 |
# File 'lib/escher-keypool.rb', line 40 def get_key_db Hash[@keys.collect { |key| [key['keyId'], key['secret']] }] end |