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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7c31636252c684eb2cc7795caec9d106839776b7
4
- data.tar.gz: 2670fd9265acf9c09e9ee3d861c97c48693b8146
3
+ metadata.gz: c1e16fcfcf116bb2445f1d8fb1fc677197da1d8c
4
+ data.tar.gz: '06978e3eb0ed46f22947227102a38bf3e9ab6c41'
5
5
  SHA512:
6
- metadata.gz: 8e22fac36b063ddfda658354fb6876949a9fa5e9c87659fd9a2b46e709c3beb6fd9bf857334c9cbe372629dae6c9c4180ff05aa86e19ec4500ed4b301a8696a7
7
- data.tar.gz: 9959e033efcccb41b2d110ae01633b4a1e602b7bdce44dc21a3a852005c0df9b5ea2f429cddb8ef28cd5c93e47632f8ff7b43b81f31f7009bfb545357ba7dd57
6
+ metadata.gz: 2d60eea98b9281b66ab1e7c92a9ac3c5ac137cb3d756fc25c159e4cf3ddbde84c2139d8727246699c8f354995615043b40e9b48d43eb2ed914520bff52f11c15
7
+ data.tar.gz: 8a6bdda64bded3126bdc64cbbe8e38b62c6d86721cb2902cce97b03a6a49216de76971164cfc57da0da63bd4ae54d10ace59264920997e0e7d67d4f253d16fd5
data/.travis.yml CHANGED
@@ -3,7 +3,7 @@ rvm:
3
3
  - 2.1
4
4
  - 2.2
5
5
  - 2.3.3
6
- - 2.4.0
6
+ - 2.4.2
7
7
  - ruby-head
8
8
  - jruby-head
9
9
  sudo: false
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.10.0
1
+ 0.11.0
@@ -1,24 +1,24 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: complex_config 0.10.0 ruby lib
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.10.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-02-02"
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.8".freeze
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
@@ -10,4 +10,5 @@ require 'complex_config/settings'
10
10
  require 'complex_config/config'
11
11
  require 'complex_config/provider/shortcuts'
12
12
  require 'complex_config/provider'
13
+ require 'complex_config/encryption'
13
14
  defined? Rails and require 'complex_config/railtie'
@@ -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
- result = evaluate(pathname)
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
+
@@ -1,6 +1,6 @@
1
1
  module ComplexConfig
2
2
  # ComplexConfig version
3
- VERSION = '0.10.0'
3
+ VERSION = '0.11.0'
4
4
  VERSION_ARRAY = VERSION.split('.').map(&:to_i) # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
@@ -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.10.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-02-02 00:00:00.000000000 Z
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.8
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