Module: Datadog::AppSec::Contrib::Rails::Patcher
- Defined in:
- lib/datadog/appsec/contrib/rails/patcher.rb
Overview
Patcher for AppSec on Rails
Defined Under Namespace
Modules: ProcessActionPatch
Constant Summary
collapse
- BEFORE_INITIALIZE_ONLY_ONCE_PER_APP =
Hash.new { |h, key| h[key] = Datadog::Core::Utils::OnlyOnce.new }
- AFTER_INITIALIZE_ONLY_ONCE_PER_APP =
Hash.new { |h, key| h[key] = Datadog::Core::Utils::OnlyOnce.new }
Class Method Summary
collapse
Class Method Details
.add_middleware(app) ⇒ Object
.after_initialize(app) ⇒ Object
137
138
139
140
141
142
143
144
|
# File 'lib/datadog/appsec/contrib/rails/patcher.rb', line 137
def after_initialize(app)
AFTER_INITIALIZE_ONLY_ONCE_PER_APP[app].run do
setup_security
inspect_middlewares(app)
end
end
|
.before_initialize(app) ⇒ Object
47
48
49
50
51
52
53
54
|
# File 'lib/datadog/appsec/contrib/rails/patcher.rb', line 47
def before_initialize(app)
BEFORE_INITIALIZE_ONLY_ONCE_PER_APP[app].run do
add_middleware(app) if Datadog.configuration.tracing[:rails][:middleware]
patch_process_action
end
end
|
.include_middleware?(middleware, app) ⇒ Boolean
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
# File 'lib/datadog/appsec/contrib/rails/patcher.rb', line 93
def include_middleware?(middleware, app)
found = false
app.middleware.instance_variable_get(:@operations).each do |operation|
args = case operation
when Array
_op, args = operation
args
when Proc
if operation.binding.local_variables.include?(:args)
operation.binding.local_variable_get(:args)
else
args_getter = Class.new do
def method_missing(_op, *args) args
end
end.new
operation.call(args_getter)
end
else
[]
end
found = true if args.include?(middleware)
end
found
end
|
.inspect_middlewares(app) ⇒ Object
127
128
129
|
# File 'lib/datadog/appsec/contrib/rails/patcher.rb', line 127
def inspect_middlewares(app)
Datadog.logger.debug { +'Rails middlewares: ' << app.middleware.map(&:inspect).inspect }
end
|
.patch ⇒ Object
33
34
35
36
37
38
39
|
# File 'lib/datadog/appsec/contrib/rails/patcher.rb', line 33
def patch
Gateway::Watcher.watch
patch_before_initialize
patch_after_initialize
Patcher.instance_variable_set(:@patched, true)
end
|
.patch_after_initialize ⇒ Object
.patch_before_initialize ⇒ Object
.patch_process_action ⇒ Object
89
90
91
|
# File 'lib/datadog/appsec/contrib/rails/patcher.rb', line 89
def patch_process_action
::ActionController::Metal.prepend(ProcessActionPatch)
end
|
.patched? ⇒ Boolean
25
26
27
|
# File 'lib/datadog/appsec/contrib/rails/patcher.rb', line 25
def patched?
Patcher.instance_variable_get(:@patched)
end
|
.target_version ⇒ Object
29
30
31
|
# File 'lib/datadog/appsec/contrib/rails/patcher.rb', line 29
def target_version
Integration.version
end
|