001// Copyright 2019 Google LLC 002// 003// Licensed under the Apache License, Version 2.0 (the "License"); 004// you may not use this file except in compliance with the License. 005// You may obtain a copy of the License at 006// 007// http://www.apache.org/licenses/LICENSE-2.0 008// 009// Unless required by applicable law or agreed to in writing, software 010// distributed under the License is distributed on an "AS IS" BASIS, 011// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012// See the License for the specific language governing permissions and 013// limitations under the License. 014 015package com.google.cloud.functions; 016 017import java.util.Collections; 018import java.util.Map; 019 020/** An interface for event function context. */ 021public interface Context { 022 /** Returns event ID. */ 023 String eventId(); 024 025 /** Returns event timestamp. */ 026 String timestamp(); 027 028 /** Returns event type. */ 029 String eventType(); 030 031 /** Returns event resource. */ 032 String resource(); 033 034 /** 035 * Returns additional attributes from this event. For CloudEvents, the entries in this map will 036 * include the 037 * <a href="https://github.com/cloudevents/spec/blob/v1.0/spec.md#required-attributes">required 038 * attributes</a> and may include 039 * <a href="https://github.com/cloudevents/spec/blob/v1.0/spec.md#required-attributes">optional 040 * attributes</a> and 041 * <a href="https://github.com/cloudevents/spec/blob/v1.0/spec.md#extension-context-attributes"> 042 * extension attributes</a>. 043 * 044 * <p>The map returned by this method may be empty but is never null.</p> 045 */ 046 default Map<String, String> attributes() { 047 return Collections.emptyMap(); 048 } 049}