active_support-encrypted_redis_cache_store 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: cf670f192950a69ebc8585160f2743290cd08363a5b7722788bef401bf3ef2cc
4
+ data.tar.gz: 53032fef1d08001b06ab94ac052ab72842ebda8fd0b12eb3b41b5effd7bb6b41
5
+ SHA512:
6
+ metadata.gz: dd19ec36d0ae2cde5e566ac0db9d7db03ef5b00bb6df91f7a54f7512f0996717b78457943c62300c0fc4c2c27d06008b5468c85aa4a2943b965e77ed94a27668
7
+ data.tar.gz: 01eac96a9ef864543890174293d514fd83442271c85b8a9eade3ab8c14f11a389f7243ae4866e40d14158c811b4cc7f428f589f5bb9eeaf2d6650187b15472d3
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,77 @@
1
+ AllCops:
2
+ Exclude:
3
+ - 'bin/*'
4
+ - 'db/**/*'
5
+ - 'vendor/**/*'
6
+ - '**/Rakefile'
7
+ - '**/config.ru'
8
+ - 'node_modules/**/*'
9
+ TargetRubyVersion: 2.5
10
+ DisplayCopNames: true
11
+
12
+ Performance:
13
+ Enabled: false
14
+
15
+ Bundler:
16
+ Enabled: false
17
+
18
+ Naming:
19
+ Enabled: false
20
+
21
+ Metrics/BlockNesting:
22
+ Enabled: false
23
+
24
+ Metrics/ClassLength:
25
+ Enabled: false
26
+
27
+ Metrics/LineLength:
28
+ Enabled: false
29
+
30
+ Metrics/MethodLength:
31
+ Enabled: false
32
+
33
+ Metrics/BlockLength:
34
+ Enabled: false
35
+
36
+ Metrics/ModuleLength:
37
+ Enabled: false
38
+
39
+ Style/AsciiComments:
40
+ Enabled: false
41
+
42
+ Style/BlockDelimiters:
43
+ Exclude:
44
+ - 'spec/**/*'
45
+
46
+ Style/Documentation:
47
+ Enabled: false
48
+
49
+ Style/BlockDelimiters:
50
+ Enabled: false
51
+
52
+ Style/DoubleNegation:
53
+ Enabled: false
54
+
55
+ Style/GuardClause:
56
+ Enabled: false
57
+
58
+ Style/ClassAndModuleChildren:
59
+ Enabled: false
60
+
61
+ Style/SpecialGlobalVars:
62
+ Enabled: false
63
+
64
+ Style/NumericPredicate:
65
+ Enabled: false
66
+
67
+ Style/Lambda:
68
+ Enabled: false
69
+
70
+ Layout/AlignParameters:
71
+ EnforcedStyle: with_fixed_indentation
72
+
73
+ Layout/MultilineMethodCallIndentation:
74
+ EnforcedStyle: indented
75
+
76
+ Lint/AmbiguousRegexpLiteral:
77
+ Enabled: false
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.0
5
+ before_install: gem install bundler -v 1.16.1
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in activesupport-encrypted_redis_store.gemspec
8
+ gemspec
9
+
10
+ gem 'fakeredis', require: 'fakeredis/rspec'
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ guard :rspec, cmd: 'bundle exec rspec' do
4
+ require 'guard/rspec/dsl'
5
+ dsl = Guard::RSpec::Dsl.new(self)
6
+
7
+ # Feel free to open issues for suggestions and improvements
8
+
9
+ # RSpec files
10
+ rspec = dsl.rspec
11
+ watch(rspec.spec_helper) { rspec.spec_dir }
12
+ watch(rspec.spec_support) { rspec.spec_dir }
13
+ watch(rspec.spec_files)
14
+
15
+ # Ruby files
16
+ ruby = dsl.ruby
17
+ dsl.watch_spec_files_for(ruby.lib_files)
18
+
19
+ # Rails files
20
+ rails = dsl.rails(view_extensions: %w[erb haml slim])
21
+ dsl.watch_spec_files_for(rails.app_files)
22
+ dsl.watch_spec_files_for(rails.views)
23
+
24
+ watch(rails.controllers) do |m|
25
+ [
26
+ rspec.spec.call("routing/#{m[1]}_routing"),
27
+ rspec.spec.call("controllers/#{m[1]}_controller"),
28
+ rspec.spec.call("acceptance/#{m[1]}")
29
+ ]
30
+ end
31
+
32
+ # Rails config changes
33
+ watch(rails.spec_helper) { rspec.spec_dir }
34
+ watch(rails.routes) { "#{rspec.spec_dir}/routing" }
35
+ watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
36
+
37
+ # Capybara features specs
38
+ watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
39
+ watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }
40
+
41
+ # Turnip features and steps
42
+ watch(%r{^spec/acceptance/(.+)\.feature$})
43
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
44
+ Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance'
45
+ end
46
+ end
47
+
48
+ guard :rubocop, all_on_start: false, cli: ['--auto-correct'] do
49
+ watch(/.+\.rb$/)
50
+ watch(%r{(?:.+/)?\.rubocop(?:_todo)?\.yml$}) { |m| File.dirname(m[0]) }
51
+ end
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 alpaca-tc
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,38 @@
1
+ # Activesupport::Cache::EncryptedRedisStore
2
+
3
+ active_support-encrypted_redis_store provides a encrypted cache for ActiveSupport.
4
+ It protects your critical data by enabling runtime encryption in the redis_cache.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'active_support-encrypted_redis_cache_store'
12
+ ```
13
+
14
+ ## Usage
15
+
16
+ Configure cache_store in your rails application.
17
+
18
+ ```ruby
19
+ # config/application.rb
20
+ config.cache_store = :encrypted_redis_cache_store, {
21
+ url: 'redis://localhost:6379',
22
+ encryptor_key: ENV['ENCRYPTOR_KEY'] #=> '2268e7bddbd13663dca12a75ad14c392' Generated by `ActiveSupport::EncryptedFile.generate_key`
23
+ }
24
+ ```
25
+
26
+ ## Development
27
+
28
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
29
+
30
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
31
+
32
+ ## Contributing
33
+
34
+ Bug reports and pull requests are welcome on GitHub at https://github.com/alpaca-tc/active_support-encrypted_redis_store.
35
+
36
+ ## License
37
+
38
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'active_support/cache/encrypted_redis_cache_store'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'active_support-encrypted_redis_cache_store'
9
+ spec.version = ActiveSupport::Cache::EncryptedRedisCacheStore::VERSION
10
+ spec.authors = ['alpaca-tc']
11
+ spec.email = ['alpaca-tc@alpaca.tc']
12
+
13
+ spec.summary = 'active_support-encrypted_redis_store provides a encrypted cache for ActiveSupport.'
14
+ spec.description = 'active_support-encrypted_redis_store provides a encrypted cache for ActiveSupport. It protects your critical data by enabling runtime encryption in the redis_cache'
15
+ spec.homepage = 'https://github.com/alpaca-tc/active_support-encrypted_redis_cache_store'
16
+ spec.license = 'MIT'
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
19
+ f.match(%r{^(test|spec|features)/})
20
+ end
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_dependency 'activesupport', '>= 5.2.0.rc2'
24
+ spec.add_dependency 'redis', '>= 4.0.1'
25
+
26
+ spec.add_development_dependency 'bundler', '~> 1.16'
27
+ spec.add_development_dependency 'guard-rspec'
28
+ spec.add_development_dependency 'guard-rubocop'
29
+ spec.add_development_dependency 'pry'
30
+ spec.add_development_dependency 'rake', '~> 10.0'
31
+ spec.add_development_dependency 'rspec', '~> 3.0'
32
+ spec.add_development_dependency 'rubocop'
33
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/cache'
4
+ require 'active_support/cache/redis_cache_store'
5
+ require 'active_support/encrypted_file'
6
+ require 'active_support/message_encryptor'
7
+
8
+ module ActiveSupport
9
+ module Cache
10
+ class EncryptedRedisCacheStore < RedisCacheStore
11
+ VERSION = '0.1.0'
12
+
13
+ attr_reader :encryptor_key
14
+
15
+ def initialize(encryptor_key: nil, **options)
16
+ @encryptor_key = encryptor_key
17
+
18
+ unless encryptor_key
19
+ raise ArgumentError, 'missing :encryptor_key option. Please generate encryptor_key `ActiveSupport::EncryptedFile.generate_key`'
20
+ end
21
+
22
+ super(**options)
23
+ end
24
+
25
+ private
26
+
27
+ def failsafe_decryption(method, returning: nil)
28
+ yield
29
+ rescue ActiveSupport::MessageEncryptor::InvalidMessage => exception
30
+ handle_exception(exception: exception, method: method, returning: returning)
31
+ returning
32
+ end
33
+
34
+ def deserialize_entry(serialized_entry)
35
+ return unless serialized_entry
36
+
37
+ decrypted = failsafe_decryption(:deserialize_entry) do
38
+ encryptor.decrypt_and_verify(serialized_entry)
39
+ end
40
+
41
+ super(decrypted) if decrypted
42
+ end
43
+
44
+ def serialize_entry(*)
45
+ encryptor.encrypt_and_sign(super)
46
+ end
47
+
48
+ def encryptor
49
+ @encryptor ||= ActiveSupport::MessageEncryptor.new(
50
+ [encryptor_key].pack('H*'),
51
+ cipher: 'aes-128-gcm'
52
+ )
53
+ end
54
+ end
55
+ end
56
+ end
metadata ADDED
@@ -0,0 +1,182 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_support-encrypted_redis_cache_store
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - alpaca-tc
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-03-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 5.2.0.rc2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 5.2.0.rc2
27
+ - !ruby/object:Gem::Dependency
28
+ name: redis
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 4.0.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 4.0.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.16'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.16'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard-rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: guard-rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '10.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '10.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: active_support-encrypted_redis_store provides a encrypted cache for ActiveSupport.
140
+ It protects your critical data by enabling runtime encryption in the redis_cache
141
+ email:
142
+ - alpaca-tc@alpaca.tc
143
+ executables: []
144
+ extensions: []
145
+ extra_rdoc_files: []
146
+ files:
147
+ - ".gitignore"
148
+ - ".rspec"
149
+ - ".rubocop.yml"
150
+ - ".travis.yml"
151
+ - Gemfile
152
+ - Guardfile
153
+ - LICENSE.txt
154
+ - README.md
155
+ - Rakefile
156
+ - active_support-encrypted_redis_cache_store.gemspec
157
+ - lib/active_support/cache/encrypted_redis_cache_store.rb
158
+ homepage: https://github.com/alpaca-tc/active_support-encrypted_redis_cache_store
159
+ licenses:
160
+ - MIT
161
+ metadata: {}
162
+ post_install_message:
163
+ rdoc_options: []
164
+ require_paths:
165
+ - lib
166
+ required_ruby_version: !ruby/object:Gem::Requirement
167
+ requirements:
168
+ - - ">="
169
+ - !ruby/object:Gem::Version
170
+ version: '0'
171
+ required_rubygems_version: !ruby/object:Gem::Requirement
172
+ requirements:
173
+ - - ">="
174
+ - !ruby/object:Gem::Version
175
+ version: '0'
176
+ requirements: []
177
+ rubyforge_project:
178
+ rubygems_version: 2.7.3
179
+ signing_key:
180
+ specification_version: 4
181
+ summary: active_support-encrypted_redis_store provides a encrypted cache for ActiveSupport.
182
+ test_files: []