complex_config 0.16.0 → 0.17.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
  SHA256:
3
- metadata.gz: 114e86c26b5932221df1aa2ae61c248697a40162db12aac16673f2a204597a08
4
- data.tar.gz: cc4847658eff087770fa628015f2edb8e27f61fce248ba82e5087671ceb1cdd8
3
+ metadata.gz: 6a62d35017801f81211c900cfd841264193155e1f89ebc27c387b7649da6dbcc
4
+ data.tar.gz: 96cdc260febe8d2dff2f479421dcf7e94e61de4dacf77ee2ca30372c069e390c
5
5
  SHA512:
6
- metadata.gz: aa4c8feae89efd54ad866f0ad98d68479b383a9fbce025de01f0db160a95210a7e894973ca5bd29a1491a146a7d611e1caa3398255203ac8fc8c0678e41a3608
7
- data.tar.gz: 047cd0f7ca2c59daaa8fd3ea03e978e8c2c06dcd14dd447762a4cad771b190533563d3dbf3e74d67682cada3c2ce0b17beb4abbceab8ff4267e2a03c67931b28
6
+ metadata.gz: aae99c356a7467495f3311dd0aaca592078164458183076aae3fd3688d65d7d0e0b37bf209cb6b0873715240b9d6b1105e04dbbd60ce80d0d53566e5a67a07a5
7
+ data.tar.gz: a63690e1401e3df9bdc29cc6f9441812521bad478fb43ee4ed6be79d7bc39a220a56c90de3862b8d4510cd9ad04d48d534a92bcb0769500b8b7cb16c900f0328
data/README.md CHANGED
@@ -144,6 +144,8 @@ Here is the `ComplexConfig::Plugins::MONEY` plugin for example:
144
144
 
145
145
  ## Changes
146
146
 
147
+ * 2019-03-18 Release 0.17.0
148
+ * Improve error message for missing encryption key
147
149
  * 2019-03-14 Release 0.16.0
148
150
  * Enable `- trim_mode` for ERB in yml files
149
151
  * Allow `to_json` calls on settings
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.16.0
1
+ 0.17.0
@@ -1,14 +1,14 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: complex_config 0.16.0 ruby lib
2
+ # stub: complex_config 0.17.0 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "complex_config".freeze
6
- s.version = "0.16.0"
6
+ s.version = "0.17.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 = "2019-03-14"
11
+ s.date = "2019-03-18"
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
14
  s.executables = ["complex_config".freeze]
@@ -23,6 +23,9 @@ module ComplexConfig
23
23
  class EncryptionKeyInvalid < EncryptionError
24
24
  end
25
25
 
26
+ class EncryptionKeyMissing < EncryptionError
27
+ end
28
+
26
29
  class DecryptionFailed < EncryptionError
27
30
  end
28
31
  end
@@ -73,12 +73,7 @@ class ComplexConfig::Provider
73
73
  end
74
74
 
75
75
  def decrypt_config(pathname)
76
- enc_pathname = pathname.to_s + '.enc'
77
- my_ks = key_source(pathname)
78
- if File.exist?(enc_pathname) && my_ks.ask_and_send(:key)
79
- text = IO.binread(enc_pathname)
80
- ComplexConfig::Encryption.new(my_ks.key_bytes).decrypt(text)
81
- end
76
+ decrypt_config_case(pathname).first
82
77
  end
83
78
 
84
79
  def encrypt_config(pathname, config)
@@ -88,14 +83,21 @@ class ComplexConfig::Provider
88
83
 
89
84
  def config(pathname, name = nil)
90
85
  datas = []
91
- if File.exist?(pathname)
86
+ path_exist = File.exist?(pathname)
87
+ if path_exist
92
88
  datas << IO.binread(pathname)
93
89
  end
94
- if decrypted = decrypt_config(pathname)
90
+ decrypted, reason, enc_pathname = decrypt_config_case(pathname)
91
+ case reason
92
+ when :ok
95
93
  datas << decrypted
94
+ when :key_missing
95
+ datas.empty? and raise ComplexConfig::EncryptionKeyMissing,
96
+ "encryption key for #{enc_pathname.to_s.inspect} is missing"
97
+ when :file_missing
98
+ datas.empty? and raise ComplexConfig::ConfigurationFileMissing,
99
+ "configuration file #{pathname.to_s.inspect} is missing"
96
100
  end
97
- datas.empty? and raise ComplexConfig::ConfigurationFileMissing,
98
- "configuration file #{pathname.to_s.inspect} is missing"
99
101
  results = datas.map { |d| evaluate(pathname, d) }
100
102
  hashes = results.map { |r| ::YAML.load(r, pathname) }
101
103
  settings = ComplexConfig::Settings.build(name, hashes.shift)
@@ -153,7 +155,7 @@ class ComplexConfig::Provider
153
155
 
154
156
  def exist?(name)
155
157
  !!config(pathname(name), name)
156
- rescue ComplexConfig::ConfigurationFileMissing
158
+ rescue ComplexConfig::ConfigurationFileMissing, ComplexConfig::EncryptionKeyMissing
157
159
  false
158
160
  end
159
161
 
@@ -211,6 +213,21 @@ class ComplexConfig::Provider
211
213
 
212
214
  private
213
215
 
216
+ def decrypt_config_case(pathname)
217
+ enc_pathname = pathname.to_s + '.enc'
218
+ my_ks = key_source(pathname)
219
+ if File.exist?(enc_pathname)
220
+ if my_ks.ask_and_send(:key)
221
+ text = IO.binread(enc_pathname)
222
+ decrypted = ComplexConfig::Encryption.new(my_ks.key_bytes).decrypt(text)
223
+ return decrypted, :ok, enc_pathname
224
+ else
225
+ return nil, :key_missing, enc_pathname
226
+ end
227
+ end
228
+ return nil, :file_missing, enc_pathname
229
+ end
230
+
214
231
  def interpret_name_value(name, value)
215
232
  if ComplexConfig::Settings === name
216
233
  if value
@@ -1,6 +1,6 @@
1
1
  module ComplexConfig
2
2
  # ComplexConfig version
3
- VERSION = '0.16.0'
3
+ VERSION = '0.17.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:
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.16.0
4
+ version: 0.17.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: 2019-03-14 00:00:00.000000000 Z
11
+ date: 2019-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gem_hadar