shared-settings 0.1.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.
@@ -0,0 +1,15 @@
1
+ module SharedSettings
2
+ module Utilities
3
+ module Base16
4
+ def self.string_to_bytes(str)
5
+ str.scan(/../).inject('') do |binary, hex_char|
6
+ binary << hex_char.to_i(16).chr
7
+ end
8
+ end
9
+
10
+ def self.bytes_to_string(bytestring)
11
+ bytestring.unpack1('H*').upcase
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,56 @@
1
+ require 'openssl'
2
+ require 'securerandom'
3
+
4
+ module SharedSettings
5
+ module Utilities
6
+ class Encryption
7
+ INIT_VEC_SIZE = 16
8
+ AES_BLOCK_SIZE = 16
9
+ ENCRYPTION_KEY_SIZE = 32
10
+
11
+ ENCRYPTION_ALGORITHM = 'AES-256-CBC'.freeze
12
+
13
+ def self.generate_aes_key(size = ENCRYPTION_KEY_SIZE)
14
+ # .upcase is to match the Elixir implementation
15
+ SecureRandom.hex(size).upcase
16
+ end
17
+
18
+ def initialize(key)
19
+ @key = key
20
+ end
21
+
22
+ def encrypt(clear_text)
23
+ init_vec = Encryption.generate_aes_key(INIT_VEC_SIZE)
24
+ cipher_instance = encryption_cipher(init_vec)
25
+ encrypted_data = cipher_instance.update(clear_text) + cipher_instance.final
26
+
27
+ [init_vec, Base16.bytes_to_string(encrypted_data)]
28
+ end
29
+
30
+ def decrypt(init_vec, cipher_text)
31
+ cipher_data = Base16.string_to_bytes(cipher_text)
32
+ cipher_instance = decryption_cipher(init_vec)
33
+
34
+ cipher_instance.update(cipher_data) + cipher_instance.final
35
+ end
36
+
37
+ private
38
+
39
+ def encryption_cipher(init_vec)
40
+ build_cipher(OpenSSL::Cipher.new(ENCRYPTION_ALGORITHM).encrypt, init_vec)
41
+ end
42
+
43
+ def decryption_cipher(init_vec)
44
+ build_cipher(OpenSSL::Cipher.new(ENCRYPTION_ALGORITHM).decrypt, init_vec)
45
+ end
46
+
47
+ def build_cipher(cipher, init_vec)
48
+ cipher.iv = Base16.string_to_bytes(init_vec)
49
+ cipher.key = Base16.string_to_bytes(@key)
50
+ cipher.padding = AES_BLOCK_SIZE
51
+
52
+ cipher
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,3 @@
1
+ module SharedSettings
2
+ VERSION = '0.1.0'.freeze
3
+ end
@@ -0,0 +1,24 @@
1
+ require_relative 'lib/shared_settings/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'shared-settings-ui'
5
+ spec.version = SharedSettings::VERSION
6
+ spec.authors = ['Kieran Eglin']
7
+
8
+ spec.summary = 'UI for shared-settings'
9
+ spec.description = 'A UI management interface for the shared-settings Gem'
10
+ spec.license = 'MIT'
11
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
12
+
13
+ # Specify which files should be added to the gem when it is released.
14
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
15
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
16
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ end
18
+ spec.bindir = 'exe'
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_dependency 'rack', '>= 2.0', '< 3'
23
+ spec.add_dependency 'shared-settings', "~> #{SharedSettings::VERSION}"
24
+ end
@@ -0,0 +1,21 @@
1
+ require_relative 'lib/shared_settings/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'shared-settings'
5
+ spec.version = SharedSettings::VERSION
6
+ spec.authors = ['Kieran Eglin']
7
+
8
+ spec.summary = 'Easily manage runtime settings'
9
+ spec.description = 'Manage runtime and encrypt settings for your Ruby app with optional support for Elixir'
10
+ spec.license = 'MIT'
11
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
12
+
13
+ # Specify which files should be added to the gem when it is released.
14
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
15
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
16
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ end
18
+ spec.bindir = 'exe'
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shared-settings
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kieran Eglin
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-03-03 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Manage runtime and encrypt settings for your Ruby app with optional support
14
+ for Elixir
15
+ email:
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".github/workflows/ruby.yml"
21
+ - ".gitignore"
22
+ - ".rubocop.yml"
23
+ - Gemfile
24
+ - Gemfile.lock
25
+ - LICENSE.txt
26
+ - README.md
27
+ - Rakefile
28
+ - bin/console
29
+ - bin/setup
30
+ - lib/shared-settings-ui.rb
31
+ - lib/shared-settings.rb
32
+ - lib/shared_settings/configuration.rb
33
+ - lib/shared_settings/instance.rb
34
+ - lib/shared_settings/persistence/redis.rb
35
+ - lib/shared_settings/serialized_setting.rb
36
+ - lib/shared_settings/setting.rb
37
+ - lib/shared_settings/ui.rb
38
+ - lib/shared_settings/ui/action.rb
39
+ - lib/shared_settings/ui/actions/asset.rb
40
+ - lib/shared_settings/ui/actions/mount.rb
41
+ - lib/shared_settings/ui/actions/setting.rb
42
+ - lib/shared_settings/ui/assets/app.css
43
+ - lib/shared_settings/ui/assets/app.js
44
+ - lib/shared_settings/ui/assets/chunks.js
45
+ - lib/shared_settings/ui/middleware.rb
46
+ - lib/shared_settings/utilities/base16.rb
47
+ - lib/shared_settings/utilities/encryption.rb
48
+ - lib/shared_settings/version.rb
49
+ - shared-settings-ui.gemspec
50
+ - shared-settings.gemspec
51
+ homepage:
52
+ licenses:
53
+ - MIT
54
+ metadata: {}
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 2.3.0
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubygems_version: 3.1.2
71
+ signing_key:
72
+ specification_version: 4
73
+ summary: Easily manage runtime settings
74
+ test_files: []