secret_env 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7323742d6e6c066b4c0239a3149a548498d82fa1
4
- data.tar.gz: 418b98c1383ebd67311dafe21232fe7e4069f6e5
3
+ metadata.gz: a02b5d85e950560098176589728877803dd512e2
4
+ data.tar.gz: 896fe3bc426152e9d93299bf6c8991ab86a6ceb7
5
5
  SHA512:
6
- metadata.gz: b6c9cc0d8615845abcfef44eb754e50d086b84d1a8f80d91a75e563af0e58f2ec9ab2baa598ab149e3e29a7b2d2c06764d199d0ce4aefb9ae9386529d018cb11
7
- data.tar.gz: ebb1ab0278300772720a5a9ec1538bbb316676971e6049d469dddbccaee8faea109e8467a500cc8055d5f50275291002d64d613ffee61f4d9f760648413d8221
6
+ metadata.gz: b457194a957371ae0de8e5b330543cdde6489037b5ff346516efe0582d5597ca68ba4076b121b07ea66b44d2e32d7b6493456fd5b6a00c52a353f2c5cda064ef
7
+ data.tar.gz: 76034dc4e5f49c1d9b6b1dd9914e8faa134773eb22a07be9aeb949db182797ab805743f70a2e75bb57ed6871efef617c93fd650b02de7da53d722516229858df
@@ -1,3 +1,3 @@
1
1
  module SecretEnv
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
data/lib/secret_env.rb CHANGED
@@ -10,19 +10,27 @@ module SecretEnv
10
10
 
11
11
  storage = Storage.setup(config['storage'])
12
12
 
13
+ env_map = {}
13
14
  Array(config.fetch('env')).each do |key, raw_value|
14
- record = Record.new(key: key, raw_value: raw_value, storage: storage)
15
- ENV[record.key] = record.value
15
+ record = Record.new(key: key, raw_value: raw_value, storage: storage, dependency: env_map)
16
+ env_map[record.key] = record
17
+ end
18
+
19
+ env_map.each do |key, record|
20
+ unless ENV.has_key?(record.key)
21
+ ENV[record.key] = record.value
22
+ end
16
23
  end
17
24
  end
18
25
 
19
26
  class Record
20
27
  attr_reader :key
21
28
 
22
- def initialize(key:, raw_value:, storage: Storage::Plain.new)
29
+ def initialize(key:, raw_value:, storage: Storage::Plain.new, dependency: {})
23
30
  @key = key
24
31
  @raw_value = raw_value
25
32
  @storage = storage
33
+ @dependency = dependency
26
34
  end
27
35
 
28
36
  def value
@@ -30,13 +38,27 @@ module SecretEnv
30
38
  parts = []
31
39
  while part = scanner.scan_until(/#\{(.*?)\}/)
32
40
  secret_key = scanner.matched[2..-2] # Extract "secret" from "\#{secret}"
33
- secret = @storage.retrieve(secret_key)
41
+
42
+
43
+ secret = case
44
+ when ENV.has_key?(secret_key)
45
+ ENV[secret_key]
46
+ when @dependency.has_key?(secret_key)
47
+ # FIXME this code may cause infinite loop
48
+ @dependency[secret_key].value
49
+ else
50
+ @storage.retrieve(secret_key)
51
+ end
52
+
53
+ raise SecretEnv::KeyNotFound unless secret
34
54
  parts << part.gsub(scanner.matched, secret)
35
55
  end
36
56
  parts << scanner.rest
37
57
  parts.join
38
58
  end
39
59
  end
60
+
61
+ class KeyNotFound < StandardError; end
40
62
  end
41
63
 
42
64
  require 'secret_env/rails' if defined?(Rails)
data/secret_env.gemspec CHANGED
@@ -21,5 +21,5 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "bundler", "~> 1.12"
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
23
  spec.add_development_dependency "rspec", "~> 3.0"
24
- spec.add_development_dependency "rcredstash"
24
+ spec.add_development_dependency "rcredstash", ">= 0.3.0"
25
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: secret_env
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - adorechic
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-06-15 00:00:00.000000000 Z
11
+ date: 2016-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: 0.3.0
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: 0.3.0
69
69
  description: SecretEnv retrieves secrets and export to ENV
70
70
  email:
71
71
  - adorechic@gmail.com
@@ -114,4 +114,3 @@ signing_key:
114
114
  specification_version: 4
115
115
  summary: SecretEnv retrieves secrets and export to ENV
116
116
  test_files: []
117
- has_rdoc: