Class: FunctionsFramework::LegacyEventConverter

Inherits:
Object
  • Object
show all
Defined in:
lib/functions_framework/legacy_event_converter.rb

Overview

Converter from legacy GCF event formats to CloudEvents.

Instance Method Summary collapse

Instance Method Details

#decode_rack_env(env) ⇒ ::CloudEvents::Event?

Decode an event from the given Rack environment hash.

Parameters:

  • env (Hash)

    The Rack environment

Returns:

  • (::CloudEvents::Event)

    if the request could be converted

  • (nil)

    if the event format was not recognized.



29
30
31
32
33
34
35
36
37
38
# File 'lib/functions_framework/legacy_event_converter.rb', line 29

def decode_rack_env env
  content_type = ::CloudEvents::ContentType.new env["CONTENT_TYPE"], default_charset: "utf-8"
  return nil unless content_type.media_type == "application" && content_type.subtype_base == "json"
  input = read_input_json env["rack.input"], content_type.charset
  return nil unless input
  input = convert_raw_pubsub_event input, env if raw_pubsub_payload? input
  context = normalized_context input
  return nil unless context
  construct_cloud_event context, input["data"]
end