# ---------------------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ---------------------------------------------------------------------------
apiVersion: camel.apache.org/v1
kind: Kamelet
metadata:
  name: google-storage-source
  annotations:
    camel.apache.org/kamelet.support.level: "Stable"
    camel.apache.org/catalog.version: "4.10.2"
    camel.apache.org/kamelet.icon: "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiBoZWlnaHQ9IjgwMCIgd2lkdGg9IjEyMDAiIHZpZXdCb3g9Ii0xOS4yMDAxNSAtMjguNDgzIDE2Ni40MDEzIDE3MC44OTgiPjxnIHRyYW5zZm9ybT0idHJhbnNsYXRlKDAgLTcuMDM0KSI+PGxpbmVhckdyYWRpZW50IHkyPSIxMjAuNzg5IiB4Mj0iNjQiIHkxPSI3LjAzNCIgeDE9IjY0IiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgaWQ9ImEiPjxzdG9wIG9mZnNldD0iMCIgc3RvcC1jb2xvcj0iIzQzODdmZCIvPjxzdG9wIG9mZnNldD0iMSIgc3RvcC1jb2xvcj0iIzQ2ODNlYSIvPjwvbGluZWFyR3JhZGllbnQ+PHBhdGggZD0iTTI3Ljc5IDExNS4yMTdMMS41NCA2OS43NDlhMTEuNDk5IDExLjQ5OSAwIDAxMC0xMS40OTlsMjYuMjUtNDUuNDY3YTExLjUgMT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ni0xLjIxMiAxLjIxNHY4LjU2NmMwIC42NjYuNTQ2IDEuMjEyIDEuMjEyIDEuMjEySDg0LjdjLjY2NyAwIDEuMjEzLS41NDYgMS4yMTMtMS4yMTJ2LTguNTY4YzAtLjY2Ni0uNTQ1LTEuMjEzLTEuMjEyLTEuMjEzbS02LjQxNiA3Ljk3NmEyLjQ4NCAyLjQ4NCAwIDAxLTIuNDc3LTIuNDggMi40NzUgMi40NzUgMCAwMTIuNDc3LTIuNDc3YzEuMzcgMCAyLjQ4IDEuMTAzIDIuNDggMi40NzdhMi40OCAyLjQ4IDAgMDEtMi40OCAyLjQ4bTYuNDE1IDguNDkxbC00MS40MzYuMDAyYy0uNjY3IDAtMS4yMTIuNTQ2LTEuMjEyIDEuMjE0djguNTY1YzAgLjY2Ni41NDYgMS4yMTMgMS4yMTIgMS4yMTNIODQuN2MuNjY3IDAgMS4yMTMtLjU0NyAxLjIxMy0xLjIxM3YtOC41NjdjMC0uNjY2LS41NDUtMS4yMTQtMS4yMTItMS4yMTRtLTYuNDE2IDcuOTc2YTIuNDgzIDIuNDgzIDAgMDEtMi40NzctMi40OCAyLjQ3NSAyLjQ3NSAwIDAxMi40NzctMi40NzcgMi40OCAyLjQ4IDAgMTEwIDQuOTU2IiBmaWxsPSIjZmZmIi8+PC9zdmc+"
    camel.apache.org/provider: "Apache Software Foundation"
    camel.apache.org/kamelet.group: "Google Storage"
    camel.apache.org/kamelet.namespace: "GCP"
  labels:
    camel.apache.org/kamelet.type: "source"
spec:
  definition:
    title: "Google Storage Source"
    description: |-
      Consume objects from Google Cloud Storage.

      If you specify the `serviceAccountKey` property, you must base64 encode it before you pass it as a parameter.
    required:
      - bucketNameOrArn
    type: object
    properties:
      bucketNameOrArn:
        title: Bucket Name Or ARN
        description: The Google Cloud Storage bucket name or Bucket Amazon Resource Name (ARN).
        type: string
      serviceAccountKey:
        title: Service Account Key
        description: The service account key to use as credentials for Google Cloud Storage access. You must encode this value in base64.
        type: binary
        x-descriptors:
        - urn:camel:group:credentials
      deleteAfterRead:
        title: Auto-delete Objects
        description: Specifies to delete objects after consuming them.
        type: boolean
        default: true
      autoCreateBucket:
        title: Autocreate Bucket
        description: Specifies to automatically create the Google Cloud Storage bucket.
        type: boolean
        default: false
      prefix:
        title: Prefix
        description: The prefix which is used in the BlobListOptions to only consume objects we are interested in.
        type: string
      filter:
        title: Filter
        description: A regular expression to include only blobs with name matching it.
        type: string
  dataTypes:
    out:
      default: binary
      headers:
        CamelGoogleCloudStorageBucketName:
          title: Google Cloud Storage Bucket Name
          description: The bucket name which has been used to retrieve objects
          type: string
        CamelGoogleCloudStorageObjectName:
          title: Google Cloud Storage Object Name
          description: The object name under which the retrieved object is stored
          type: string
        CamelGoogleCloudStorageContentType:
          title: Content Type
          description: The content type of the retrieved object.
          default: application/octet-stream
          type: string
        CamelGoogleCloudStorageETag:
          title: ETag Value
          description: |-
            The hex encoded 128-bit MD5 digest of the associated object according to RFC 1864.
            Is the generation number of the object for which you are retrieving information.
          type: string
      types:
        binary:
          format: "application-octet-stream"
          description: Default binary representation of the Google Storage Cloud object retrieved from the bucket.
          mediaType: application/octet-stream
        cloudevents:
          format: "aws2-s3:application-cloudevents"
          description: |-
            Output data type represents Google Storage download to response as CloudEvent V1. The data type sets Camel specific CloudEvent headers on the exchange with
            respective data from the S3 bucket and its derived object.
          headers:
            CamelCloudEventID:
              title: CloudEvent ID
              description: The Camel exchange id set as event id
              type: string
            CamelCloudEventType:
              title: CloudEvent Type
              description: The event type
              default: "org.apache.camel.event.google.storage.downloadTo"
              type: string
            CamelCloudEventSource:
              title: CloudEvent Source
              description: The event source. By default, the Google Cloud Storage bucket name with prefix "google.storage.bucket.".
              type: string
            CamelCloudEventSubject:
              title: CloudEvent Subject
              description: The event subject. Usually the Google Cloud Storage object name.
              type: string
            CamelCloudEventTime:
              title: CloudEvent Time
              description: The exchange creation timestamp as event time.
              type: string
  dependencies:
    - "camel:kamelet"
    - "camel:google-storage"
    - "camel:jackson"
  template:
    from:
      uri: "google-storage://{{bucketNameOrArn}}"
      parameters:
        autoCreateBucket: "{{autoCreateBucket}}"
        serviceAccountKey: "base64:{{?serviceAccountKey}}"
        deleteAfterRead: "{{deleteAfterRead}}"
        filter: "{{?filter}}"
        prefix: "{{?prefix}}"
      steps:
      - to: kamelet:sink