wbconfigurator 0.2 → 0.2.1

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: 3ffd332828a7b6fd0f0bbecc8687fa6c8106a23784edce28b8e8cf1795579f70
4
- data.tar.gz: 8766eb08427c53b35f28208831b901987f15b3b42d548711cce537371d40684e
3
+ metadata.gz: 98be19c8fa6f73d1e47870db4705593b72ff32e912bde9f80160555725fac942
4
+ data.tar.gz: 253c4e7e0892c355f585242552035a19d8eaf948eb090d7c5f6374648207d674
5
5
  SHA512:
6
- metadata.gz: 5b79a2ea876cbe2349a093d0877a41c8cb3340ee20959e15476d21e9a649d7dab492236e1abf3a5314a479716d11d7aad4ffab76f6058358c8e0252ec3b0aaff
7
- data.tar.gz: ac9656c2ef10c9fddd1b1e4f58999f5f1370d5be6b3ee447f1c97f05644b108c01048d3d895f0fdbd18493c7f925dc9946d5baea47cc22df7e9a119340cf57c7
6
+ metadata.gz: 75df96a0f04acc4560a2701a3c4152937dbcb0e2e848910d81cfb7769684e62f925910a792061071d05be8cb5b3ff09fe235294eb3201e0e3222d2ac96354b57
7
+ data.tar.gz: eb64974f3661fc19d386e009c6951330c9cab7b62ea102bb60ac231e919f7013ccbf76d3977a4a35a127a4c1dc1dea3e1812a4654bfd25a29971a9b6ed4ced0c
data/Gemfile CHANGED
@@ -4,3 +4,8 @@
4
4
  source 'https://rubygems.org'
5
5
 
6
6
  gem 'secure_yaml'
7
+
8
+ group :test do
9
+ gem 'rspec', '~> 3.7'
10
+ gem 'pry'
11
+ end
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
- ruby
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
- 1.17.3
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 'configurator', git: 'https://github.com/wildbit/configurator.git'
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,6 +2,7 @@
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'
7
8
 
@@ -155,4 +156,8 @@ module App
155
156
  def self.config
156
157
  @config ||= Configurator.new
157
158
  end
159
+
160
+ def self.clear_config
161
+ @config = Configurator.new
162
+ end
158
163
  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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Configurator
4
- VERSION = '0.2'
4
+ VERSION = '0.2.1'
5
5
  end
data/spec/data/db.yaml ADDED
@@ -0,0 +1,2 @@
1
+ username: admin
2
+ password: admin
@@ -0,0 +1,2 @@
1
+ retry_count: 2
2
+ display_errors: true
@@ -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,26 @@
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
+ it '.load_all!' do
10
+ App.config.load_all!
11
+
12
+ aggregate_failures do
13
+ expect(App.config.test.display_errors).to be true
14
+ expect(App.config.db.username).to eq('admin')
15
+ end
16
+ end
17
+
18
+ it '.load! - valid file' do
19
+ App.config.load!(:db)
20
+ expect(App.config.db.username).to eq('admin')
21
+ end
22
+
23
+ it '.load! - invalid file' do
24
+ expect { App.config.load!(:dbs) }.to raise_error /Configuration file.*doesn't exist on path/
25
+ end
26
+ 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: '0.2'
4
+ version: 0.2.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: 2020-08-03 00:00:00.000000000 Z
11
+ date: 2021-02-11 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.0.8
63
- signing_key:
67
+ rubygems_version: 3.0.9
68
+ signing_key:
64
69
  specification_version: 4
65
70
  summary: Config tool.
66
71
  test_files: []