Module: Sbmt::Strangler::Mixin
- Defined in:
- lib/sbmt/strangler/mixin.rb
Instance Attribute Summary collapse
-
#strangler_action ⇒ Object
readonly
Returns the value of attribute strangler_action.
Instance Method Summary collapse
- #allowed_headers ⇒ Object
- #allowed_params ⇒ Object
- #http_params ⇒ Object
- #http_request(payload) ⇒ Object
- #proxy_url ⇒ Object
- #render_origin_response(response) ⇒ Object
Instance Attribute Details
#strangler_action ⇒ Object (readonly)
Returns the value of attribute strangler_action.
6 7 8 |
# File 'lib/sbmt/strangler/mixin.rb', line 6 def strangler_action @strangler_action end |
Instance Method Details
#allowed_headers ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/sbmt/strangler/mixin.rb', line 18 def allowed_headers if strangler_action.headers_allowlist.blank? return request.headers.select { |name, _| name.starts_with?("HTTP_") }.to_h end request.headers.select { |name, _| name.in?(strangler_action.headers_allowlist) }.to_h end |
#allowed_params ⇒ Object
12 13 14 15 16 |
# File 'lib/sbmt/strangler/mixin.rb', line 12 def allowed_params return http_params if strangler_action.params_tracking_allowlist.blank? params.permit(*strangler_action.params_tracking_allowlist).to_h end |
#http_params ⇒ Object
8 9 10 |
# File 'lib/sbmt/strangler/mixin.rb', line 8 def http_params params.to_unsafe_h.except(:action, :controller, :format) end |
#http_request(payload) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/sbmt/strangler/mixin.rb', line 26 def http_request(payload) strangler_action.http_client.call( proxy_url, strangler_action.proxy_http_method, payload: payload, headers: allowed_headers ) end |
#proxy_url ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/sbmt/strangler/mixin.rb', line 35 def proxy_url case strangler_action.proxy_url in String => url url in Proc => proc proc.call(http_params, request.headers) end end |
#render_origin_response(response) ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/sbmt/strangler/mixin.rb', line 44 def render_origin_response(response) if response.success? body, status = response.value!.values_at(:body, :status) render json: body, status: status return end body, status = response.failure.values_at(:body, :status) render json: body, status: status end |