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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c28053b61dff2ae48b2da22e7bd5e8f2bcc80f48fdeaf490c9a2a607d4e876c9
4
- data.tar.gz: cadf63913aeebf969f0f99d76a6be2e6c06cad5304f40699b96dce0fcd77e8f5
3
+ metadata.gz: 8e2e094436710a9fe5569cdb635d9d2230c07d401a084120d8d3a66e0b545155
4
+ data.tar.gz: 9d5d62f7903c36706445ab9b2f81b720aaf6c20bbc5e04a2aefc28d9a9c4e237
5
5
  SHA512:
6
- metadata.gz: e00cb460bb319128e56fa2ea8607bdaa93a16bf64c279d2480d417633688e80eb8fc6e2ea905345862dbc8ad2174ef6d30b218742addb055108b9933c07142ee
7
- data.tar.gz: 49a16f1422acee6f938c09e4de0fee07861b765c1ada576ecad07bb957f35fc0d6d35119287717af7ad8c4936de874d15a3c661a5069212af763dbfcc7022102
6
+ metadata.gz: 88b09d7bdd720f1fce793ac31592315d41268a76014fec760728b3a837b569fe294af91171534c2bdd20f71802bba68c1a06e8fc1a1d32759b50de3fe0cf2117
7
+ data.tar.gz: 7708530ed03359d75b9ef2be05014289f090399a5ff1cbbde1aceab1313245153ce3574b1a6d1bcef9649620a0b877307cdcc689685f5c6cfc16f529d03d699b
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.14.1
1
+ 0.15.0
@@ -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 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)
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
-
@@ -1,9 +1,9 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: complex_config 0.14.1 ruby lib
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.14.1"
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]
@@ -10,7 +10,6 @@ class ComplexConfig::Encryption
10
10
  end
11
11
 
12
12
  def encrypt(text)
13
-
14
13
  @cipher.encrypt
15
14
  @cipher.key = @secret
16
15
  iv = @cipher.random_iv
@@ -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: SecureRandom.hex(16))
232
+ ComplexConfig::KeySource.new(var: new_key)
221
233
  when true
222
234
  key_source(pathname)
223
235
  when String
@@ -1,6 +1,6 @@
1
1
  module ComplexConfig
2
2
  # ComplexConfig version
3
- VERSION = '0.14.1'
3
+ VERSION = '0.15.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:
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: complex_config
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.1
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank