complex_config 0.13.3 → 0.14.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 +5 -5
- data/Gemfile +0 -2
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/bin/complex_config +92 -0
- data/complex_config.gemspec +6 -5
- data/lib/complex_config/provider.rb +16 -5
- data/lib/complex_config/version.rb +1 -1
- data/spec/complex_config/provider_spec.rb +10 -0
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c28ccee05d5a9ac6940f0b73babaca1a93c21e0f55f048bbc77ec000ccabb9f9
|
4
|
+
data.tar.gz: 053fca226196c715755fa82921eb43602d176faa3eb402b783b49d1b7113705e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ba5fa43f39da3bef7c836a3ce6df235e1876a47981adb845139b7361118641780b62c5defc1610aa6b5f27d6a1027f337e10e426b8e184fb07363e74ec98449
|
7
|
+
data.tar.gz: 2551fe15c77f3442f99240d86097f3b28b2968e91ca36116ff51517caf12c66ddb096c0136aa968d091e79bc01947c70f3b9656b0ae13d9751c92b77c202d3a8
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -9,6 +9,7 @@ GemHadar do
|
|
9
9
|
homepage "https://github.com/flori/#{name}"
|
10
10
|
summary 'configuration library'
|
11
11
|
description 'This library allows you to access configuration files via a simple interface'
|
12
|
+
executables 'complex_config'
|
12
13
|
test_dir 'spec'
|
13
14
|
ignore '.*.sw[pon]', 'pkg', 'Gemfile.lock', 'coverage', '.rvmrc',
|
14
15
|
'.AppleDouble', '.DS_Store', '.byebug_history', 'errors.lst'
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.14.0
|
data/bin/complex_config
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'complex_config/rude'
|
4
|
+
require 'tins/xt'
|
5
|
+
include Tins::GO
|
6
|
+
require 'tempfile'
|
7
|
+
|
8
|
+
$opts = go 'h'
|
9
|
+
|
10
|
+
def usage(msg: 'Displaying help', rc: 0)
|
11
|
+
puts <<~end
|
12
|
+
#{msg}
|
13
|
+
|
14
|
+
Usage: #$0 COMMAND [OPTIONS] [FILENAME]"
|
15
|
+
|
16
|
+
Commands are
|
17
|
+
edit edit encrypted file FILENAME (suffix .enc)
|
18
|
+
encrypt encrypt file FILENAME (suffix not .enc)
|
19
|
+
decrypt decrypt file FILENAME (suffix .enc)
|
20
|
+
display decrypt and display encrypted file FILENAME (suffix .enc)
|
21
|
+
|
22
|
+
Options are
|
23
|
+
|
24
|
+
-c CONFIG_DIR set CONFIG_DIR (default: "./config")
|
25
|
+
-h this help
|
26
|
+
|
27
|
+
end
|
28
|
+
exit rc
|
29
|
+
end
|
30
|
+
|
31
|
+
def fetch_filename(suffix: true)
|
32
|
+
fn = ARGV.shift.dup or usage msg: "config filename required", rc: 1
|
33
|
+
if suffix
|
34
|
+
unless fn.end_with?('.enc')
|
35
|
+
usage msg: "config filename needs suffix .enc", rc: 1
|
36
|
+
end
|
37
|
+
else
|
38
|
+
if fn.end_with?('.enc')
|
39
|
+
usage msg: "config filename seems to be already encrypted with suffix .enc", rc: 1
|
40
|
+
end
|
41
|
+
end
|
42
|
+
File.exist?(fn) or usage msg: "config filename #{fn} doesn't exist", rc: 1
|
43
|
+
suffix and fn.sub!(/\.enc\z/, '')
|
44
|
+
fn
|
45
|
+
end
|
46
|
+
|
47
|
+
$opts[?h] and usage
|
48
|
+
ComplexConfig::Provider.config_dir = File.expand_path($opts[?c] || './config')
|
49
|
+
|
50
|
+
case command = ARGV.shift
|
51
|
+
when 'edit'
|
52
|
+
fn = fetch_filename
|
53
|
+
did_not_change = Class.new(StandardError)
|
54
|
+
begin
|
55
|
+
File.secure_write(fn + '.enc') do |f|
|
56
|
+
Tempfile.open('complex_config') do |t|
|
57
|
+
config = ComplexConfig::Provider.decrypt_config(fn)
|
58
|
+
t.write config
|
59
|
+
t.flush
|
60
|
+
system ENV.fetch('EDITOR', 'vi'), t.path
|
61
|
+
new_config = IO.binread(t.path)
|
62
|
+
if config == new_config
|
63
|
+
puts "Configuration hasn't been changed."
|
64
|
+
raise did_not_change
|
65
|
+
else
|
66
|
+
f.write ComplexConfig::Provider.encrypt_config(fn, new_config)
|
67
|
+
puts "New configuration has been written."
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
rescue did_not_change
|
72
|
+
end
|
73
|
+
when 'decrypt'
|
74
|
+
fn = fetch_filename
|
75
|
+
File.exist?(fn) and usage msg: "decrypted config #{fn.inspect} already exists", rc: 1
|
76
|
+
File.secure_write(fn) do |f|
|
77
|
+
f.write ComplexConfig::Provider.decrypt_config(fn)
|
78
|
+
end
|
79
|
+
puts "File was decrypted to #{fn.inspect}. You can remove #{(fn + '.enc').inspect} now."
|
80
|
+
when 'display'
|
81
|
+
puts ComplexConfig::Provider.decrypt_config(fetch_filename)
|
82
|
+
when 'encrypt'
|
83
|
+
fn = fetch_filename suffix: false
|
84
|
+
File.exist?(fn + '.enc') and usage msg: "encrypted config #{(fn + '.enc').inspect} already exists", rc: 1
|
85
|
+
File.secure_write(fn + '.enc') do |f|
|
86
|
+
f.write ComplexConfig::Provider.encrypt_config(fn, IO.binread(fn))
|
87
|
+
end
|
88
|
+
puts "File was encrypted to #{(fn + '.enc').inspect}. You can remove #{fn.inspect} now."
|
89
|
+
else
|
90
|
+
usage msg: "Unknown command #{command.inspect}", rc: 1
|
91
|
+
end
|
92
|
+
|
data/complex_config.gemspec
CHANGED
@@ -1,22 +1,23 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: complex_config 0.
|
2
|
+
# stub: complex_config 0.14.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.14.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 = "2018-
|
11
|
+
s.date = "2018-06-07"
|
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.executables = ["complex_config".freeze]
|
14
15
|
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
|
+
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, "bin/complex_config".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
17
|
s.homepage = "https://github.com/flori/complex_config".freeze
|
17
18
|
s.licenses = ["Apache-2.0".freeze]
|
18
19
|
s.rdoc_options = ["--title".freeze, "ComplexConfig -- configuration library".freeze, "--main".freeze, "README.md".freeze]
|
19
|
-
s.rubygems_version = "2.6
|
20
|
+
s.rubygems_version = "2.7.6".freeze
|
20
21
|
s.summary = "configuration library".freeze
|
21
22
|
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
23
|
|
@@ -72,16 +72,27 @@ class ComplexConfig::Provider
|
|
72
72
|
config_dir + "#{name}.yml"
|
73
73
|
end
|
74
74
|
|
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
|
82
|
+
end
|
83
|
+
|
84
|
+
def encrypt_config(pathname, config)
|
85
|
+
ks = key_source(pathname)
|
86
|
+
ComplexConfig::Encryption.new(ks.key_bytes).encrypt(config)
|
87
|
+
end
|
88
|
+
|
75
89
|
def config(pathname, name = nil)
|
76
90
|
datas = []
|
77
91
|
if File.exist?(pathname)
|
78
92
|
datas << IO.binread(pathname)
|
79
93
|
end
|
80
|
-
|
81
|
-
|
82
|
-
if File.exist?(enc_pathname) && my_ks.ask_and_send(:key)
|
83
|
-
text = IO.binread(enc_pathname)
|
84
|
-
datas << ComplexConfig::Encryption.new(my_ks.key_bytes).decrypt(text)
|
94
|
+
if decrypted = decrypt_config(pathname)
|
95
|
+
datas << decrypted
|
85
96
|
end
|
86
97
|
datas.empty? and raise ComplexConfig::ConfigurationFileMissing,
|
87
98
|
"configuration file #{pathname.to_s.inspect} is missing"
|
@@ -209,6 +209,16 @@ RSpec.describe ComplexConfig::Provider do
|
|
209
209
|
expect(provider.config(asset('new_config.yml'))).to eq config
|
210
210
|
end
|
211
211
|
|
212
|
+
it 'can encrypt file content with RAILS_MASTER_KEY key' do
|
213
|
+
ENV['RAILS_MASTER_KEY'] = SecureRandom.hex(16)
|
214
|
+
encrypted = provider.encrypt_config(asset('new_config.yml'), 'test')
|
215
|
+
expect(encrypted).not_to be_empty
|
216
|
+
ks = ComplexConfig::KeySource.new(env_var: 'RAILS_MASTER_KEY')
|
217
|
+
expect(
|
218
|
+
ComplexConfig::Encryption.new(ks.key_bytes).decrypt(encrypted)
|
219
|
+
).to eq 'test'
|
220
|
+
end
|
221
|
+
|
212
222
|
it 'can be changed and written' do
|
213
223
|
provider.deep_freeze = false
|
214
224
|
expect(provider.config(asset('config.yml')).development.config.baz).to eq 'something'
|
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.14.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: 2018-
|
11
|
+
date: 2018-06-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gem_hadar
|
@@ -130,7 +130,8 @@ dependencies:
|
|
130
130
|
version: 0.3.4
|
131
131
|
description: This library allows you to access configuration files via a simple interface
|
132
132
|
email: flori@ping.de
|
133
|
-
executables:
|
133
|
+
executables:
|
134
|
+
- complex_config
|
134
135
|
extensions: []
|
135
136
|
extra_rdoc_files:
|
136
137
|
- README.md
|
@@ -162,6 +163,7 @@ files:
|
|
162
163
|
- Rakefile
|
163
164
|
- TODO.md
|
164
165
|
- VERSION
|
166
|
+
- bin/complex_config
|
165
167
|
- complex_config.gemspec
|
166
168
|
- config/products.yml
|
167
169
|
- lib/complex_config.rb
|
@@ -219,7 +221,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
219
221
|
version: '0'
|
220
222
|
requirements: []
|
221
223
|
rubyforge_project:
|
222
|
-
rubygems_version: 2.6
|
224
|
+
rubygems_version: 2.7.6
|
223
225
|
signing_key:
|
224
226
|
specification_version: 4
|
225
227
|
summary: configuration library
|