complex_config 0.14.1 → 0.15.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/VERSION +1 -1
- data/bin/complex_config +25 -6
- data/complex_config.gemspec +2 -2
- data/lib/complex_config/encryption.rb +0 -1
- data/lib/complex_config/provider.rb +13 -1
- data/lib/complex_config/version.rb +1 -1
- data/spec/complex_config/provider_spec.rb +5 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e2e094436710a9fe5569cdb635d9d2230c07d401a084120d8d3a66e0b545155
|
4
|
+
data.tar.gz: 9d5d62f7903c36706445ab9b2f81b720aaf6c20bbc5e04a2aefc28d9a9c4e237
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88b09d7bdd720f1fce793ac31592315d41268a76014fec760728b3a837b569fe294af91171534c2bdd20f71802bba68c1a06e8fc1a1d32759b50de3fe0cf2117
|
7
|
+
data.tar.gz: 7708530ed03359d75b9ef2be05014289f090399a5ff1cbbde1aceab1313245153ce3574b1a6d1bcef9649620a0b877307cdcc689685f5c6cfc16f529d03d699b
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.15.0
|
data/bin/complex_config
CHANGED
@@ -4,8 +4,10 @@ require 'complex_config/rude'
|
|
4
4
|
require 'tins/xt'
|
5
5
|
include Tins::GO
|
6
6
|
require 'tempfile'
|
7
|
+
require 'fileutils'
|
8
|
+
include FileUtils
|
7
9
|
|
8
|
-
$opts = go 'h'
|
10
|
+
$opts = go 'o:n:h'
|
9
11
|
|
10
12
|
def usage(msg: 'Displaying help', rc: 0)
|
11
13
|
puts <<~end
|
@@ -14,10 +16,12 @@ def usage(msg: 'Displaying help', rc: 0)
|
|
14
16
|
Usage: #$0 COMMAND [OPTIONS] [FILENAME]"
|
15
17
|
|
16
18
|
Commands are
|
17
|
-
edit
|
18
|
-
encrypt
|
19
|
-
decrypt
|
20
|
-
display
|
19
|
+
edit edit encrypted file FILENAME (suffix .enc)
|
20
|
+
encrypt encrypt file FILENAME (suffix not .enc)
|
21
|
+
decrypt decrypt file FILENAME (suffix .enc)
|
22
|
+
display decrypt and display encrypted file FILENAME (suffix .enc)
|
23
|
+
new_key generate a new key and display it
|
24
|
+
recrypt recrypt a file, -o OLD_KEY to decrypt, -n NEW_KEY to encrypt
|
21
25
|
|
22
26
|
Options are
|
23
27
|
|
@@ -86,7 +90,22 @@ when 'encrypt'
|
|
86
90
|
f.write ComplexConfig::Provider.encrypt_config(fn, IO.binread(fn))
|
87
91
|
end
|
88
92
|
puts "File was encrypted to #{(fn + '.enc').inspect}. You can remove #{fn.inspect} now."
|
93
|
+
when 'new_key'
|
94
|
+
puts ComplexConfig::Provider.new_key
|
95
|
+
when 'recrypt'
|
96
|
+
old_key = $opts[?o] && ComplexConfig::Provider.valid_key?($opts[?o]) or
|
97
|
+
usage msg: "-o OLD_KEY option required and has to be valid", rc: 1
|
98
|
+
new_key = $opts[?n] && ComplexConfig::Provider.valid_key?($opts[?n]) or
|
99
|
+
usage msg: "-n NEW_KEY option required and has to be valid", rc: 1
|
100
|
+
encrypted_fn = fetch_filename
|
101
|
+
encrypted_text = IO.binread(encrypted_fn + '.enc')
|
102
|
+
decrypted_text = ComplexConfig::Encryption.new(old_key.key_bytes).decrypt(encrypted_text)
|
103
|
+
recrypted_text = ComplexConfig::Encryption.new(new_key.key_bytes).encrypt(decrypted_text)
|
104
|
+
File.secure_write(encrypted_fn + '.enc') do |f|
|
105
|
+
f.write(recrypted_text)
|
106
|
+
mv encrypted_fn + '.enc', encrypted_fn + '.enc.bak'
|
107
|
+
end
|
108
|
+
puts "File was recrypted as #{(encrypted_fn + '.enc').inspect}. You can remove #{(encrypted_fn + '.enc.bak').inspect} now."
|
89
109
|
else
|
90
110
|
usage msg: "Unknown command #{command.inspect}", rc: 1
|
91
111
|
end
|
92
|
-
|
data/complex_config.gemspec
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: complex_config 0.
|
2
|
+
# stub: complex_config 0.15.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.15.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]
|
@@ -195,6 +195,18 @@ class ComplexConfig::Provider
|
|
195
195
|
|
196
196
|
attr_writer :master_key_pathname
|
197
197
|
|
198
|
+
def new_key
|
199
|
+
SecureRandom.hex(16)
|
200
|
+
end
|
201
|
+
|
202
|
+
def valid_key?(key)
|
203
|
+
ks = ComplexConfig::KeySource.new(var: key)
|
204
|
+
ComplexConfig::Encryption.new(ks.key_bytes)
|
205
|
+
ks
|
206
|
+
rescue
|
207
|
+
false
|
208
|
+
end
|
209
|
+
|
198
210
|
private
|
199
211
|
|
200
212
|
def interpret_name_value(name, value)
|
@@ -217,7 +229,7 @@ class ComplexConfig::Provider
|
|
217
229
|
ks =
|
218
230
|
case encrypt
|
219
231
|
when :random
|
220
|
-
ComplexConfig::KeySource.new(var:
|
232
|
+
ComplexConfig::KeySource.new(var: new_key)
|
221
233
|
when true
|
222
234
|
key_source(pathname)
|
223
235
|
when String
|
@@ -156,6 +156,11 @@ RSpec.describe ComplexConfig::Provider do
|
|
156
156
|
it 'can read when key is stored in file' do
|
157
157
|
expect(described_class['with-key-file'].development.foo.bar).to eq 'baz'
|
158
158
|
end
|
159
|
+
|
160
|
+
it 'can check the size of a given key' do
|
161
|
+
expect(described_class).to be_valid_key(key)
|
162
|
+
expect(described_class).not_to be_valid_key(key + ' blub')
|
163
|
+
end
|
159
164
|
end
|
160
165
|
|
161
166
|
context 'writing encrypted configurations' do
|