rails_surrogate_key_logging 1.3.0 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/surrogate_key_logging/action_controller/params.rb +2 -2
- data/lib/surrogate_key_logging/action_controller.rb +1 -1
- data/lib/surrogate_key_logging/action_dispatch.rb +1 -1
- data/lib/surrogate_key_logging/active_record/attributes.rb +1 -1
- data/lib/surrogate_key_logging/active_record.rb +1 -1
- data/lib/surrogate_key_logging/active_support.rb +24 -29
- data/lib/surrogate_key_logging/configuration.rb +2 -2
- data/lib/surrogate_key_logging/engine.rb +13 -6
- data/lib/surrogate_key_logging/key_manager.rb +1 -0
- data/lib/surrogate_key_logging/key_store.rb +1 -1
- data/lib/surrogate_key_logging/sidekiq.rb +11 -0
- data/lib/surrogate_key_logging/version.rb +1 -1
- data/lib/surrogate_key_logging.rb +7 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f5d3a0747a79affaf71480538b5ca2567c962ddf03c6af176661ea082b7427e5
|
4
|
+
data.tar.gz: aec5af8fb44ca382501cef61b9d142328a8befa571df08821e4b9f5ef365490c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8ec40ce47168317e745ed14d707ca7c8a35ce7bd9eec78c7224baf4bcaa5f2a92b8eeade6024a745aa66d018ea11bbb65fb5989461923d635df60cf0eb0f060
|
7
|
+
data.tar.gz: b245a066710ba8440584f4fb51588bf0a968e969ef41eef0ae52e739bfdf266cc40d63770ccc4866917a806437b7d1ebb8eb5bcfdc48f914ee47df44ca60f26e
|
@@ -5,11 +5,11 @@ require 'active_support/concern'
|
|
5
5
|
module SurrogateKeyLogging
|
6
6
|
module ActionController
|
7
7
|
module Params
|
8
|
-
extend ActiveSupport::Concern
|
8
|
+
extend ::ActiveSupport::Concern
|
9
9
|
|
10
10
|
class_methods do
|
11
11
|
def surrogate_params(*params, action: '*')
|
12
|
-
@surrogate_params ||= ActiveSupport::HashWithIndifferentAccess.new {|h,k| h[k] = [] }
|
12
|
+
@surrogate_params ||= ::ActiveSupport::HashWithIndifferentAccess.new {|h,k| h[k] = [] }
|
13
13
|
params.each do |param|
|
14
14
|
param = param.to_s
|
15
15
|
@surrogate_params[action] << param
|
@@ -1,36 +1,31 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
# Add ability for @mask to be a class/instance/lambda/proc
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
value = call(value, parents, original_params)
|
18
|
-
elsif value.is_a?(Array)
|
19
|
-
# If we don't pop the current parent it will be duplicated as we
|
20
|
-
# process each array value.
|
21
|
-
parents.pop if deep_regexps
|
22
|
-
value = value.map { |v| value_for_key(key, v, parents, original_params) }
|
23
|
-
# Restore the parent stack after processing the array.
|
24
|
-
parents.push(key) if deep_regexps
|
25
|
-
elsif blocks.any?
|
26
|
-
key = key.dup if key.duplicable?
|
27
|
-
value = value.dup if value.duplicable?
|
28
|
-
blocks.each { |b| b.arity == 2 ? b.call(key, value) : b.call(key, value, original_params) }
|
29
|
-
end
|
3
|
+
module SurrogateKeyLogging
|
4
|
+
module ActiveSupport
|
5
|
+
# Add ability for @mask to be a class/instance/lambda/proc
|
6
|
+
def value_for_key(key, value, parents = [], original_params = nil) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
|
7
|
+
parents.push(key) if deep_regexps
|
8
|
+
if regexps.any? { |r| r.match?(key.to_s) }
|
9
|
+
value = @mask.respond_to?(:call) ? @mask.call(key, value, parents, original_params) : @mask
|
10
|
+
elsif deep_regexps && (joined = parents.join('.')) && deep_regexps.any? { |r| r.match?(joined) } # rubocop:disable Lint/DuplicateBranch
|
11
|
+
value = @mask.respond_to?(:call) ? @mask.call(key, value, parents, original_params) : @mask
|
12
|
+
elsif value.is_a?(Hash)
|
13
|
+
value = call(value, parents, original_params)
|
14
|
+
elsif value.is_a?(Array)
|
15
|
+
# If we don't pop the current parent it will be duplicated as we
|
16
|
+
# process each array value.
|
30
17
|
parents.pop if deep_regexps
|
31
|
-
value
|
18
|
+
value = value.map { |v| value_for_key(key, v, parents, original_params) }
|
19
|
+
# Restore the parent stack after processing the array.
|
20
|
+
parents.push(key) if deep_regexps
|
21
|
+
elsif blocks.any?
|
22
|
+
key = key.dup if key.duplicable?
|
23
|
+
value = value.dup if value.duplicable?
|
24
|
+
blocks.each { |b| b.arity == 2 ? b.call(key, value) : b.call(key, value, original_params) }
|
32
25
|
end
|
33
|
-
|
26
|
+
parents.pop if deep_regexps
|
27
|
+
value
|
34
28
|
end
|
29
|
+
|
35
30
|
end
|
36
31
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module SurrogateKeyLogging
|
4
|
-
class Config < ActiveSupport::OrderedOptions
|
4
|
+
class Config < ::ActiveSupport::OrderedOptions
|
5
5
|
end
|
6
6
|
|
7
7
|
module Configuration
|
8
|
-
extend ActiveSupport::Concern
|
8
|
+
extend ::ActiveSupport::Concern
|
9
9
|
|
10
10
|
def surrogate_key_logging
|
11
11
|
SurrogateKeyLogging.config
|
@@ -17,11 +17,6 @@ module SurrogateKeyLogging
|
|
17
17
|
g.templates.unshift File.expand_path('lib/templates', root)
|
18
18
|
end
|
19
19
|
|
20
|
-
rake_tasks do
|
21
|
-
# load 'tasks/surrogate_key_logging.rake'
|
22
|
-
# load 'tasks/key_store/active_record.rake'
|
23
|
-
end
|
24
|
-
|
25
20
|
initializer 'surrogate_key_logging.config' do |app|
|
26
21
|
SurrogateKeyLogging.configure do |config|
|
27
22
|
config.enabled = Rails.env.production? unless config.key?(:enabled)
|
@@ -35,7 +30,9 @@ module SurrogateKeyLogging
|
|
35
30
|
end
|
36
31
|
|
37
32
|
initializer 'surrogate_key_logging.middleware' do |app|
|
38
|
-
|
33
|
+
if SurrogateKeyLogging.config.enabled
|
34
|
+
app.middleware.insert_before(0, Middleware)
|
35
|
+
end
|
39
36
|
end
|
40
37
|
|
41
38
|
initializer 'surrogate_key_logging.filter_parameters' do
|
@@ -53,5 +50,15 @@ module SurrogateKeyLogging
|
|
53
50
|
end
|
54
51
|
end
|
55
52
|
|
53
|
+
initializer 'surrogate_key_logging.sidekiq' do
|
54
|
+
if SurrogateKeyLogging.config.enabled && defined?(::Sidekiq)
|
55
|
+
Sidekiq.configure_server do |config|
|
56
|
+
config.server_middleware do |chain|
|
57
|
+
chain.prepend SurrogateKeyLogging::SidekiqMiddleware
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
56
63
|
end
|
57
64
|
end
|
@@ -33,6 +33,7 @@ module SurrogateKeyLogging
|
|
33
33
|
|
34
34
|
def call(_key, value, _parents = [], _original_params = nil)
|
35
35
|
return "" if value.blank?
|
36
|
+
return value unless SurrogateKeyLogging.config.enabled
|
36
37
|
surrogate = get(value)
|
37
38
|
Rails.logger.tagged('SurrogateKeyLogging') { Rails.logger.info "Surrogate: `#{surrogate}`, value: `#{value}`" } if SurrogateKeyLogging.config.debug
|
38
39
|
surrogate
|
@@ -4,7 +4,7 @@ require 'active_support'
|
|
4
4
|
|
5
5
|
# Container Module
|
6
6
|
module SurrogateKeyLogging
|
7
|
-
extend ActiveSupport::Autoload
|
7
|
+
extend ::ActiveSupport::Autoload
|
8
8
|
|
9
9
|
autoload :ActionController
|
10
10
|
autoload :ActionDispatch
|
@@ -41,7 +41,7 @@ module SurrogateKeyLogging
|
|
41
41
|
def reset
|
42
42
|
reset! if config.cache
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
def reset!
|
46
46
|
@key_manager = @parameter_filter = nil
|
47
47
|
end
|
@@ -55,7 +55,7 @@ module SurrogateKeyLogging
|
|
55
55
|
end
|
56
56
|
|
57
57
|
def filter_for_attributes(attrs)
|
58
|
-
::ActiveSupport::ParameterFilter.new(attrs, mask: key_manager)
|
58
|
+
::ActiveSupport::ParameterFilter.new(config.enabled ? attrs : [], mask: key_manager)
|
59
59
|
end
|
60
60
|
|
61
61
|
def key_store
|
@@ -63,11 +63,11 @@ module SurrogateKeyLogging
|
|
63
63
|
end
|
64
64
|
|
65
65
|
def filter_parameters(params)
|
66
|
-
parameter_filter.filter
|
66
|
+
parameter_filter.filter(params)
|
67
67
|
end
|
68
68
|
|
69
69
|
def surrogate_for(value)
|
70
|
-
key_manager.get(value)
|
70
|
+
config.enabled ? key_manager.get(value) : value
|
71
71
|
end
|
72
72
|
|
73
73
|
def add_param_to_filter(attr, *parents)
|
@@ -84,6 +84,8 @@ module SurrogateKeyLogging
|
|
84
84
|
|
85
85
|
end
|
86
86
|
|
87
|
+
require 'active_support/parameter_filter'
|
88
|
+
::ActiveSupport::ParameterFilter::CompiledFilter.send(:prepend, ActiveSupport)
|
87
89
|
KeyStore.eager_load!
|
88
90
|
::Rails::Application::Configuration.send(:include, Configuration)
|
89
91
|
require 'surrogate_key_logging/engine'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_surrogate_key_logging
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Taylor Yelverton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-07-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|