complex_config 0.10.0 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/VERSION +1 -1
- data/complex_config.gemspec +7 -7
- data/lib/complex_config.rb +1 -0
- data/lib/complex_config/encryption.rb +58 -0
- data/lib/complex_config/provider.rb +34 -3
- data/lib/complex_config/version.rb +1 -1
- data/spec/complex_config/encryption_spec.rb +27 -0
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c1e16fcfcf116bb2445f1d8fb1fc677197da1d8c
|
4
|
+
data.tar.gz: '06978e3eb0ed46f22947227102a38bf3e9ab6c41'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d60eea98b9281b66ab1e7c92a9ac3c5ac137cb3d756fc25c159e4cf3ddbde84c2139d8727246699c8f354995615043b40e9b48d43eb2ed914520bff52f11c15
|
7
|
+
data.tar.gz: 8a6bdda64bded3126bdc64cbbe8e38b62c6d86721cb2902cce97b03a6a49216de76971164cfc57da0da63bd4ae54d10ace59264920997e0e7d67d4f253d16fd5
|
data/.travis.yml
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.11.0
|
data/complex_config.gemspec
CHANGED
@@ -1,24 +1,24 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: complex_config 0.
|
2
|
+
# stub: complex_config 0.11.0 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "complex_config".freeze
|
6
|
-
s.version = "0.
|
6
|
+
s.version = "0.11.0"
|
7
7
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
9
9
|
s.require_paths = ["lib".freeze]
|
10
10
|
s.authors = ["Florian Frank".freeze]
|
11
|
-
s.date = "2017-
|
11
|
+
s.date = "2017-10-27"
|
12
12
|
s.description = "This library allows you to access configuration files via a simple interface".freeze
|
13
13
|
s.email = "flori@ping.de".freeze
|
14
|
-
s.extra_rdoc_files = ["README.md".freeze, "lib/complex_config.rb".freeze, "lib/complex_config/config.rb".freeze, "lib/complex_config/errors.rb".freeze, "lib/complex_config/plugins.rb".freeze, "lib/complex_config/plugins/enable.rb".freeze, "lib/complex_config/plugins/money.rb".freeze, "lib/complex_config/plugins/uri.rb".freeze, "lib/complex_config/provider.rb".freeze, "lib/complex_config/provider/shortcuts.rb".freeze, "lib/complex_config/proxy.rb".freeze, "lib/complex_config/railtie.rb".freeze, "lib/complex_config/rude.rb".freeze, "lib/complex_config/settings.rb".freeze, "lib/complex_config/shortcuts.rb".freeze, "lib/complex_config/version.rb".freeze]
|
15
|
-
s.files = [".gitignore".freeze, ".rspec".freeze, ".travis.yml".freeze, ".utilsrc".freeze, "COPYING".freeze, "Gemfile".freeze, "README.md".freeze, "Rakefile".freeze, "TODO.md".freeze, "VERSION".freeze, "complex_config.gemspec".freeze, "config/products.yml".freeze, "lib/complex_config.rb".freeze, "lib/complex_config/config.rb".freeze, "lib/complex_config/errors.rb".freeze, "lib/complex_config/plugins.rb".freeze, "lib/complex_config/plugins/enable.rb".freeze, "lib/complex_config/plugins/money.rb".freeze, "lib/complex_config/plugins/uri.rb".freeze, "lib/complex_config/provider.rb".freeze, "lib/complex_config/provider/shortcuts.rb".freeze, "lib/complex_config/proxy.rb".freeze, "lib/complex_config/railtie.rb".freeze, "lib/complex_config/rude.rb".freeze, "lib/complex_config/settings.rb".freeze, "lib/complex_config/shortcuts.rb".freeze, "lib/complex_config/version.rb".freeze, "spec/complex_config/config_spec.rb".freeze, "spec/complex_config/plugins_spec.rb".freeze, "spec/complex_config/provider_spec.rb".freeze, "spec/complex_config/settings_spec.rb".freeze, "spec/complex_config/shortcuts_spec.rb".freeze, "spec/config/broken_config.yml".freeze, "spec/config/config.yml".freeze, "spec/spec_helper.rb".freeze]
|
14
|
+
s.extra_rdoc_files = ["README.md".freeze, "lib/complex_config.rb".freeze, "lib/complex_config/config.rb".freeze, "lib/complex_config/encryption.rb".freeze, "lib/complex_config/errors.rb".freeze, "lib/complex_config/plugins.rb".freeze, "lib/complex_config/plugins/enable.rb".freeze, "lib/complex_config/plugins/money.rb".freeze, "lib/complex_config/plugins/uri.rb".freeze, "lib/complex_config/provider.rb".freeze, "lib/complex_config/provider/shortcuts.rb".freeze, "lib/complex_config/proxy.rb".freeze, "lib/complex_config/railtie.rb".freeze, "lib/complex_config/rude.rb".freeze, "lib/complex_config/settings.rb".freeze, "lib/complex_config/shortcuts.rb".freeze, "lib/complex_config/version.rb".freeze]
|
15
|
+
s.files = [".gitignore".freeze, ".rspec".freeze, ".travis.yml".freeze, ".utilsrc".freeze, "COPYING".freeze, "Gemfile".freeze, "README.md".freeze, "Rakefile".freeze, "TODO.md".freeze, "VERSION".freeze, "complex_config.gemspec".freeze, "config/products.yml".freeze, "lib/complex_config.rb".freeze, "lib/complex_config/config.rb".freeze, "lib/complex_config/encryption.rb".freeze, "lib/complex_config/errors.rb".freeze, "lib/complex_config/plugins.rb".freeze, "lib/complex_config/plugins/enable.rb".freeze, "lib/complex_config/plugins/money.rb".freeze, "lib/complex_config/plugins/uri.rb".freeze, "lib/complex_config/provider.rb".freeze, "lib/complex_config/provider/shortcuts.rb".freeze, "lib/complex_config/proxy.rb".freeze, "lib/complex_config/railtie.rb".freeze, "lib/complex_config/rude.rb".freeze, "lib/complex_config/settings.rb".freeze, "lib/complex_config/shortcuts.rb".freeze, "lib/complex_config/version.rb".freeze, "spec/complex_config/config_spec.rb".freeze, "spec/complex_config/encryption_spec.rb".freeze, "spec/complex_config/plugins_spec.rb".freeze, "spec/complex_config/provider_spec.rb".freeze, "spec/complex_config/settings_spec.rb".freeze, "spec/complex_config/shortcuts_spec.rb".freeze, "spec/config/broken_config.yml".freeze, "spec/config/config.yml".freeze, "spec/spec_helper.rb".freeze]
|
16
16
|
s.homepage = "https://github.com/flori/complex_config".freeze
|
17
17
|
s.licenses = ["Apache-2.0".freeze]
|
18
18
|
s.rdoc_options = ["--title".freeze, "ComplexConfig -- configuration library".freeze, "--main".freeze, "README.md".freeze]
|
19
|
-
s.rubygems_version = "2.6.
|
19
|
+
s.rubygems_version = "2.6.13".freeze
|
20
20
|
s.summary = "configuration library".freeze
|
21
|
-
s.test_files = ["spec/complex_config/config_spec.rb".freeze, "spec/complex_config/plugins_spec.rb".freeze, "spec/complex_config/provider_spec.rb".freeze, "spec/complex_config/settings_spec.rb".freeze, "spec/complex_config/shortcuts_spec.rb".freeze, "spec/spec_helper.rb".freeze]
|
21
|
+
s.test_files = ["spec/complex_config/config_spec.rb".freeze, "spec/complex_config/encryption_spec.rb".freeze, "spec/complex_config/plugins_spec.rb".freeze, "spec/complex_config/provider_spec.rb".freeze, "spec/complex_config/settings_spec.rb".freeze, "spec/complex_config/shortcuts_spec.rb".freeze, "spec/spec_helper.rb".freeze]
|
22
22
|
|
23
23
|
if s.respond_to? :specification_version then
|
24
24
|
s.specification_version = 4
|
data/lib/complex_config.rb
CHANGED
@@ -0,0 +1,58 @@
|
|
1
|
+
require "openssl"
|
2
|
+
require "base64"
|
3
|
+
|
4
|
+
class ComplexConfig::Encryption
|
5
|
+
class EncryptionError < StandardError; end
|
6
|
+
|
7
|
+
class DecryptionFailed < EncryptionError; end
|
8
|
+
|
9
|
+
def initialize(secret)
|
10
|
+
@secret = secret
|
11
|
+
@cipher = OpenSSL::Cipher.new('aes-128-gcm')
|
12
|
+
end
|
13
|
+
|
14
|
+
def encrypt(text)
|
15
|
+
|
16
|
+
@cipher.encrypt
|
17
|
+
@cipher.key = @secret
|
18
|
+
iv = @cipher.random_iv
|
19
|
+
@cipher.auth_data = ""
|
20
|
+
|
21
|
+
encrypted = @cipher.update(Marshal.dump(text))
|
22
|
+
encrypted << @cipher.final
|
23
|
+
|
24
|
+
[
|
25
|
+
encrypted,
|
26
|
+
iv,
|
27
|
+
@cipher.auth_tag
|
28
|
+
].map { |v| base64_encode(v) }.join('--')
|
29
|
+
end
|
30
|
+
|
31
|
+
def decrypt(text)
|
32
|
+
encrypted, iv, auth_tag = text.split('--').map { |v| base64_decode(v) }
|
33
|
+
|
34
|
+
auth_tag.nil? || auth_tag.bytes.length != 16 and
|
35
|
+
raise DecryptionFailed, "auth_tag #{auth_tag.inspect} invalid"
|
36
|
+
|
37
|
+
@cipher.decrypt
|
38
|
+
@cipher.key = @secret
|
39
|
+
@cipher.iv = iv
|
40
|
+
@cipher.auth_tag = auth_tag
|
41
|
+
@cipher.auth_data = ""
|
42
|
+
|
43
|
+
decrypted_data = @cipher.update(encrypted)
|
44
|
+
decrypted_data << @cipher.final
|
45
|
+
|
46
|
+
Marshal.load(decrypted_data)
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def base64_encode(x)
|
52
|
+
::Base64.strict_encode64(x)
|
53
|
+
end
|
54
|
+
|
55
|
+
def base64_decode(x)
|
56
|
+
::Base64.strict_decode64(x)
|
57
|
+
end
|
58
|
+
end
|
@@ -57,7 +57,16 @@ class ComplexConfig::Provider
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def config(pathname, name = nil)
|
60
|
-
|
60
|
+
data =
|
61
|
+
if enc_pathname = pathname.to_s + '.enc' and File.exist?(enc_pathname)
|
62
|
+
key = key(pathname)
|
63
|
+
text = IO.binread(enc_pathname)
|
64
|
+
# TODO merge with pathname w/o .enc
|
65
|
+
ComplexConfig::Encryption.new(key).decrypt(text)
|
66
|
+
else
|
67
|
+
IO.binread(pathname)
|
68
|
+
end
|
69
|
+
result = evaluate(pathname, data)
|
61
70
|
hash = ::YAML.load(result, pathname)
|
62
71
|
ComplexConfig::Settings.build(name, hash).tap do |settings|
|
63
72
|
deep_freeze? and settings.deep_freeze
|
@@ -89,8 +98,7 @@ class ComplexConfig::Provider
|
|
89
98
|
self
|
90
99
|
end
|
91
100
|
|
92
|
-
def evaluate(pathname)
|
93
|
-
data = File.read pathname
|
101
|
+
def evaluate(pathname, data)
|
94
102
|
erb = ::ERB.new(data)
|
95
103
|
erb.filename = pathname.to_s
|
96
104
|
erb.result
|
@@ -101,4 +109,27 @@ class ComplexConfig::Provider
|
|
101
109
|
end
|
102
110
|
|
103
111
|
attr_writer :env
|
112
|
+
|
113
|
+
def key(pathname = nil)
|
114
|
+
key = [
|
115
|
+
@key,
|
116
|
+
read_key_from_file(pathname),
|
117
|
+
ENV['RAILS_MASTER_KEY']
|
118
|
+
].compact[0, 1]
|
119
|
+
unless key.empty?
|
120
|
+
key.pack('H*')
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
attr_writer :key
|
125
|
+
|
126
|
+
private
|
127
|
+
|
128
|
+
def read_key_from_file(pathname)
|
129
|
+
if pathname
|
130
|
+
IO.binread(pathname.to_s + '.key')
|
131
|
+
end
|
132
|
+
rescue Errno::ENOENT
|
133
|
+
end
|
104
134
|
end
|
135
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe ComplexConfig::Encryption do
|
4
|
+
let :secret do
|
5
|
+
"\x1A8\x9E\xA8\xC2\x7F@@6\xB2W\a\x9A)\xCDw"
|
6
|
+
end
|
7
|
+
|
8
|
+
let :value do
|
9
|
+
Marshal.dump('foobar')
|
10
|
+
end
|
11
|
+
|
12
|
+
let :enc do
|
13
|
+
described_class.new secret
|
14
|
+
end
|
15
|
+
|
16
|
+
let :encrypted do
|
17
|
+
"3uAULzmKjJGIWuFeEK+fORPAMPs=--BhH9oIkxoDiOlyLK--Ni5r+QtO9EYcDd7HlYd3Yw=="
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'can encrypt' do
|
21
|
+
expect(enc.encrypt(value)).to match /\A.+--.+--.+==\z/
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'can decrypt' do
|
25
|
+
expect(enc.decrypt(encrypted)).to eq value
|
26
|
+
end
|
27
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: complex_config
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florian Frank
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-10-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gem_hadar
|
@@ -130,6 +130,7 @@ extra_rdoc_files:
|
|
130
130
|
- README.md
|
131
131
|
- lib/complex_config.rb
|
132
132
|
- lib/complex_config/config.rb
|
133
|
+
- lib/complex_config/encryption.rb
|
133
134
|
- lib/complex_config/errors.rb
|
134
135
|
- lib/complex_config/plugins.rb
|
135
136
|
- lib/complex_config/plugins/enable.rb
|
@@ -158,6 +159,7 @@ files:
|
|
158
159
|
- config/products.yml
|
159
160
|
- lib/complex_config.rb
|
160
161
|
- lib/complex_config/config.rb
|
162
|
+
- lib/complex_config/encryption.rb
|
161
163
|
- lib/complex_config/errors.rb
|
162
164
|
- lib/complex_config/plugins.rb
|
163
165
|
- lib/complex_config/plugins/enable.rb
|
@@ -172,6 +174,7 @@ files:
|
|
172
174
|
- lib/complex_config/shortcuts.rb
|
173
175
|
- lib/complex_config/version.rb
|
174
176
|
- spec/complex_config/config_spec.rb
|
177
|
+
- spec/complex_config/encryption_spec.rb
|
175
178
|
- spec/complex_config/plugins_spec.rb
|
176
179
|
- spec/complex_config/provider_spec.rb
|
177
180
|
- spec/complex_config/settings_spec.rb
|
@@ -203,12 +206,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
203
206
|
version: '0'
|
204
207
|
requirements: []
|
205
208
|
rubyforge_project:
|
206
|
-
rubygems_version: 2.6.
|
209
|
+
rubygems_version: 2.6.13
|
207
210
|
signing_key:
|
208
211
|
specification_version: 4
|
209
212
|
summary: configuration library
|
210
213
|
test_files:
|
211
214
|
- spec/complex_config/config_spec.rb
|
215
|
+
- spec/complex_config/encryption_spec.rb
|
212
216
|
- spec/complex_config/plugins_spec.rb
|
213
217
|
- spec/complex_config/provider_spec.rb
|
214
218
|
- spec/complex_config/settings_spec.rb
|