wbconfigurator 0.2 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +5 -0
- data/Gemfile.lock +23 -2
- data/README.md +2 -2
- data/lib/config/app.rb +9 -2
- data/lib/config/patch/secure_yaml/cipher.rb +39 -0
- data/lib/config/version.rb +1 -1
- data/spec/data/db.yaml +2 -0
- data/spec/data/test.yaml +4 -0
- data/spec/spec_helper.rb +13 -0
- data/spec/unit/app_spec.rb +48 -0
- metadata +11 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c6a0a05711b29eb8bd8c4eefaa2d45d9fab0813a8a8db1cb6dec7083f6a3475
|
4
|
+
data.tar.gz: e456a5d8e1efff923292fa2e48f2f140d5dc51febd8dce95afdae4c97594d792
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 30b89d75958aeb943d2b79d2e7cf315cda716368d3269d6b13e5925deda36e995fd171fa1be5eda8553cf241cd1222f9136cff81957be44971c0209fe96f54ab
|
7
|
+
data.tar.gz: 41913c7f625b270c6510edb91b32ff8abcb4833d16a837ee5281c7f7192be202cc506d79e4f46ba60dc091361a88db906a2e9c4d411b18296ecc6a09d8757f95
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,13 +1,34 @@
|
|
1
1
|
GEM
|
2
2
|
remote: https://rubygems.org/
|
3
3
|
specs:
|
4
|
+
coderay (1.1.3)
|
5
|
+
diff-lcs (1.4.4)
|
6
|
+
method_source (1.0.0)
|
7
|
+
pry (0.14.0)
|
8
|
+
coderay (~> 1.1)
|
9
|
+
method_source (~> 1.0)
|
10
|
+
rspec (3.10.0)
|
11
|
+
rspec-core (~> 3.10.0)
|
12
|
+
rspec-expectations (~> 3.10.0)
|
13
|
+
rspec-mocks (~> 3.10.0)
|
14
|
+
rspec-core (3.10.1)
|
15
|
+
rspec-support (~> 3.10.0)
|
16
|
+
rspec-expectations (3.10.1)
|
17
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
18
|
+
rspec-support (~> 3.10.0)
|
19
|
+
rspec-mocks (3.10.2)
|
20
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
21
|
+
rspec-support (~> 3.10.0)
|
22
|
+
rspec-support (3.10.2)
|
4
23
|
secure_yaml (2.0.2)
|
5
24
|
|
6
25
|
PLATFORMS
|
7
|
-
|
26
|
+
x86_64-darwin-19
|
8
27
|
|
9
28
|
DEPENDENCIES
|
29
|
+
pry
|
30
|
+
rspec (~> 3.7)
|
10
31
|
secure_yaml
|
11
32
|
|
12
33
|
BUNDLED WITH
|
13
|
-
|
34
|
+
2.2.9
|
data/README.md
CHANGED
@@ -14,7 +14,7 @@ You can use the library with a Bundler.
|
|
14
14
|
With Bundler:
|
15
15
|
|
16
16
|
``` ruby
|
17
|
-
gem '
|
17
|
+
gem 'wbconfigurator'
|
18
18
|
```
|
19
19
|
|
20
20
|
## Issues & Comments
|
@@ -28,4 +28,4 @@ Configurator library is released under the [MIT](http://www.opensource.org/licen
|
|
28
28
|
|
29
29
|
## Copyright
|
30
30
|
|
31
|
-
Copyright © 2020 Wildbit LLC.
|
31
|
+
Copyright © 2020 Wildbit LLC.
|
data/lib/config/app.rb
CHANGED
@@ -2,8 +2,10 @@
|
|
2
2
|
|
3
3
|
require 'yaml'
|
4
4
|
require 'secure_yaml'
|
5
|
+
require_relative 'patch/secure_yaml/cipher'
|
5
6
|
require 'singleton'
|
6
7
|
require 'ostruct'
|
8
|
+
require 'erb'
|
7
9
|
|
8
10
|
# App::Configuration class helps loading configuration files.
|
9
11
|
#
|
@@ -126,7 +128,8 @@ module App
|
|
126
128
|
end
|
127
129
|
|
128
130
|
def load_from_yaml(filename)
|
129
|
-
|
131
|
+
yaml_file = ERB.new(File.read(file_full_path(filename))).result
|
132
|
+
SecureYaml.load(yaml_file)
|
130
133
|
end
|
131
134
|
|
132
135
|
# generate accessors for loaded data
|
@@ -155,4 +158,8 @@ module App
|
|
155
158
|
def self.config
|
156
159
|
@config ||= Configurator.new
|
157
160
|
end
|
158
|
-
|
161
|
+
|
162
|
+
def self.clear_config
|
163
|
+
@config = Configurator.new
|
164
|
+
end
|
165
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'openssl'
|
2
|
+
require 'digest/sha2'
|
3
|
+
require 'base64'
|
4
|
+
|
5
|
+
module SecureYaml
|
6
|
+
|
7
|
+
class Cipher
|
8
|
+
|
9
|
+
def encrypt(secret_key, plain_data)
|
10
|
+
cipher = create_cipher(secret_key, :encrypt)
|
11
|
+
strip_newline_chars_from_base64(Base64.encode64(cipher.update(plain_data) + cipher.final))
|
12
|
+
end
|
13
|
+
|
14
|
+
def decrypt(secret_key, encrypted_data)
|
15
|
+
cipher = create_cipher(secret_key, :decrypt)
|
16
|
+
cipher.update(Base64.decode64(encrypted_data)) + cipher.final
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def create_cipher(secret_key, type)
|
22
|
+
cipher = retrieve_encryption_type(type)
|
23
|
+
cipher.key = Digest::SHA2.new(256).digest(secret_key)
|
24
|
+
cipher
|
25
|
+
end
|
26
|
+
|
27
|
+
def retrieve_encryption_type(type = :encrypt)
|
28
|
+
cipher = OpenSSL::Cipher.new("AES-256-CFB")
|
29
|
+
type == :encrypt ? cipher.encrypt : cipher.decrypt
|
30
|
+
cipher
|
31
|
+
end
|
32
|
+
|
33
|
+
def strip_newline_chars_from_base64(base64)
|
34
|
+
base64.gsub("\n", '')
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
data/lib/config/version.rb
CHANGED
data/spec/data/db.yaml
ADDED
data/spec/data/test.yaml
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rspec'
|
4
|
+
require 'configurator'
|
5
|
+
require 'pry'
|
6
|
+
|
7
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
8
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
9
|
+
|
10
|
+
RSpec.configure do |c|
|
11
|
+
c.formatter = :documentation
|
12
|
+
c.color = true
|
13
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Configurator' do
|
4
|
+
before(:each) do
|
5
|
+
App.clear_config
|
6
|
+
App.config.files_path = File.join(File.dirname(__FILE__), '../data/')
|
7
|
+
end
|
8
|
+
|
9
|
+
context 'loading' do
|
10
|
+
it '.load_all!' do
|
11
|
+
expect { App.config.load_all! }.not_to raise_error
|
12
|
+
end
|
13
|
+
|
14
|
+
it '.load! - valid file' do
|
15
|
+
expect { App.config.load!(:db) }.not_to raise_error
|
16
|
+
end
|
17
|
+
|
18
|
+
it '.load! - invalid file' do
|
19
|
+
expect { App.config.load!(:dbs) }.to raise_error /Configuration file.*doesn't exist on path/
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'content' do
|
24
|
+
it 'all config files' do
|
25
|
+
App.config.load_all!
|
26
|
+
|
27
|
+
aggregate_failures do
|
28
|
+
expect(App.config.test.display_errors).to be true
|
29
|
+
expect(App.config.db.username).to eq('admin')
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'single file' do
|
34
|
+
App.config.load!(:db)
|
35
|
+
expect(App.config.db.username).to eq('admin')
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'erb content' do
|
39
|
+
App.config.load!(:test)
|
40
|
+
expect(App.config.test.error_id).to eq('error_2')
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'erb content - boolean' do
|
44
|
+
App.config.load!(:test)
|
45
|
+
expect(App.config.test.boolean).to eq(true)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wbconfigurator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Igor Balos
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: secure_yaml
|
@@ -38,13 +38,18 @@ files:
|
|
38
38
|
- README.md
|
39
39
|
- configurator.gemspec
|
40
40
|
- lib/config/app.rb
|
41
|
+
- lib/config/patch/secure_yaml/cipher.rb
|
41
42
|
- lib/config/version.rb
|
42
43
|
- lib/configurator.rb
|
44
|
+
- spec/data/db.yaml
|
45
|
+
- spec/data/test.yaml
|
46
|
+
- spec/spec_helper.rb
|
47
|
+
- spec/unit/app_spec.rb
|
43
48
|
homepage: https://github.com/wildbit/configurator
|
44
49
|
licenses:
|
45
50
|
- MIT
|
46
51
|
metadata: {}
|
47
|
-
post_install_message:
|
52
|
+
post_install_message:
|
48
53
|
rdoc_options: []
|
49
54
|
require_paths:
|
50
55
|
- lib
|
@@ -59,8 +64,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
59
64
|
- !ruby/object:Gem::Version
|
60
65
|
version: 1.9.3
|
61
66
|
requirements: []
|
62
|
-
rubygems_version: 3.
|
63
|
-
signing_key:
|
67
|
+
rubygems_version: 3.2.3
|
68
|
+
signing_key:
|
64
69
|
specification_version: 4
|
65
70
|
summary: Config tool.
|
66
71
|
test_files: []
|