convert_raw_pubsub_event input, env

in lib/functions_framework/legacy_event_converter.rb [57:81]


    def convert_raw_pubsub_event input, env
      message = input["message"]
      path = "#{env['SCRIPT_NAME']}#{env['PATH_INFO']}"
      path_match = %r{projects/[^/?]+/topics/[^/?]+}.match path
      topic = path_match ? path_match[0] : "UNKNOWN_PUBSUB_TOPIC"
      timestamp = message["publishTime"] || ::Time.now.utc.strftime("%Y-%m-%dT%H:%M:%S.%6NZ")
      {
        "context" => {
          "eventId" => message["messageId"],
          "timestamp" => timestamp,
          "eventType" => "google.pubsub.topic.publish",
          "resource" => {
            "service" => "pubsub.googleapis.com",
            "type" => "type.googleapis.com/google.pubsub.v1.PubsubMessage",
            "name" => topic
          }
        },
        "data" => {
          "@type" => "type.googleapis.com/google.pubsub.v1.PubsubMessage",
          "data" => message["data"],
          "attributes" => message["attributes"]
        }
      }
    end