escher-keypool 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/escher-keypool.rb +46 -0
- data/lib/escher/version.rb +5 -0
- metadata +46 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 68dd8f30908e38416e18d4a8693e240b54b39374
|
4
|
+
data.tar.gz: 319f7db3bc7559e14c28db9fcc805f8eb827c223
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3f0a33cb0fad7e82925f3181e3a73b047bf76595a3d6cb9a6bdc542a76c8c24060ef95d7b8e58b1f9ca4790ab403b831f596954587640c701111ba513bb8dd56
|
7
|
+
data.tar.gz: ae4252e9a25dbf2b325029f96e2a747d4995f6d475ca43fe703174eb424ab0908539a4612953dfa2ba83a9e40919e83ee5433418980f96669b28ce84e347d5a3
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require "escher/version"
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Escher
|
5
|
+
class Keypool
|
6
|
+
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@keys = JSON.parse(ENV['KEY_POOL'])
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
def get_active_key(service_id)
|
15
|
+
key_id_env_key = service_id.upcase + '_KEYID'
|
16
|
+
key_id = ENV[key_id_env_key]
|
17
|
+
|
18
|
+
if not key_id
|
19
|
+
raise "the " + key_id_env_key + " environment variable is not found"
|
20
|
+
end
|
21
|
+
|
22
|
+
service_keys = @keys.select { |key| key['keyId'].start_with?(key_id) }
|
23
|
+
if service_keys.length == 0
|
24
|
+
raise "key not found for " + service_id
|
25
|
+
end
|
26
|
+
|
27
|
+
candidate_keys = service_keys.select { |key| key['acceptOnly'] == 0 }
|
28
|
+
if candidate_keys.length == 0
|
29
|
+
raise "active key not found for " + service_id
|
30
|
+
end
|
31
|
+
if candidate_keys.length > 1
|
32
|
+
raise "ambigous active key for " + service_id
|
33
|
+
end
|
34
|
+
|
35
|
+
{ api_key_id: candidate_keys[0]['keyId'], api_secret: candidate_keys[0]['secret'] }
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
def get_key_db
|
41
|
+
Hash[@keys.collect { |key| [key['keyId'], key['secret']] }]
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: escher-keypool
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Emarsys
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-17 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Manages keys using environment variables.
|
14
|
+
email:
|
15
|
+
- andras.barthazi@emarsys.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/escher-keypool.rb
|
21
|
+
- lib/escher/version.rb
|
22
|
+
homepage: https://github.com/emartech/escher-keypool-ruby
|
23
|
+
licenses:
|
24
|
+
- MIT
|
25
|
+
metadata: {}
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 2.2.2
|
43
|
+
signing_key:
|
44
|
+
specification_version: 4
|
45
|
+
summary: Keypool for Escher
|
46
|
+
test_files: []
|