Class: ForestAdminAgent::Utils::CallerParser

Inherits:
Object
  • Object
show all
Includes:
Http::Exceptions, ForestAdminDatasourceToolkit::Exceptions
Defined in:
lib/forest_admin_agent/utils/caller_parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ CallerParser

Returns a new instance of CallerParser.



11
12
13
14
# File 'lib/forest_admin_agent/utils/caller_parser.rb', line 11

def initialize(args)
  @args = args
  @token_data = {}
end

Instance Method Details

#parseObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/forest_admin_agent/utils/caller_parser.rb', line 16

def parse
  validate_headers
  @token_data = decode_token
  @token_data[:timezone] = extract_timezone
  @token_data[:request] = { ip: @args[:headers]['action_dispatch.remote_ip'].to_s }
  # One id per request, generated by the agent, shared by every operation it triggers (used to
  # correlate the audit trail) and echoed back to the client in the response header.
  # See ForestAdminAgent::Http::CorrelationId.
  @token_data[:request_id] = Http::CorrelationId.current
  project, environment = extract_forest_context
  @token_data[:project] = project
  @token_data[:environment] = environment

  ForestAdminDatasourceToolkit::Components::Caller.new(**@token_data.transform_keys(&:to_sym))
end