secret_env 0.1.0 → 0.2.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: 6b6d038747e564094d9d1efb86fa4498304889b3
4
- data.tar.gz: df4f21fbecfdc383face4429e049d31c9f126b54
3
+ metadata.gz: 7323742d6e6c066b4c0239a3149a548498d82fa1
4
+ data.tar.gz: 418b98c1383ebd67311dafe21232fe7e4069f6e5
5
5
  SHA512:
6
- metadata.gz: af95c81e96ce289d6086f0e75c76df1debe74858c4a9ccb2d25ddaa7921ead9d80f81b34bfc710d5d9607c55c1eb02d645889c6e9c3d436aeac3682e126252f7
7
- data.tar.gz: 76efe372b0cb71548992df198e474360667f98a9a42ebeb2bbed92714a3905986e1e71e325f58dde651139385c008aa1f95cf94ee21e8a6d6be80d2f586cadca
6
+ metadata.gz: b6c9cc0d8615845abcfef44eb754e50d086b84d1a8f80d91a75e563af0e58f2ec9ab2baa598ab149e3e29a7b2d2c06764d199d0ce4aefb9ae9386529d018cb11
7
+ data.tar.gz: ebb1ab0278300772720a5a9ec1538bbb316676971e6049d469dddbccaee8faea109e8467a500cc8055d5f50275291002d64d613ffee61f4d9f760648413d8221
@@ -0,0 +1,56 @@
1
+ module SecretEnv
2
+ module Storage
3
+ class << self
4
+ def setup(config)
5
+ if config
6
+ klass(config.fetch('type')).new(namespace: config['namespace'])
7
+ else
8
+ Storage::Plain.new
9
+ end
10
+ end
11
+
12
+ private
13
+
14
+ def klass(type)
15
+ case type
16
+ when 'plain'
17
+ Storage::Plain
18
+ when 'credstash'
19
+ Storage::CredStash
20
+ else
21
+ raise "Unknown storage type: #{type}"
22
+ end
23
+ end
24
+ end
25
+
26
+ class Base
27
+ attr_reader :namespace
28
+
29
+ def initialize(namespace: '')
30
+ @namespace = namespace
31
+ end
32
+
33
+ def retrieve(secret_key)
34
+ raise NotImplemedError
35
+ end
36
+
37
+ private
38
+
39
+ def full_key(secret_key)
40
+ "#{namespace}#{secret_key}"
41
+ end
42
+ end
43
+
44
+ class Plain < Base
45
+ def retrieve(secret_key)
46
+ "#\{#{full_key(secret_key)}\}"
47
+ end
48
+ end
49
+
50
+ class CredStash < Base
51
+ def retrieve(secret_key)
52
+ ::CredStash.get(full_key(secret_key))
53
+ end
54
+ end
55
+ end
56
+ end
@@ -1,3 +1,3 @@
1
1
  module SecretEnv
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/secret_env.rb CHANGED
@@ -1,4 +1,5 @@
1
- require "secret_env/version"
1
+ require 'secret_env/version'
2
+ require 'secret_env/storage'
2
3
  require 'yaml'
3
4
 
4
5
  module SecretEnv
@@ -7,18 +8,7 @@ module SecretEnv
7
8
  def self.load(env: 'development')
8
9
  config = YAML.load_file(SECRETS_FILE).fetch(env)
9
10
 
10
- storage = if config['storage']
11
- case config['storage'].fetch('type')
12
- when 'plain'
13
- Storage::Plain.new
14
- when 'credstash'
15
- Storage::CredStash.new
16
- else
17
- raise "Unknown storage type: #{config['storage']['type']}"
18
- end
19
- else
20
- Storage::Plain.new
21
- end
11
+ storage = Storage.setup(config['storage'])
22
12
 
23
13
  Array(config.fetch('env')).each do |key, raw_value|
24
14
  record = Record.new(key: key, raw_value: raw_value, storage: storage)
@@ -43,29 +33,10 @@ module SecretEnv
43
33
  secret = @storage.retrieve(secret_key)
44
34
  parts << part.gsub(scanner.matched, secret)
45
35
  end
36
+ parts << scanner.rest
46
37
  parts.join
47
38
  end
48
39
  end
49
-
50
- module Storage
51
- class Base
52
- def retrieve(secret_key)
53
- raise NotImplemedError
54
- end
55
- end
56
-
57
- class Plain < Base
58
- def retrieve(secret_key)
59
- "#\{#{secret_key}\}"
60
- end
61
- end
62
-
63
- class CredStash < Base
64
- def retrieve(secret_key)
65
- ::CredStash.get(secret_key)
66
- end
67
- end
68
- end
69
40
  end
70
41
 
71
42
  require 'secret_env/rails' if defined?(Rails)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: secret_env
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - adorechic
@@ -86,6 +86,7 @@ files:
86
86
  - exe/secret_env
87
87
  - lib/secret_env.rb
88
88
  - lib/secret_env/rails.rb
89
+ - lib/secret_env/storage.rb
89
90
  - lib/secret_env/version.rb
90
91
  - secret_env.gemspec
91
92
  homepage: