chamber 1.0.3 → 2.0.0
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 +4 -4
- data/README.md +288 -173
- data/bin/chamber +2 -288
- data/lib/chamber.rb +19 -67
- data/lib/chamber/binary/heroku.rb +59 -0
- data/lib/chamber/binary/runner.rb +94 -0
- data/lib/chamber/binary/travis.rb +23 -0
- data/lib/chamber/commands/base.rb +33 -0
- data/lib/chamber/commands/comparable.rb +37 -0
- data/lib/chamber/commands/compare.rb +46 -0
- data/lib/chamber/commands/context_resolver.rb +72 -0
- data/lib/chamber/commands/files.rb +12 -0
- data/lib/chamber/commands/heroku.rb +30 -0
- data/lib/chamber/commands/heroku/clear.rb +25 -0
- data/lib/chamber/commands/heroku/compare.rb +31 -0
- data/lib/chamber/commands/heroku/pull.rb +30 -0
- data/lib/chamber/commands/heroku/push.rb +25 -0
- data/lib/chamber/commands/initialize.rb +73 -0
- data/lib/chamber/commands/securable.rb +48 -0
- data/lib/chamber/commands/secure.rb +16 -0
- data/lib/chamber/commands/show.rb +23 -0
- data/lib/chamber/commands/travis.rb +14 -0
- data/lib/chamber/commands/travis/secure.rb +35 -0
- data/lib/chamber/configuration.rb +34 -0
- data/lib/chamber/environmentable.rb +23 -0
- data/lib/chamber/errors/undecryptable_value_error.rb +6 -0
- data/lib/chamber/file.rb +17 -5
- data/lib/chamber/file_set.rb +18 -12
- data/lib/chamber/filters/boolean_conversion_filter.rb +41 -0
- data/lib/chamber/filters/decryption_filter.rb +69 -0
- data/lib/chamber/filters/encryption_filter.rb +57 -0
- data/lib/chamber/filters/environment_filter.rb +75 -0
- data/lib/chamber/filters/namespace_filter.rb +37 -0
- data/lib/chamber/filters/secure_filter.rb +39 -0
- data/lib/chamber/instance.rb +40 -0
- data/lib/chamber/namespace_set.rb +55 -16
- data/lib/chamber/rails/railtie.rb +1 -1
- data/lib/chamber/settings.rb +103 -42
- data/lib/chamber/system_environment.rb +3 -93
- data/lib/chamber/version.rb +2 -2
- data/spec/fixtures/settings.yml +27 -0
- data/spec/lib/chamber/commands/context_resolver_spec.rb +106 -0
- data/spec/lib/chamber/commands/files_spec.rb +19 -0
- data/spec/lib/chamber/commands/heroku/clear_spec.rb +11 -0
- data/spec/lib/chamber/commands/heroku/compare_spec.rb +11 -0
- data/spec/lib/chamber/commands/heroku/pull_spec.rb +11 -0
- data/spec/lib/chamber/commands/heroku/push_spec.rb +11 -0
- data/spec/lib/chamber/commands/secure_spec.rb +29 -0
- data/spec/lib/chamber/commands/show_spec.rb +43 -0
- data/spec/lib/chamber/file_set_spec.rb +1 -1
- data/spec/lib/chamber/file_spec.rb +32 -9
- data/spec/lib/chamber/filters/boolean_conversion_filter_spec.rb +44 -0
- data/spec/lib/chamber/filters/decryption_filter_spec.rb +55 -0
- data/spec/lib/chamber/filters/encryption_filter_spec.rb +48 -0
- data/spec/lib/chamber/filters/environment_filter_spec.rb +35 -0
- data/spec/lib/chamber/filters/namespace_filter_spec.rb +73 -0
- data/spec/lib/chamber/filters/secure_filter_spec.rb +36 -0
- data/spec/lib/chamber/namespace_set_spec.rb +61 -18
- data/spec/lib/chamber/settings_spec.rb +99 -23
- data/spec/lib/chamber/system_environment_spec.rb +1 -71
- data/spec/lib/chamber_spec.rb +40 -26
- data/spec/rails-2-test/config.ru +0 -0
- data/spec/rails-2-test/config/application.rb +5 -0
- data/spec/rails-2-test/script/console +0 -0
- data/spec/rails-3-test/config.ru +0 -0
- data/spec/rails-3-test/config/application.rb +5 -0
- data/spec/rails-3-test/script/rails +0 -0
- data/spec/rails-4-test/bin/rails +0 -0
- data/spec/rails-4-test/config.ru +0 -0
- data/spec/rails-4-test/config/application.rb +5 -0
- data/spec/spec_key +27 -0
- data/spec/spec_key.pub +9 -0
- metadata +85 -4
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'rspectacular'
|
2
|
+
require 'chamber/filters/secure_filter'
|
3
|
+
|
4
|
+
module Chamber
|
5
|
+
module Filters
|
6
|
+
describe SecureFilter do
|
7
|
+
it 'will return values which are marked as "secure"' do
|
8
|
+
filtered_settings = SecureFilter.execute( data: {
|
9
|
+
_secure_my_secure_setting: 'hello' })
|
10
|
+
|
11
|
+
expect(filtered_settings._secure_my_secure_setting).to match 'hello'
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'will not return values which are not marked as "secure"' do
|
15
|
+
filtered_settings = SecureFilter.execute( data: {
|
16
|
+
my_secure_setting: 'hello' })
|
17
|
+
|
18
|
+
expect(filtered_settings.my_secure_setting).to be_nil
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'will properly return values even if they are mixed and deeply nested' do
|
22
|
+
filtered_settings = SecureFilter.execute( data: {
|
23
|
+
_secure_setting: 'hello',
|
24
|
+
secure_setting: 'goodbye',
|
25
|
+
secure_group: {
|
26
|
+
_secure_nested_setting: 'movie',
|
27
|
+
insecure_nested_setting: 'dinner' }})
|
28
|
+
|
29
|
+
expect(filtered_settings._secure_setting).to eql 'hello'
|
30
|
+
expect(filtered_settings.secure_setting).to be_nil
|
31
|
+
expect(filtered_settings.secure_group._secure_nested_setting).to eql 'movie'
|
32
|
+
expect(filtered_settings.secure_group.insecure_nested_setting).to be_nil
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -1,46 +1,89 @@
|
|
1
1
|
require 'rspectacular'
|
2
2
|
require 'chamber/namespace_set'
|
3
3
|
|
4
|
-
|
4
|
+
module Chamber
|
5
5
|
describe NamespaceSet do
|
6
6
|
it 'can create a set from from a hash' do
|
7
7
|
namespace_set = NamespaceSet.new( environment: :development,
|
8
8
|
hostname: 'my host')
|
9
9
|
|
10
|
-
expect(namespace_set).to eq [
|
10
|
+
expect(namespace_set).to eq ['development', 'my host']
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'can create a set from an array' do
|
14
14
|
namespace_set = NamespaceSet.new([:development,
|
15
15
|
'my host'])
|
16
16
|
|
17
|
-
expect(namespace_set).to eq [
|
17
|
+
expect(namespace_set).to eq ['development', 'my host']
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'can create a set from a set' do
|
21
21
|
original_set = Set[:development, 'my host']
|
22
22
|
namespace_set = NamespaceSet.new(original_set)
|
23
23
|
|
24
|
-
expect(namespace_set).to eq [
|
24
|
+
expect(namespace_set).to eq ['development', 'my host']
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'can create itself using square-bracket notation' do
|
28
|
+
namespace_set = NamespaceSet[:development, 'my host']
|
29
|
+
|
30
|
+
expect(namespace_set).to eq ['development', 'my host']
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'can create itself from another NamespaceSet' do
|
34
|
+
original_set = NamespaceSet[:development, 'my host']
|
35
|
+
namespace_set = NamespaceSet.new(original_set)
|
36
|
+
|
37
|
+
expect(namespace_set).to eq ['development', 'my host']
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'can create itself from a single value' do
|
41
|
+
namespace_set = NamespaceSet.new(:development)
|
42
|
+
|
43
|
+
expect(namespace_set).to eq ['development']
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'when creating itself from another NamespaceSet, it creates a new NamespaceSet' do
|
47
|
+
original_set = NamespaceSet[:development, 'my host']
|
48
|
+
namespace_set = NamespaceSet.new(original_set)
|
49
|
+
|
50
|
+
expect(namespace_set.object_id).not_to eq original_set.object_id
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'when creating itself from another NamespaceSet, it does not nest the NamespaceSets' do
|
54
|
+
original_set = NamespaceSet[:development, 'my host']
|
55
|
+
namespace_set = NamespaceSet.new(original_set)
|
56
|
+
|
57
|
+
expect(namespace_set.send(:raw_namespaces)).not_to be_a NamespaceSet
|
25
58
|
end
|
26
59
|
|
27
60
|
it 'can turn itself into an array' do
|
28
|
-
namespace_set = NamespaceSet
|
61
|
+
namespace_set = NamespaceSet[:development, 'my host']
|
29
62
|
|
30
|
-
expect(namespace_set.to_ary).to eq [
|
31
|
-
expect(namespace_set.to_a).to eq [
|
63
|
+
expect(namespace_set.to_ary).to eq ['development', 'my host']
|
64
|
+
expect(namespace_set.to_a).to eq ['development', 'my host']
|
32
65
|
end
|
33
66
|
|
34
67
|
it 'can combine itself with an array' do
|
35
|
-
namespace_set = NamespaceSet
|
68
|
+
namespace_set = NamespaceSet[:development, 'my host']
|
36
69
|
other_set = Set['other value', 3]
|
70
|
+
|
71
|
+
combined_set = namespace_set + other_set
|
72
|
+
|
73
|
+
expect(combined_set).to eq ['development', 'my host', 'other value', '3']
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'can combine itself with another NamespaceSet' do
|
77
|
+
namespace_set = NamespaceSet[:development, 'my host']
|
78
|
+
other_set = NamespaceSet['other value', 3]
|
79
|
+
|
37
80
|
combined_set = namespace_set + other_set
|
38
81
|
|
39
|
-
expect(combined_set).to eq [
|
82
|
+
expect(combined_set).to eq ['development', 'my host', 'other value', '3']
|
40
83
|
end
|
41
84
|
|
42
85
|
it 'does not modify the set in place if combining with another array' do
|
43
|
-
namespace_set = NamespaceSet
|
86
|
+
namespace_set = NamespaceSet[:development, 'my host']
|
44
87
|
other_set = Set['other value', 3]
|
45
88
|
combined_set = namespace_set + other_set
|
46
89
|
|
@@ -48,32 +91,32 @@ describe NamespaceSet do
|
|
48
91
|
end
|
49
92
|
|
50
93
|
it 'can combine itself with something that can be converted to an array' do
|
51
|
-
namespace_set = NamespaceSet
|
94
|
+
namespace_set = NamespaceSet[:development, 'my host']
|
52
95
|
other_set = (1..3)
|
53
96
|
combined_set = namespace_set + other_set
|
54
97
|
|
55
|
-
expect(combined_set).to eq [
|
98
|
+
expect(combined_set).to eq ['development', 'my host', '1', '2', '3']
|
56
99
|
end
|
57
100
|
|
58
101
|
it 'does not allow duplicate items' do
|
59
|
-
namespace_set = NamespaceSet
|
102
|
+
namespace_set = NamespaceSet[:development, :development]
|
60
103
|
|
61
|
-
expect(namespace_set).to eq [
|
104
|
+
expect(namespace_set).to eq ['development']
|
62
105
|
end
|
63
106
|
|
64
107
|
it 'will process a value by executing it if it is a callable' do
|
65
|
-
namespace_set = NamespaceSet
|
108
|
+
namespace_set = NamespaceSet[ -> { 'callable' } ]
|
66
109
|
|
67
110
|
expect(namespace_set).to eq ['callable']
|
68
111
|
|
69
|
-
namespace_set = NamespaceSet.new(
|
112
|
+
namespace_set = NamespaceSet.new( :my_namespace => -> { 'callable' } )
|
70
113
|
|
71
114
|
expect(namespace_set).to eq ['callable']
|
72
115
|
end
|
73
116
|
|
74
117
|
it 'can compare itself to another NamespaceSet' do
|
75
|
-
namespace_set = NamespaceSet
|
76
|
-
other_namespace_set = NamespaceSet
|
118
|
+
namespace_set = NamespaceSet[:development, :development]
|
119
|
+
other_namespace_set = NamespaceSet[:development, :development]
|
77
120
|
|
78
121
|
expect(namespace_set).to eql other_namespace_set
|
79
122
|
end
|
@@ -1,31 +1,31 @@
|
|
1
1
|
require 'rspectacular'
|
2
2
|
require 'chamber/settings'
|
3
3
|
|
4
|
-
|
4
|
+
module Chamber
|
5
5
|
describe Settings do
|
6
6
|
it 'can verify that it is equal to another Settings object' do
|
7
7
|
settings = Settings.new( settings: {setting: 'value'},
|
8
|
-
namespaces:
|
8
|
+
namespaces: ['good'])
|
9
9
|
other_settings = Settings.new( settings: {setting: 'value'},
|
10
|
-
namespaces:
|
10
|
+
namespaces: ['good'])
|
11
11
|
|
12
12
|
expect(settings).to eql other_settings
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'does not consider itself equal if the namespaces are not equal' do
|
16
16
|
settings = Settings.new( settings: {setting: 'value'},
|
17
|
-
namespaces:
|
17
|
+
namespaces: ['good'])
|
18
18
|
other_settings = Settings.new( settings: {setting: 'value'},
|
19
|
-
namespaces:
|
19
|
+
namespaces: ['bad'])
|
20
20
|
|
21
21
|
expect(settings).not_to eql other_settings
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'does not consider itself equal if the settings are not equal' do
|
25
25
|
settings = Settings.new( settings: {setting: 'value'},
|
26
|
-
namespaces:
|
26
|
+
namespaces: ['good'])
|
27
27
|
other_settings = Settings.new( settings: {setting: 'value 1'},
|
28
|
-
namespaces:
|
28
|
+
namespaces: ['good'])
|
29
29
|
|
30
30
|
expect(settings).not_to eql other_settings
|
31
31
|
end
|
@@ -72,32 +72,55 @@ describe Settings do
|
|
72
72
|
end
|
73
73
|
|
74
74
|
it 'can merge itself with a hash' do
|
75
|
-
settings
|
76
|
-
|
75
|
+
settings = Settings.new(settings: {setting: 'value'})
|
76
|
+
other_settings = { other_setting: 'another value' }
|
77
|
+
|
78
|
+
merged_settings = settings.merge(other_settings)
|
77
79
|
|
78
|
-
expect(
|
79
|
-
|
80
|
+
expect(merged_settings).to eq('setting' => 'value',
|
81
|
+
'other_setting' => 'another value')
|
80
82
|
end
|
81
83
|
|
82
84
|
it 'can merge itself with Settings' do
|
83
85
|
settings = Settings.new(settings: {setting: 'value'},
|
84
|
-
namespaces:
|
85
|
-
|
86
|
+
namespaces: ['good'])
|
86
87
|
other_settings = Settings.new(settings: {other_setting: 'another value'},
|
87
|
-
namespaces:
|
88
|
+
namespaces: ['bad'])
|
89
|
+
|
90
|
+
merged_settings = settings.merge(other_settings)
|
91
|
+
|
92
|
+
expect(merged_settings).to eql Settings.new(settings: {
|
93
|
+
setting: 'value',
|
94
|
+
other_setting: 'another value' },
|
95
|
+
namespaces: ['good', 'bad'])
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'does not manipulate the existing Settings but instead returns a new one' do
|
99
|
+
settings = Settings.new(settings: {setting: 'value'})
|
100
|
+
other_settings = Settings.new(settings: {other_setting: 'another value'})
|
88
101
|
|
89
|
-
settings.merge
|
102
|
+
merged_settings = settings.merge(other_settings)
|
90
103
|
|
91
|
-
expect(
|
92
|
-
|
93
|
-
other_setting: 'another value' },
|
94
|
-
namespaces: NamespaceSet.new(['good', 'bad']))
|
104
|
+
expect(merged_settings.object_id).not_to eql settings.object_id
|
105
|
+
expect(merged_settings.object_id).not_to eql other_settings.object_id
|
95
106
|
end
|
96
107
|
|
97
108
|
it 'can convert itself into a hash' do
|
98
109
|
settings = Settings.new(settings: {setting: 'value'})
|
99
110
|
|
100
|
-
expect(settings.to_hash).to
|
111
|
+
expect(settings.to_hash).to eql('setting' => 'value')
|
112
|
+
expect(settings.to_hash).to be_a Hash
|
113
|
+
expect(settings.to_hash).not_to be_a Hashie::Mash
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'does not allow manipulation of the internal setting hash when converted to a Hash' do
|
117
|
+
settings = Settings.new(settings: {setting: 'value'})
|
118
|
+
|
119
|
+
settings_hash = settings.to_hash
|
120
|
+
settings_hash['setting'] = 'foo'
|
121
|
+
|
122
|
+
expect(settings.send(:data).object_id).not_to eql settings_hash.object_id
|
123
|
+
expect(settings.setting).to eql 'value'
|
101
124
|
end
|
102
125
|
|
103
126
|
it 'allows messages to be passed through to the underlying data' do
|
@@ -126,10 +149,63 @@ describe Settings do
|
|
126
149
|
other_namespace_setting: 'value' },
|
127
150
|
non_namespace_setting: 'other value'
|
128
151
|
},
|
129
|
-
namespaces:
|
152
|
+
namespaces: ['namespace_value', 'other_namespace_value'])
|
153
|
+
|
154
|
+
expect(settings).to eq('namespace_setting' => 'value',
|
155
|
+
'other_namespace_setting' => 'value')
|
156
|
+
end
|
157
|
+
|
158
|
+
it 'can decrypt a setting if it finds a secure key' do
|
159
|
+
settings = Settings.new(settings: {
|
160
|
+
_secure_my_encrypted_setting: 'cJbFe0NI5wknmsp2fVgpC/YeBD2pvcdVD+p0pUdnMoYThaV4mpsspg/ZTBtmjx7kMwcF6cjXFLDVw3FxptTHwzJUd4akun6EZ57m+QzCMJYnfY95gB2/emEAQLSz4/YwsE4LDGydkEjY1ZprfXznf+rU31YGDJUTf34ESz7fsQGSc9DjkBb9ao8Mv4cI7pCXkQZDwS5kLAZDf6agy1GzeL71Z8lrmQzk8QQuf/1kQzxsWVlzpKNXWS7u2CJ0sN5eINMngJBfv5ZFrZgfXc86wdgUKc8aaoX8OQA1kKTcdgbE9NcAhNr1+WfNxMnz84XzmUp2Y0H1jPgGkBKQJKArfQ=='
|
161
|
+
},
|
162
|
+
decryption_key: './spec/spec_key')
|
163
|
+
|
164
|
+
expect(settings).to eq('my_encrypted_setting' => 'hello')
|
165
|
+
end
|
166
|
+
|
167
|
+
it 'can encrypt a setting if it finds a secure key' do
|
168
|
+
settings = Settings.new(settings: {
|
169
|
+
_secure_my_encrypted_setting: 'hello'
|
170
|
+
},
|
171
|
+
encryption_key: './spec/spec_key.pub',
|
172
|
+
pre_filters: [],
|
173
|
+
post_filters: [ Filters::EncryptionFilter ])
|
174
|
+
|
175
|
+
expect(settings._secure_my_encrypted_setting).to match Filters::EncryptionFilter::BASE64_STRING_PATTERN
|
176
|
+
end
|
177
|
+
|
178
|
+
it 'can encrypt a settings without explicitly having to have a filter passed' do
|
179
|
+
settings = Settings.new(settings: {
|
180
|
+
_secure_my_encrypted_setting: 'hello'
|
181
|
+
},
|
182
|
+
decryption_key: './spec/spec_key',
|
183
|
+
encryption_key: './spec/spec_key.pub')
|
184
|
+
|
185
|
+
expect(settings).to eq('my_encrypted_setting' => 'hello')
|
186
|
+
|
187
|
+
secure_settings = settings.secure
|
188
|
+
|
189
|
+
expect(secure_settings._secure_my_encrypted_setting).to match Filters::EncryptionFilter::BASE64_STRING_PATTERN
|
190
|
+
end
|
191
|
+
|
192
|
+
it 'can check if it is equal to other items which can be converted into hashes' do
|
193
|
+
settings = Settings.new(settings: {setting: 'value'})
|
194
|
+
|
195
|
+
expect(settings).to eq('setting' => 'value')
|
196
|
+
end
|
197
|
+
|
198
|
+
it 'can filter secured settings' do
|
199
|
+
settings = Settings.new(settings: {
|
200
|
+
_secure_my_encrypted_setting: 'cJbFe0NI5wknmsp2fVgpC/YeBD2pvcdVD+p0pUdnMoYThaV4mpsspg/ZTBtmjx7kMwcF6cjXFLDVw3FxptTHwzJUd4akun6EZ57m+QzCMJYnfY95gB2/emEAQLSz4/YwsE4LDGydkEjY1ZprfXznf+rU31YGDJUTf34ESz7fsQGSc9DjkBb9ao8Mv4cI7pCXkQZDwS5kLAZDf6agy1GzeL71Z8lrmQzk8QQuf/1kQzxsWVlzpKNXWS7u2CJ0sN5eINMngJBfv5ZFrZgfXc86wdgUKc8aaoX8OQA1kKTcdgbE9NcAhNr1+WfNxMnz84XzmUp2Y0H1jPgGkBKQJKArfQ==',
|
201
|
+
my_insecure_setting: 'goodbye',
|
202
|
+
},
|
203
|
+
decryption_key: './spec/spec_key')
|
204
|
+
|
205
|
+
secured_settings = settings.secured
|
130
206
|
|
131
|
-
expect(
|
132
|
-
|
207
|
+
expect(secured_settings.my_encrypted_setting).to eql 'hello'
|
208
|
+
expect(secured_settings.my_insecure_setting?).to be_false
|
133
209
|
end
|
134
210
|
end
|
135
211
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'rspectacular'
|
2
2
|
require 'chamber/system_environment'
|
3
3
|
|
4
|
-
|
4
|
+
module Chamber
|
5
5
|
describe SystemEnvironment do
|
6
6
|
it 'can extract environment variables based on a hash that is passed in' do
|
7
7
|
source_hash = {
|
@@ -36,20 +36,6 @@ describe SystemEnvironment do
|
|
36
36
|
})
|
37
37
|
end
|
38
38
|
|
39
|
-
it 'allows injected environment variables to be prefixed for compatibility' do
|
40
|
-
ENV['PREFIX_VALUE_ONE'] = 'value 1'
|
41
|
-
|
42
|
-
source_hash = {
|
43
|
-
value_one: 'value',
|
44
|
-
}
|
45
|
-
|
46
|
-
environment_hash = SystemEnvironment.inject_into(source_hash, [:prefix])
|
47
|
-
|
48
|
-
expect(environment_hash).to eql({
|
49
|
-
'value_one' => 'value 1',
|
50
|
-
})
|
51
|
-
end
|
52
|
-
|
53
39
|
it 'allows extracted environment variables to be prefixed for compatibility' do
|
54
40
|
source_hash = {
|
55
41
|
value_one: 'value',
|
@@ -61,61 +47,5 @@ describe SystemEnvironment do
|
|
61
47
|
'PREFIX_VALUE_ONE' => 'value',
|
62
48
|
})
|
63
49
|
end
|
64
|
-
|
65
|
-
it 'can inject existing environment variable values into a hash' do
|
66
|
-
ENV['LEVEL_ONE_1_LEVEL_TWO_1'] = 'value 1'
|
67
|
-
ENV['LEVEL_ONE_1_LEVEL_TWO_2_LEVEL_THREE_1'] = 'value 2'
|
68
|
-
ENV['LEVEL_ONE_1_LEVEL_TWO_2_LEVEL_THREE_2'] = 'value 3'
|
69
|
-
ENV['LEVEL_ONE_1_LEVEL_TWO_3'] = 'value 4'
|
70
|
-
ENV['LEVEL_ONE_1_LEVEL_ONE_2'] = 'value 5'
|
71
|
-
|
72
|
-
source_hash = {
|
73
|
-
level_one_1: {
|
74
|
-
level_two_1: nil,
|
75
|
-
level_two_2: {
|
76
|
-
level_three_1: nil,
|
77
|
-
level_three_2: '',
|
78
|
-
},
|
79
|
-
level_two_3: '',
|
80
|
-
level_one_2: '' }
|
81
|
-
}
|
82
|
-
|
83
|
-
expect(SystemEnvironment.inject_into(source_hash)).to eql({
|
84
|
-
'level_one_1' => {
|
85
|
-
'level_two_1' => 'value 1',
|
86
|
-
'level_two_2' => {
|
87
|
-
'level_three_1' => 'value 2',
|
88
|
-
'level_three_2' => 'value 3',
|
89
|
-
},
|
90
|
-
'level_two_3' => 'value 4',
|
91
|
-
'level_one_2' => 'value 5' }
|
92
|
-
})
|
93
|
-
|
94
|
-
ENV.delete('LEVEL_ONE_1_LEVEL_TWO_1')
|
95
|
-
ENV.delete('LEVEL_ONE_1_LEVEL_TWO_2_LEVEL_THREE_1')
|
96
|
-
ENV.delete('LEVEL_ONE_1_LEVEL_TWO_2_LEVEL_THREE_2')
|
97
|
-
ENV.delete('LEVEL_ONE_1_LEVEL_TWO_3')
|
98
|
-
ENV.delete('LEVEL_ONE_1_LEVEL_ONE_2')
|
99
|
-
end
|
100
|
-
|
101
|
-
it 'can convert simple boolean text values to their Boolean equivalents' do
|
102
|
-
source_hash = {
|
103
|
-
true_text: 'true',
|
104
|
-
true_single: 't',
|
105
|
-
true_yes: 'yes',
|
106
|
-
false_text: 'false',
|
107
|
-
false_single: 'f',
|
108
|
-
false_no: 'no',
|
109
|
-
}
|
110
|
-
|
111
|
-
environment_hash = SystemEnvironment.inject_into(source_hash)
|
112
|
-
|
113
|
-
expect(environment_hash['true_text']).to be_a TrueClass
|
114
|
-
expect(environment_hash['true_single']).to be_a TrueClass
|
115
|
-
expect(environment_hash['true_yes']).to be_a TrueClass
|
116
|
-
expect(environment_hash['false_text']).to be_a FalseClass
|
117
|
-
expect(environment_hash['false_single']).to be_a FalseClass
|
118
|
-
expect(environment_hash['false_no']).to be_a FalseClass
|
119
|
-
end
|
120
50
|
end
|
121
51
|
end
|
data/spec/lib/chamber_spec.rb
CHANGED
@@ -23,6 +23,13 @@ test:
|
|
23
23
|
HEREDOC
|
24
24
|
end
|
25
25
|
|
26
|
+
File.open('/tmp/chamber/secure.yml', 'w+') do |file|
|
27
|
+
file.puts <<-HEREDOC
|
28
|
+
test:
|
29
|
+
_secure_my_encrpyted_setting: cJbFe0NI5wknmsp2fVgpC/YeBD2pvcdVD+p0pUdnMoYThaV4mpsspg/ZTBtmjx7kMwcF6cjXFLDVw3FxptTHwzJUd4akun6EZ57m+QzCMJYnfY95gB2/emEAQLSz4/YwsE4LDGydkEjY1ZprfXznf+rU31YGDJUTf34ESz7fsQGSc9DjkBb9ao8Mv4cI7pCXkQZDwS5kLAZDf6agy1GzeL71Z8lrmQzk8QQuf/1kQzxsWVlzpKNXWS7u2CJ0sN5eINMngJBfv5ZFrZgfXc86wdgUKc8aaoX8OQA1kKTcdgbE9NcAhNr1+WfNxMnz84XzmUp2Y0H1jPgGkBKQJKArfQ==
|
30
|
+
HEREDOC
|
31
|
+
end
|
32
|
+
|
26
33
|
File.open('/tmp/chamber/credentials.yml', 'w+') do |file|
|
27
34
|
file.puts <<-HEREDOC
|
28
35
|
test:
|
@@ -71,19 +78,19 @@ only_namespaced_sub_settings:
|
|
71
78
|
HEREDOC
|
72
79
|
end
|
73
80
|
|
74
|
-
describe Chamber
|
81
|
+
describe Chamber do
|
75
82
|
before(:each) { Chamber.load(:basepath => '/tmp/chamber') }
|
76
83
|
|
77
84
|
it 'knows how to load itself with a path string' do
|
78
85
|
Chamber.load(:basepath => '/tmp/chamber')
|
79
86
|
|
80
|
-
expect(Chamber.basepath.to_s).to eql '/tmp/chamber'
|
87
|
+
expect(Chamber.configuration.basepath.to_s).to eql '/tmp/chamber'
|
81
88
|
end
|
82
89
|
|
83
90
|
it 'knows how to load itself with a path object' do
|
84
91
|
Chamber.load(:basepath => Pathname.new('/tmp/chamber'))
|
85
92
|
|
86
|
-
expect(Chamber.basepath.to_s).to eql '/tmp/chamber'
|
93
|
+
expect(Chamber.configuration.basepath.to_s).to eql '/tmp/chamber'
|
87
94
|
end
|
88
95
|
|
89
96
|
it 'processes settings files through ERB before YAML' do
|
@@ -95,11 +102,11 @@ describe Chamber, :singletons => [Chamber] do
|
|
95
102
|
end
|
96
103
|
|
97
104
|
it 'can access the settings through method-based access' do
|
98
|
-
expect(Chamber.
|
105
|
+
expect(Chamber.test.my_setting).to eql 'my_value'
|
99
106
|
end
|
100
107
|
|
101
|
-
it 'can access the
|
102
|
-
expect(Chamber.
|
108
|
+
it 'can access the settings via "env"' do
|
109
|
+
expect(Chamber.env.test.my_setting).to eql 'my_value'
|
103
110
|
end
|
104
111
|
|
105
112
|
it 'prefers values stored in environment variables over those in the YAML files' do
|
@@ -107,9 +114,9 @@ describe Chamber, :singletons => [Chamber] do
|
|
107
114
|
ENV['TEST_ANOTHER_LEVEL_LEVEL_THREE_AN_ARRAY'] = 'something'
|
108
115
|
|
109
116
|
Chamber.load(:basepath => '/tmp/chamber')
|
110
|
-
expect(Chamber.
|
111
|
-
expect(Chamber.
|
112
|
-
expect(Chamber.
|
117
|
+
expect(Chamber.test.my_setting).to eql 'some_other_value'
|
118
|
+
expect(Chamber.test.another_level.level_three.an_array).to eql 'something'
|
119
|
+
expect(Chamber.test.my_dynamic_setting).to eql 2
|
113
120
|
|
114
121
|
ENV.delete 'TEST_MY_SETTING'
|
115
122
|
ENV.delete 'TEST_ANOTHER_LEVEL_LEVEL_THREE_AN_ARRAY'
|
@@ -120,8 +127,8 @@ describe Chamber, :singletons => [Chamber] do
|
|
120
127
|
:namespaces => {
|
121
128
|
:my_namespace => -> { 'blue' } } )
|
122
129
|
|
123
|
-
expect(Chamber.
|
124
|
-
expect(Chamber.
|
130
|
+
expect(Chamber.other.everything).to eql 'works'
|
131
|
+
expect(Chamber.test.my_dynamic_setting).to eql 2
|
125
132
|
end
|
126
133
|
|
127
134
|
it 'loads multiple namespaces if it is called twice' do
|
@@ -130,7 +137,7 @@ describe Chamber, :singletons => [Chamber] do
|
|
130
137
|
:first_namespace_call => -> { :first },
|
131
138
|
:second_namespace_call => -> { :second }, } )
|
132
139
|
|
133
|
-
expect(Chamber.
|
140
|
+
expect(Chamber.namespaces.to_a).to eql ['first', 'second']
|
134
141
|
end
|
135
142
|
|
136
143
|
it 'does not load the same namespace twice' do
|
@@ -139,7 +146,7 @@ describe Chamber, :singletons => [Chamber] do
|
|
139
146
|
:first_namespace_call => -> { :first },
|
140
147
|
:first_namespace_call => -> { :first }, } )
|
141
148
|
|
142
|
-
expect(Chamber.
|
149
|
+
expect(Chamber.namespaces.to_a).to eql ['first']
|
143
150
|
end
|
144
151
|
|
145
152
|
it 'will load settings files which are only namespaced' do
|
@@ -163,7 +170,7 @@ describe Chamber, :singletons => [Chamber] do
|
|
163
170
|
end
|
164
171
|
|
165
172
|
it 'still raises an error if you try to send a message which the settings hash does not understand' do
|
166
|
-
expect{ Chamber.
|
173
|
+
expect{ Chamber.env.i_do_not_know }.to raise_error NoMethodError
|
167
174
|
end
|
168
175
|
|
169
176
|
it 'does not raise an exception if a namespaced file does not exist' do
|
@@ -179,13 +186,13 @@ describe Chamber, :singletons => [Chamber] do
|
|
179
186
|
:namespaces => {
|
180
187
|
:my_namespace => -> { 'blue' } } )
|
181
188
|
|
182
|
-
expect(Chamber.
|
183
|
-
expect(Chamber.
|
184
|
-
expect(Chamber.
|
189
|
+
expect(Chamber.test.my_setting).to eql 'my_value'
|
190
|
+
expect(Chamber.test.my_other_setting).to eql 'my_other_value'
|
191
|
+
expect(Chamber.test.another_level.setting_one).to eql 3
|
185
192
|
end
|
186
193
|
|
187
194
|
it 'loads YAML files from the "settings" directory under the base directory if any exist' do
|
188
|
-
expect(Chamber.
|
195
|
+
expect(Chamber.sub_settings.my_sub_setting).to eql 'my_sub_setting_value'
|
189
196
|
end
|
190
197
|
|
191
198
|
it 'does not load YAML files from the "settings" directory if it is namespaced' do
|
@@ -253,16 +260,16 @@ describe Chamber, :singletons => [Chamber] do
|
|
253
260
|
end
|
254
261
|
|
255
262
|
it 'can notify properly whether it responds to messages if the underlying settings does' do
|
256
|
-
expect(Chamber.
|
263
|
+
expect(Chamber.respond_to?(:sub_settings)).to be_a TrueClass
|
257
264
|
end
|
258
265
|
|
259
266
|
it 'can explicitly specify files without specifying a basepath' do
|
260
267
|
Chamber.load files: ['/tmp/chamber/credentials.yml']
|
261
268
|
|
262
|
-
expect(Chamber.filenames).to
|
263
|
-
expect(Chamber.
|
264
|
-
|
265
|
-
|
269
|
+
expect(Chamber.filenames).to eql ['/tmp/chamber/credentials.yml']
|
270
|
+
expect(Chamber.to_hash).to eql('test' => {
|
271
|
+
'my_username' => 'username',
|
272
|
+
'my_password' => 'password', } )
|
266
273
|
end
|
267
274
|
|
268
275
|
it 'ignores the basepath if file patterns are explicitly passed in' do
|
@@ -273,14 +280,21 @@ describe Chamber, :singletons => [Chamber] do
|
|
273
280
|
end
|
274
281
|
|
275
282
|
it 'can render itself as a string even if it has not been loaded' do
|
276
|
-
|
283
|
+
Chamber.load
|
277
284
|
|
278
285
|
expect(Chamber.to_s).to eql ''
|
279
286
|
end
|
280
287
|
|
281
288
|
it 'can determine settings even if it has not been loaded' do
|
282
|
-
|
289
|
+
Chamber.load
|
290
|
+
|
291
|
+
expect(Chamber.to_hash).to eql({})
|
292
|
+
end
|
293
|
+
|
294
|
+
it 'can unencrpyt an already encrpyted value if it has access to the private key' do
|
295
|
+
Chamber.load(files: '/tmp/chamber/secure.yml',
|
296
|
+
decryption_key: './spec/spec_key')
|
283
297
|
|
284
|
-
expect(Chamber.
|
298
|
+
expect(Chamber.test.my_encrpyted_setting).to eql 'hello'
|
285
299
|
end
|
286
300
|
end
|