Skip to content

Commit

Permalink
SAVEPOINT
Browse files Browse the repository at this point in the history
  • Loading branch information
lloeki committed Oct 5, 2022
1 parent 706045a commit 3a21a7e
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 67 deletions.
16 changes: 8 additions & 8 deletions lib/datadog/appsec/contrib/rack/gateway/watcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def self.watch
trace = active_trace
span = active_span

Rack::Reactive::Request.subscribe(op, waf_context) do |action, result, _block|
record = [:block, :monitor].include?(action)
Rack::Reactive::Request.subscribe(op, waf_context) do |result, _block|
record = [:match].include?(result.status)
if record
# TODO: should this hash be an Event instance instead?
event = {
Expand All @@ -42,7 +42,7 @@ def self.watch
end
end

_action, _result, block = Rack::Reactive::Request.publish(op, request)
_result, block = Rack::Reactive::Request.publish(op, request)
end

next [nil, [[:block, event]]] if block
Expand All @@ -66,8 +66,8 @@ def self.watch
trace = active_trace
span = active_span

Rack::Reactive::Response.subscribe(op, waf_context) do |action, result, _block|
record = [:block, :monitor].include?(action)
Rack::Reactive::Response.subscribe(op, waf_context) do |result, _block|
record = [:match].include?(result.status)
if record
# TODO: should this hash be an Event instance instead?
event = {
Expand All @@ -82,7 +82,7 @@ def self.watch
end
end

_action, _result, block = Rack::Reactive::Response.publish(op, response)
_result, block = Rack::Reactive::Response.publish(op, response)
end

next [nil, [[:block, event]]] if block
Expand All @@ -107,7 +107,7 @@ def self.watch
span = active_span

Rack::Reactive::RequestBody.subscribe(op, waf_context) do |action, result, _block|
record = [:block, :monitor].include?(action)
record = [:match].include?(result.status)
if record
# TODO: should this hash be an Event instance instead?
event = {
Expand All @@ -122,7 +122,7 @@ def self.watch
end
end

_action, _result, block = Rack::Reactive::RequestBody.publish(op, request)
_result, block = Rack::Reactive::RequestBody.publish(op, request)
end

next [nil, [[:block, event]]] if block
Expand Down
20 changes: 10 additions & 10 deletions lib/datadog/appsec/contrib/rack/reactive/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,20 @@ def self.subscribe(op, waf_context)
}

waf_timeout = Datadog::AppSec.settings.waf_timeout
action, result = waf_context.run(waf_args, waf_timeout)
result = waf_context.run(waf_args, waf_timeout)

Datadog.logger.debug { "WAF TIMEOUT: #{result.inspect}" } if result.timeout

# TODO: encapsulate return array in a type
case action
when :monitor
case result.status
when :match
Datadog.logger.debug { "WAF: #{result.inspect}" }
yield [action, result, false]
when :block
Datadog.logger.debug { "WAF: #{result.inspect}" }
yield [action, result, true]
throw(:block, [action, result, true])
when :good

block = result.actions.include?('block')

yield [result, block]

throw(:block, [result, true]) if block
when :ok
Datadog.logger.debug { "WAF OK: #{result.inspect}" }
when :invalid_call
Datadog.logger.debug { "WAF CALL ERROR: #{result.inspect}" }
Expand Down
20 changes: 10 additions & 10 deletions lib/datadog/appsec/contrib/rack/reactive/request_body.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,20 @@ def self.subscribe(op, waf_context)
}

waf_timeout = Datadog::AppSec.settings.waf_timeout
action, result = waf_context.run(waf_args, waf_timeout)
result = waf_context.run(waf_args, waf_timeout)

Datadog.logger.debug { "WAF TIMEOUT: #{result.inspect}" } if result.timeout

# TODO: encapsulate return array in a type
case action
when :monitor
case result.status
when :match
Datadog.logger.debug { "WAF: #{result.inspect}" }
yield [action, result, false]
when :block
Datadog.logger.debug { "WAF: #{result.inspect}" }
yield [action, result, true]
throw(:block, [action, result, true])
when :good

block = result.actions.include?('block')

yield [result, block]

throw(:block, [result, true]) if block
when :ok
Datadog.logger.debug { "WAF OK: #{result.inspect}" }
when :invalid_call
Datadog.logger.debug { "WAF CALL ERROR: #{result.inspect}" }
Expand Down
20 changes: 10 additions & 10 deletions lib/datadog/appsec/contrib/rack/reactive/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,20 @@ def self.subscribe(op, waf_context)
}

waf_timeout = Datadog::AppSec.settings.waf_timeout
action, result = waf_context.run(waf_args, waf_timeout)
result = waf_context.run(waf_args, waf_timeout)

Datadog.logger.debug { "WAF TIMEOUT: #{result.inspect}" } if result.timeout

