Class: Smplkit::Audit::TestForwarderActions

Inherits:
Object
  • Object
show all
Defined in:
lib/smplkit/audit/functions.rb

Overview

execute is a server-side proxy that lets the console preview a destination without browser CORS getting in the way. The audit service applies its SSRF guard before resolving the URL —private/loopback/link-local addresses (incl. the EC2 IMDS at 169.254.169.254) and disallowed ports are rejected.

Instance Method Summary collapse

Constructor Details

#initialize(api) ⇒ TestForwarderActions

Returns a new instance of TestForwarderActions.



29
30
31
# File 'lib/smplkit/audit/functions.rb', line 29

def initialize(api)
  @api = api
end

Instance Method Details

#execute(url:, method: "POST", headers: nil, body: nil, success_status: "2xx", timeout_ms: nil) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/smplkit/audit/functions.rb', line 33

def execute(url:, method: "POST", headers: nil, body: nil,
            success_status: "2xx", timeout_ms: nil)
  req = SmplkitGeneratedClient::Audit::TestForwarderRequest.new(
    url: url,
    method: method,
    headers: (headers || []).map do |h|
      name, value = h.is_a?(Hash) ? [h[:name] || h["name"], h[:value] || h["value"]] : [h.name, h.value]
      SmplkitGeneratedClient::Audit::HttpHeader.new(name: name, value: value)
    end,
    body: body,
    success_status: success_status,
    timeout_ms: timeout_ms
  )
  resp = @api.execute_test_forwarder(req)
  TestForwarderResult.new(
    succeeded: resp.succeeded || false,
    response_status: resp.response_status,
    response_headers: resp.response_headers || {},
    response_body: resp.response_body || "",
    latency_ms: resp.latency_ms,
    error: resp.error
  )
end