complex_config 0.13.1 → 0.13.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/VERSION +1 -1
- data/complex_config.gemspec +7 -7
- data/lib/complex_config.rb +1 -0
- data/lib/complex_config/key_source.rb +33 -0
- data/lib/complex_config/provider.rb +47 -52
- data/lib/complex_config/proxy.rb +2 -4
- data/lib/complex_config/version.rb +1 -1
- data/spec/complex_config/key_source_spec.rb +36 -0
- data/spec/complex_config/provider_spec.rb +25 -2
- data/spec/complex_config/settings_spec.rb +10 -0
- data/spec/complex_config/shortcuts_spec.rb +7 -0
- data/spec/config/config.yml +3 -0
- data/spec/config/master.key +1 -0
- metadata +8 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 6801d4be41f9717643e5d2c8c3a6579fe2f74af9
|
|
4
|
+
data.tar.gz: 15c87e5fccfe600f5e775d996feac8ee5c6c174e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 578bc404bf7d30fd04865fc0855c719e6f9285d0e7031bf9040b66a3be8667ae4ed5850902e86fe8a77b517851b7cca90423907aca6de1e75d1bbf9f963e8b4f
|
|
7
|
+
data.tar.gz: 52b81ccae832406d4cfd652baff4434c5a72ecb6cfd884edcabe899ad6755b220a2cbf3dd56ccc20570ea43f2fc2840bfde462e8b110f905d4460eb4ae4b5c3c
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.13.
|
|
1
|
+
0.13.2
|
data/complex_config.gemspec
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
|
2
|
-
# stub: complex_config 0.13.
|
|
2
|
+
# stub: complex_config 0.13.2 ruby lib
|
|
3
3
|
|
|
4
4
|
Gem::Specification.new do |s|
|
|
5
5
|
s.name = "complex_config".freeze
|
|
6
|
-
s.version = "0.13.
|
|
6
|
+
s.version = "0.13.2"
|
|
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 = "2018-02-
|
|
11
|
+
s.date = "2018-02-23"
|
|
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/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/config/with-key-file.yml.enc".freeze, "spec/config/with-key-file.yml.key".freeze, "spec/config/without-key-file.yml.enc".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/key_source.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/key_source.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/key_source_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/config/master.key".freeze, "spec/config/with-key-file.yml.enc".freeze, "spec/config/with-key-file.yml.key".freeze, "spec/config/without-key-file.yml.enc".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.
|
|
19
|
+
s.rubygems_version = "2.6.14".freeze
|
|
20
20
|
s.summary = "configuration library".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]
|
|
21
|
+
s.test_files = ["spec/complex_config/config_spec.rb".freeze, "spec/complex_config/encryption_spec.rb".freeze, "spec/complex_config/key_source_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
|
@@ -8,6 +8,7 @@ require 'complex_config/errors'
|
|
|
8
8
|
require 'complex_config/proxy'
|
|
9
9
|
require 'complex_config/settings'
|
|
10
10
|
require 'complex_config/config'
|
|
11
|
+
require 'complex_config/key_source'
|
|
11
12
|
require 'complex_config/provider/shortcuts'
|
|
12
13
|
require 'complex_config/provider'
|
|
13
14
|
require 'complex_config/encryption'
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
class ComplexConfig::KeySource
|
|
2
|
+
def initialize(pathname: nil, env_var: nil, var: nil, master_key_pathname: nil)
|
|
3
|
+
settings = [ pathname, env_var, var, master_key_pathname ].compact.size
|
|
4
|
+
if settings > 1
|
|
5
|
+
raise ArgumentError, 'only one setting at most possible'
|
|
6
|
+
end
|
|
7
|
+
pathname and pathname = pathname.to_s
|
|
8
|
+
master_key_pathname and master_key_pathname = master_key_pathname.to_s
|
|
9
|
+
@pathname, @env_var, @var, @master_key_pathname =
|
|
10
|
+
pathname, env_var, var, master_key_pathname
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def master_key?
|
|
14
|
+
!!@master_key_pathname
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def key
|
|
18
|
+
if @var
|
|
19
|
+
@var.ask_and_send(:chomp)
|
|
20
|
+
elsif @env_var
|
|
21
|
+
ENV[@env_var].ask_and_send(:chomp)
|
|
22
|
+
elsif master_key?
|
|
23
|
+
IO.binread(@master_key_pathname).chomp
|
|
24
|
+
elsif @pathname
|
|
25
|
+
IO.binread(@pathname + '.key').chomp
|
|
26
|
+
end
|
|
27
|
+
rescue Errno::ENOENT
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def key_bytes
|
|
31
|
+
[ key ].pack('H*')
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -10,8 +10,18 @@ class ComplexConfig::Provider
|
|
|
10
10
|
include ComplexConfig::Provider::Shortcuts
|
|
11
11
|
|
|
12
12
|
def initialize
|
|
13
|
-
@plugins
|
|
14
|
-
@deep_freeze
|
|
13
|
+
@plugins = Set.new
|
|
14
|
+
@deep_freeze = true
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
attr_writer :master_key_pathname
|
|
18
|
+
|
|
19
|
+
def master_key_pathname
|
|
20
|
+
if @master_key_pathname
|
|
21
|
+
@master_key_pathname
|
|
22
|
+
else
|
|
23
|
+
config_dir + 'master.key'
|
|
24
|
+
end
|
|
15
25
|
end
|
|
16
26
|
|
|
17
27
|
def configure_with(config)
|
|
@@ -67,12 +77,11 @@ class ComplexConfig::Provider
|
|
|
67
77
|
if File.exist?(pathname)
|
|
68
78
|
datas << IO.binread(pathname)
|
|
69
79
|
end
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
then
|
|
80
|
+
enc_pathname = pathname.to_s + '.enc'
|
|
81
|
+
my_ks = key_source(pathname)
|
|
82
|
+
if File.exist?(enc_pathname) && my_ks.ask_and_send(:key)
|
|
74
83
|
text = IO.binread(enc_pathname)
|
|
75
|
-
datas << ComplexConfig::Encryption.new(
|
|
84
|
+
datas << ComplexConfig::Encryption.new(my_ks.key_bytes).decrypt(text)
|
|
76
85
|
end
|
|
77
86
|
datas.empty? and raise ComplexConfig::ConfigurationFileMissing,
|
|
78
87
|
"configuration file #{pathname.to_s.inspect} is missing"
|
|
@@ -103,17 +112,16 @@ class ComplexConfig::Provider
|
|
|
103
112
|
name, value = interpret_name_value(name, value)
|
|
104
113
|
config_pathname = pathname(name).to_s
|
|
105
114
|
if encrypt
|
|
106
|
-
|
|
107
|
-
kb = key_to_bytes(key)
|
|
115
|
+
ks = provide_key_source(config_pathname, encrypt)
|
|
108
116
|
File.secure_write(config_pathname + '.enc') do |out|
|
|
109
|
-
out.write ComplexConfig::Encryption.new(
|
|
117
|
+
out.write ComplexConfig::Encryption.new(ks.key_bytes).encrypt(prepare_output(value))
|
|
110
118
|
end
|
|
111
119
|
if store_key
|
|
112
120
|
File.secure_write(config_pathname + '.key') do |out|
|
|
113
|
-
out.write key
|
|
121
|
+
out.write ks.key
|
|
114
122
|
end
|
|
115
123
|
end
|
|
116
|
-
key
|
|
124
|
+
ks.key
|
|
117
125
|
else
|
|
118
126
|
File.secure_write(config_pathname) do |out|
|
|
119
127
|
out.puts prepare_output(value)
|
|
@@ -158,26 +166,24 @@ class ComplexConfig::Provider
|
|
|
158
166
|
|
|
159
167
|
attr_writer :env
|
|
160
168
|
|
|
161
|
-
def
|
|
169
|
+
def key_source(pathname = nil)
|
|
162
170
|
[
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
171
|
+
ComplexConfig::KeySource.new(pathname: pathname),
|
|
172
|
+
ComplexConfig::KeySource.new(var: @key),
|
|
173
|
+
ComplexConfig::KeySource.new(env_var: 'COMPLEX_CONFIG_KEY'),
|
|
174
|
+
ComplexConfig::KeySource.new(env_var: 'RAILS_MASTER_KEY'),
|
|
175
|
+
ComplexConfig::KeySource.new(master_key_pathname: master_key_pathname),
|
|
176
|
+
].find(&:key)
|
|
168
177
|
end
|
|
169
178
|
|
|
170
|
-
def
|
|
171
|
-
|
|
172
|
-
key_to_bytes(k)
|
|
173
|
-
else
|
|
174
|
-
warn "encryption key is missing for #{pathname.to_s.inspect} => Ignoring it!"
|
|
175
|
-
nil
|
|
176
|
-
end
|
|
179
|
+
def key(pathname = nil)
|
|
180
|
+
key_source(pathname).ask_and_send(:key)
|
|
177
181
|
end
|
|
178
182
|
|
|
179
183
|
attr_writer :key
|
|
180
184
|
|
|
185
|
+
attr_writer :master_key_pathname
|
|
186
|
+
|
|
181
187
|
private
|
|
182
188
|
|
|
183
189
|
def interpret_name_value(name, value)
|
|
@@ -196,33 +202,22 @@ class ComplexConfig::Provider
|
|
|
196
202
|
return name, value
|
|
197
203
|
end
|
|
198
204
|
|
|
199
|
-
def
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
encrypt
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
205
|
+
def provide_key_source(pathname, encrypt)
|
|
206
|
+
ks =
|
|
207
|
+
case encrypt
|
|
208
|
+
when :random
|
|
209
|
+
ComplexConfig::KeySource.new(var: SecureRandom.hex(16))
|
|
210
|
+
when true
|
|
211
|
+
key_source(pathname)
|
|
212
|
+
when String
|
|
213
|
+
if encrypt =~ /\A\h{32}\z/
|
|
214
|
+
ComplexConfig::KeySource.new(var: encrypt)
|
|
215
|
+
else
|
|
216
|
+
raise ComplexConfig::EncryptionKeyInvalid,
|
|
217
|
+
"encryption key has wrong format, has to be hex number of length "\
|
|
218
|
+
"32, was #{encrypt.inspect}"
|
|
219
|
+
end
|
|
212
220
|
end
|
|
213
|
-
|
|
214
|
-
key or raise ComplexConfig::EncryptionKeyInvalid, "encryption key is missing"
|
|
215
|
-
end
|
|
216
|
-
|
|
217
|
-
def key_to_bytes(key)
|
|
218
|
-
[ key ].pack('H*')
|
|
219
|
-
end
|
|
220
|
-
|
|
221
|
-
def read_key_from_file(pathname)
|
|
222
|
-
if pathname
|
|
223
|
-
IO.binread(pathname.to_s + '.key')
|
|
224
|
-
end
|
|
225
|
-
rescue Errno::ENOENT
|
|
221
|
+
ks or raise ComplexConfig::EncryptionKeyInvalid, "encryption key is missing"
|
|
226
222
|
end
|
|
227
223
|
end
|
|
228
|
-
|
data/lib/complex_config/proxy.rb
CHANGED
|
@@ -35,10 +35,8 @@ module ComplexConfig
|
|
|
35
35
|
config = ::ComplexConfig::Provider[name]
|
|
36
36
|
(class << self; self; end).class_eval do
|
|
37
37
|
define_method(name) do |env = nil|
|
|
38
|
-
if env
|
|
39
|
-
config[env]
|
|
40
|
-
elsif @env
|
|
41
|
-
config[@env]
|
|
38
|
+
if env ||= @env
|
|
39
|
+
config[env] || ::ComplexConfig::Settings.new
|
|
42
40
|
else
|
|
43
41
|
config
|
|
44
42
|
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
RSpec.describe ComplexConfig::KeySource do
|
|
4
|
+
it 'should provide key from pathname' do
|
|
5
|
+
ks = described_class.new(pathname: asset('with-key-file.yml'))
|
|
6
|
+
expect(ks.key).to eq '90ec1139596f9dfdb51e72277735ce9a'
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it 'should provide key from env_var' do
|
|
10
|
+
ENV['THE_KEY'] = '41424344'
|
|
11
|
+
ks = described_class.new(env_var: 'THE_KEY')
|
|
12
|
+
expect(ks.key_bytes).to eq "ABCD"
|
|
13
|
+
ENV['THE_KEY'] = nil
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it 'should provide key from var' do
|
|
17
|
+
ks = described_class.new(var: 'deadbeef')
|
|
18
|
+
expect(ks.key).to eq 'deadbeef'
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it 'should provide key from master_key_pathname' do
|
|
22
|
+
ks = described_class.new(master_key_pathname: asset('master.key'))
|
|
23
|
+
expect(ks.key).to eq '90ec1139596f9dfdb51e72277735ce9a'
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it 'can return key as bytes' do
|
|
27
|
+
ks = described_class.new(var: '41424344')
|
|
28
|
+
expect(ks.key_bytes).to eq "ABCD"
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it 'cannot use more than one setting' do
|
|
32
|
+
expect {
|
|
33
|
+
described_class.new(var: 'deadbeef', env_var: 'FOO')
|
|
34
|
+
}.to raise_error ArgumentError
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -69,6 +69,16 @@ RSpec.describe ComplexConfig::Provider do
|
|
|
69
69
|
it 'falls back to current working directory by default' do
|
|
70
70
|
expect(provider.config_dir).to eq Pathname.pwd + 'config'
|
|
71
71
|
end
|
|
72
|
+
|
|
73
|
+
it 'can derive master_key_pathname' do
|
|
74
|
+
expect(provider.master_key_pathname).to eq\
|
|
75
|
+
Pathname.pwd.join('config/master.key')
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
it 'can set master_key_pathname' do
|
|
79
|
+
provider.master_key_pathname = 'foo'
|
|
80
|
+
expect(provider.master_key_pathname).to eq 'foo'
|
|
81
|
+
end
|
|
72
82
|
end
|
|
73
83
|
|
|
74
84
|
context 'reading configurations' do
|
|
@@ -137,6 +147,7 @@ RSpec.describe ComplexConfig::Provider do
|
|
|
137
147
|
|
|
138
148
|
it 'can read when key is set by accessor' do
|
|
139
149
|
provider.key = key
|
|
150
|
+
expect(provider.key).to eq key.chomp
|
|
140
151
|
expect(provider['without-key-file'].development.foo.bar).to eq 'baz'
|
|
141
152
|
end
|
|
142
153
|
|
|
@@ -229,7 +240,7 @@ RSpec.describe ComplexConfig::Provider do
|
|
|
229
240
|
expect {
|
|
230
241
|
expect(provider['config']).to be_a ComplexConfig::Settings
|
|
231
242
|
}.to change {
|
|
232
|
-
provider.instance.__send__(:__mize_cache__).
|
|
243
|
+
provider.instance.__send__(:__mize_cache__).instance_variable_get(:@data).size
|
|
233
244
|
}.by(1)
|
|
234
245
|
expect(provider).not_to receive(:config)
|
|
235
246
|
expect(provider['config']).to be_a ComplexConfig::Settings
|
|
@@ -241,7 +252,7 @@ RSpec.describe ComplexConfig::Provider do
|
|
|
241
252
|
expect {
|
|
242
253
|
result = provider.flush_cache
|
|
243
254
|
}.to change {
|
|
244
|
-
provider.instance.__send__(:__mize_cache__).
|
|
255
|
+
provider.instance.__send__(:__mize_cache__).instance_variable_get(:@data).size
|
|
245
256
|
}.by(-1)
|
|
246
257
|
expect(result).to be_a ComplexConfig::Provider
|
|
247
258
|
end
|
|
@@ -282,5 +293,17 @@ RSpec.describe ComplexConfig::Provider do
|
|
|
282
293
|
it 'falls back to "development" as a default' do
|
|
283
294
|
expect(provider.env).to eq 'development'
|
|
284
295
|
end
|
|
296
|
+
|
|
297
|
+
end
|
|
298
|
+
|
|
299
|
+
context 'shared' do
|
|
300
|
+
before do
|
|
301
|
+
provider.config_dir = Pathname.new(__FILE__).dirname.dirname + 'config'
|
|
302
|
+
end
|
|
303
|
+
|
|
304
|
+
it 'can share values' do
|
|
305
|
+
expect(provider['config'].development.shared).to eq true
|
|
306
|
+
expect(provider['config'].test.shared).to eq true
|
|
307
|
+
end
|
|
285
308
|
end
|
|
286
309
|
end
|
|
@@ -104,6 +104,16 @@ EOT
|
|
|
104
104
|
settings.pretty_print(q)
|
|
105
105
|
end
|
|
106
106
|
|
|
107
|
+
it 'can be converted into YAML' do
|
|
108
|
+
expect(settings.to_yaml).to eq <<EOT
|
|
109
|
+
---
|
|
110
|
+
:foo:
|
|
111
|
+
:bar:
|
|
112
|
+
:baz: true
|
|
113
|
+
:qux: quux
|
|
114
|
+
EOT
|
|
115
|
+
end
|
|
116
|
+
|
|
107
117
|
it 'raises exception if expected attribute is missing' do
|
|
108
118
|
expect { settings.nix }.to raise_error(ComplexConfig::AttributeMissing)
|
|
109
119
|
end
|
|
@@ -8,6 +8,8 @@ RSpec.describe 'shortcuts' do
|
|
|
8
8
|
|
|
9
9
|
before do
|
|
10
10
|
provider.config_dir = Pathname.new(__FILE__).dirname.dirname + 'config'
|
|
11
|
+
allow(ENV).to receive(:[]).with('COMPLEX_CONFIG_KEY')
|
|
12
|
+
allow(ENV).to receive(:[]).with('RAILS_MASTER_KEY')
|
|
11
13
|
allow(ENV).to receive(:[]).with('RAILS_ENV').and_return('development')
|
|
12
14
|
end
|
|
13
15
|
|
|
@@ -37,6 +39,11 @@ RSpec.describe 'shortcuts' do
|
|
|
37
39
|
expect(settings.config.baz).to eq 'something else'
|
|
38
40
|
end
|
|
39
41
|
|
|
42
|
+
it 'complex_config_with_env "shortcut" returns empty settings for non existant envs' do
|
|
43
|
+
settings = complex_config_with_env.config('nix')
|
|
44
|
+
expect(settings).to be_a ComplexConfig::Settings
|
|
45
|
+
end
|
|
46
|
+
|
|
40
47
|
it 'has the alias cc for complex_config_with_env' do
|
|
41
48
|
settings = cc.config(:development)
|
|
42
49
|
expect(settings).to be_a ComplexConfig::Settings
|
data/spec/config/config.yml
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
90ec1139596f9dfdb51e72277735ce9a
|
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.13.
|
|
4
|
+
version: 0.13.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Florian Frank
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2018-02-
|
|
11
|
+
date: 2018-02-23 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: gem_hadar
|
|
@@ -138,6 +138,7 @@ extra_rdoc_files:
|
|
|
138
138
|
- lib/complex_config/config.rb
|
|
139
139
|
- lib/complex_config/encryption.rb
|
|
140
140
|
- lib/complex_config/errors.rb
|
|
141
|
+
- lib/complex_config/key_source.rb
|
|
141
142
|
- lib/complex_config/plugins.rb
|
|
142
143
|
- lib/complex_config/plugins/enable.rb
|
|
143
144
|
- lib/complex_config/plugins/money.rb
|
|
@@ -167,6 +168,7 @@ files:
|
|
|
167
168
|
- lib/complex_config/config.rb
|
|
168
169
|
- lib/complex_config/encryption.rb
|
|
169
170
|
- lib/complex_config/errors.rb
|
|
171
|
+
- lib/complex_config/key_source.rb
|
|
170
172
|
- lib/complex_config/plugins.rb
|
|
171
173
|
- lib/complex_config/plugins/enable.rb
|
|
172
174
|
- lib/complex_config/plugins/money.rb
|
|
@@ -181,12 +183,14 @@ files:
|
|
|
181
183
|
- lib/complex_config/version.rb
|
|
182
184
|
- spec/complex_config/config_spec.rb
|
|
183
185
|
- spec/complex_config/encryption_spec.rb
|
|
186
|
+
- spec/complex_config/key_source_spec.rb
|
|
184
187
|
- spec/complex_config/plugins_spec.rb
|
|
185
188
|
- spec/complex_config/provider_spec.rb
|
|
186
189
|
- spec/complex_config/settings_spec.rb
|
|
187
190
|
- spec/complex_config/shortcuts_spec.rb
|
|
188
191
|
- spec/config/broken_config.yml
|
|
189
192
|
- spec/config/config.yml
|
|
193
|
+
- spec/config/master.key
|
|
190
194
|
- spec/config/with-key-file.yml.enc
|
|
191
195
|
- spec/config/with-key-file.yml.key
|
|
192
196
|
- spec/config/without-key-file.yml.enc
|
|
@@ -215,13 +219,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
215
219
|
version: '0'
|
|
216
220
|
requirements: []
|
|
217
221
|
rubyforge_project:
|
|
218
|
-
rubygems_version: 2.
|
|
222
|
+
rubygems_version: 2.6.14
|
|
219
223
|
signing_key:
|
|
220
224
|
specification_version: 4
|
|
221
225
|
summary: configuration library
|
|
222
226
|
test_files:
|
|
223
227
|
- spec/complex_config/config_spec.rb
|
|
224
228
|
- spec/complex_config/encryption_spec.rb
|
|
229
|
+
- spec/complex_config/key_source_spec.rb
|
|
225
230
|
- spec/complex_config/plugins_spec.rb
|
|
226
231
|
- spec/complex_config/provider_spec.rb
|
|
227
232
|
- spec/complex_config/settings_spec.rb
|