# TODO: encapsulate return array in a type
case action
when :monitor
case result.status
when :match
Datadog.logger.debug { "WAF: #{result.inspect}" }
yield [action, result, false]
when :block
Datadog.logger.debug { "WAF: #{result.inspect}" }
yield [action, result, true]
throw(:block, [action, result, true])
when :good

block = result.actions.include?('block')

yield [result, block]

throw(:block, [result, true]) if block
when :ok
Datadog.logger.debug { "WAF OK: #{result.inspect}" }
when :invalid_call
Datadog.logger.debug { "WAF CALL ERROR: #{result.inspect}" }
Expand Down
6 changes: 3 additions & 3 deletions lib/datadog/appsec/contrib/rails/gateway/watcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ def self.watch
trace = active_trace
span = active_span

Rails::Reactive::Action.subscribe(op, waf_context) do |action, result, _block|
record = [:block, :monitor].include?(action)
Rails::Reactive::Action.subscribe(op, waf_context) do |result, _block|
record = [:match].include?(result[:code])
if record
# TODO: should this hash be an Event instance instead?
event = {
Expand All @@ -38,7 +38,7 @@ def self.watch
end
end

_action, _result, block = Rails::Reactive::Action.publish(op, request)
_result, block = Rails::Reactive::Action.publish(op, request)
end

next [nil, [[:block, event]]] if block
Expand Down
20 changes: 10 additions & 10 deletions lib/datadog/appsec/contrib/rails/reactive/action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,20 @@ def self.subscribe(op, waf_context)
}

waf_timeout = Datadog::AppSec.settings.waf_timeout
action, result = waf_context.run(waf_args, waf_timeout)
_code, result = waf_context.run(waf_args, waf_timeout)

Datadog.logger.debug { "WAF TIMEOUT: #{result.inspect}" } if result.timeout

# TODO: encapsulate return array in a type
case action
when :monitor
case result[:code]
when :match
Datadog.logger.debug { "WAF: #{result.inspect}" }
yield [action, result, false]
when :block
Datadog.logger.debug { "WAF: #{result.inspect}" }
yield [action, result, true]
throw(:block, [action, result, true])
when :good

block = result.actions.include?('block')

yield [result, block]

throw(:block, [result, true]) if block
when :ok
Datadog.logger.debug { "WAF OK: #{result.inspect}" }
when :invalid_call
Datadog.logger.debug { "WAF CALL ERROR: #{result.inspect}" }
Expand Down
12 changes: 6 additions & 6 deletions lib/datadog/appsec/contrib/sinatra/gateway/watcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def self.watch
trace = active_trace
span = active_span

Rack::Reactive::RequestBody.subscribe(op, waf_context) do |action, result, _block|
record = [:block, :monitor].include?(action)
Rack::Reactive::RequestBody.subscribe(op, waf_context) do |result, _block|
record = [:match].include?(result[:code])
if record
# TODO: should this hash be an Event instance instead?
event = {
Expand All @@ -40,7 +40,7 @@ def self.watch
end
end

_action, _result, block = Rack::Reactive::RequestBody.publish(op, request)
_result, block = Rack::Reactive::RequestBody.publish(op, request)
end

next [nil, [[:block, event]]] if block
Expand All @@ -64,8 +64,8 @@ def self.watch
trace = active_trace
span = active_span

Sinatra::Reactive::Routed.subscribe(op, waf_context) do |action, result, _block|
record = [:block, :monitor].include?(action)
Sinatra::Reactive::Routed.subscribe(op, waf_context) do |result, _block|
record = [:match].include?(result[:code])
if record
# TODO: should this hash be an Event instance instead?
event = {
Expand All @@ -80,7 +80,7 @@ def self.watch
end
end

_action, _result, block = Sinatra::Reactive::Routed.publish(op, [request, route_params])
_result, block = Sinatra::Reactive::Routed.publish(op, [request, route_params])
end

next [nil, [[:block, event]]] if block
Expand Down
20 changes: 10 additions & 10 deletions lib/datadog/appsec/contrib/sinatra/reactive/routed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,20 @@ def self.subscribe(op, waf_context)
}

waf_timeout = Datadog::AppSec.settings.waf_timeout
action, result = waf_context.run(waf_args, waf_timeout)
_code, result = waf_context.run(waf_args, waf_timeout)

Datadog.logger.debug { "WAF TIMEOUT: #{result.inspect}" } if result.timeout

# TODO: encapsulate return array in a type
case action
when :monitor
case result[:code]
when :match
Datadog.logger.debug { "WAF: #{result.inspect}" }
yield [action, result, false]
when :block
Datadog.logger.debug { "WAF: #{result.inspect}" }
yield [action, result, true]
throw(:block, [action, result, true])
when :good

block = result.actions.include?('block')

yield [result, block]

throw(:block, [result, true]) if block
when :ok
Datadog.logger.debug { "WAF OK: #{result.inspect}" }
when :invalid_call
Datadog.logger.debug { "WAF CALL ERROR: #{result.inspect}" }
Expand Down

0 comments on commit 3a21a7e

Please sign in to comment.