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  /**
023   * Returns event ID.
024   *
025   * @return event ID
026   */
027  String eventId();
028
029  /**
030   * Returns event timestamp.
031   *
032   * @return event timestamp
033   */
034  String timestamp();
035
036  /**
037   * Returns event type.
038   *
039   * @return event type
040   */
041  String eventType();
042
043  /**
044   * Returns event resource.
045   *
046   * @return event resource
047   */
048  String resource();
049
050  /**
051   * Returns additional attributes from this event. For CloudEvents, the entries in this map will
052   * include the <a
053   * href="https://github.com/cloudevents/spec/blob/v1.0/spec.md#required-attributes">required
054   * attributes</a> and may include <a
055   * href="https://github.com/cloudevents/spec/blob/v1.0/spec.md#required-attributes">optional
056   * attributes</a> and <a
057   * href="https://github.com/cloudevents/spec/blob/v1.0/spec.md#extension-context-attributes">
058   * extension attributes</a>.
059   *
060   * <p>The map returned by this method may be empty but is never null.
061   *
062   * @return additional attributes form this event.
063   */
064  default Map<String, String> attributes() {
065    return Collections.emptyMap();
066  }
067}