Class: Datadog::AppSec::Response
- Inherits:
-
Object
- Object
- Datadog::AppSec::Response
- Defined in:
- lib/datadog/appsec/response.rb
Overview
AppSec response
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(status:, headers: {}, body: []) ⇒ Response
constructor
A new instance of Response.
- #to_action_dispatch_response ⇒ Object
- #to_rack ⇒ Object
- #to_sinatra_response ⇒ Object
Constructor Details
#initialize(status:, headers: {}, body: []) ⇒ Response
Returns a new instance of Response.
12 13 14 15 16 |
# File 'lib/datadog/appsec/response.rb', line 12 def initialize(status:, headers: {}, body: []) @status = status @headers = headers @body = body end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
10 11 12 |
# File 'lib/datadog/appsec/response.rb', line 10 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
10 11 12 |
# File 'lib/datadog/appsec/response.rb', line 10 def headers @headers end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
10 11 12 |
# File 'lib/datadog/appsec/response.rb', line 10 def status @status end |
Class Method Details
.graphql_response(gateway_multiplex) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/datadog/appsec/response.rb', line 53 def graphql_response(gateway_multiplex) multiplex_return = [] gateway_multiplex.queries.each do |query| # This method is only called in places where GraphQL-Ruby is already required query_result = ::GraphQL::Query::Result.new( query: query, values: JSON.parse(content('application/json')) ) multiplex_return << query_result end multiplex_return end |
.negotiate(env, actions) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/datadog/appsec/response.rb', line 31 def negotiate(env, actions) # @type var configured_response: Response? configured_response = nil actions.each do |action| # Need to use next to make steep happy :( # I rather use break to stop the execution next if configured_response action_configuration = AppSec::Processor::Actions.fetch_configuration(action) next unless action_configuration configured_response = case action_configuration['type'] when 'block_request' block_response(env, action_configuration['parameters']) when 'redirect_request' redirect_response(env, action_configuration['parameters']) end end configured_response || default_response(env) end |
Instance Method Details
#to_action_dispatch_response ⇒ Object
26 27 28 |
# File 'lib/datadog/appsec/response.rb', line 26 def to_action_dispatch_response ::ActionDispatch::Response.new(status, headers, body) end |
#to_rack ⇒ Object
18 19 20 |
# File 'lib/datadog/appsec/response.rb', line 18 def to_rack [status, headers, body] end |
#to_sinatra_response ⇒ Object
22 23 24 |
# File 'lib/datadog/appsec/response.rb', line 22 def to_sinatra_response ::Sinatra::Response.new(body, status, headers) end |