# ---------------------------------------------------------------------------
# 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: aws-eventbridge-sink
  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,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB3aWR0aD0iMWVtIiBoZWlnaHQ9IjFlbSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ieE1pZFlNaWQgbWVldCIgdmlld0JveD0iMCAwIDI1NiAyNTYiIHN0eWxlPSItbXMtdHJhbnNmb3JtOiByb3RhdGUoMzYwZGVnKTsgLXdlYmtpdC10cmFuc2Zvcm06IHJvdGF0ZSgzNjBkZWcpOyB0cmFuc2Zvcm06IHJvdGF0ZSgzNjBkZWcpOyI+PGRlZnM+PGxpbmVhckdyYWRpZW50IGlkPSJJY29uaWZ5SWQtMTgyM2Y2NTU1NjktYWYxZGQ1LTIwMzYiIHgxPSIwJSIgeDI9IjEwMCUiIHkxPSIxMDAlIiB5Mj0iMCUiPjxzdG9wIG9mZnNldD0iMCUiIHN0b3AtY29sb3I9IiNCMDA4NEQiLz48c3RvcCBvZmZzZXQ9IjEwMCUiIHN0b3AtY29sb3I9IiNGRjRGOEIiLz48L2xpbmVhckd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tMy4yWm0tMTQ2LjA0IDUwLjM5Yy02Ljg2IDAtMTIuNDQyLTUuNjEyLTEyLjQ0Mi0xMi41MDhjMC02LjkgNS41ODEtMTIuNTEgMTIuNDQyLTEyLjUxYzYuODU3IDAgMTIuNDM5IDUuNjEgMTIuNDM5IDEyLjUxYzAgNi44OTYtNS41ODIgMTIuNTA4LTEyLjQ0IDEyLjUwOFptMTAuMzkzIDMuMjM2YzUuMDYyLTMuMzkyIDguNDEtOS4xODEgOC40MS0xNS43NDRjMC0xMC40MjYtOC40MzYtMTguOTEtMTguODAzLTE4LjkxYy0zLjAwNCAwLTUuODMzLjczLTguMzUzIDEuOTk0TDQ4LjQ1OCAxMjhsMTguNDI4LTMyLjA5M2wtNS41MTUtMy4yTDQyLjAyNyAxMjYuNGEzLjIxIDMuMjEgMCAwIDAgMCAzLjJsMTIuMzg4IDIxLjU2OGMtMy4yNjggMy40MDUtNS4yODkgOC4wMjItNS4yODkgMTMuMTE0YzAgMTAuNDI1IDguNDM2IDE4LjkwOCAxOC44MDcgMTguOTA4YzEuNTYyIDAgMy4wNzQtLjIxNCA0LjUyOC0uNTc5bDEwLjE1IDE3LjY4Yy41Ny45ODkgMS42MiAxLjYgMi43NTcgMS42aDM5LjQ1MXYtNi40SDg3LjIwNGwtOC44NzgtMTUuNDY1WiIvPjwvc3ZnPg=="
    camel.apache.org/provider: "Apache Software Foundation"
    camel.apache.org/kamelet.group: "AWS Eventbridge"
    camel.apache.org/kamelet.namespace: "AWS"
  labels:
    camel.apache.org/kamelet.type: "sink"
spec:
  definition:
    title: "AWS Eventbridge Sink"
    description: Send events to an Amazon Eventbridge Eventbus.

      In the headers, you need to set the `resources-arn` / `ce-resources-arn` property to specify the ARN of resources related to the event.

      In the headers, you need to set the `detail-type` / `ce-detail-type` property to specify the detail type related to the event.

      In the headers, you need to set the `event-source` / `ce-event-source` property to specify the event source related to the event.

      If you do not set the property in the header, the Kamelet uses the exchange ID for the file name.
    required:
      - eventbusNameOrArn
      - region
    type: object
    properties:
      eventbusNameOrArn:
        title: Eventbus Name
        description: The Eventbridge Eventbus name or Amazon Resource Name (ARN).
        type: string
      accessKey:
        title: Access Key
        description: The access key obtained from AWS.
        type: string
        format: password
        x-descriptors:
        - urn:camel:group:credentials
      secretKey:
        title: Secret Key
        description: The secret key obtained from AWS.
        type: string
        format: password
        x-descriptors:
        - urn:camel:group:credentials
      region:
        title: AWS Region
        description: The AWS region to access.
        type: string
        enum: ["ap-south-1", "eu-south-1", "us-gov-east-1", "me-central-1", "ca-central-1", "eu-central-1", "us-iso-west-1", "us-west-1", "us-west-2", "af-south-1", "eu-north-1", "eu-west-3", "eu-west-2", "eu-west-1", "ap-northeast-3", "ap-northeast-2", "ap-northeast-1", "me-south-1", "sa-east-1", "ap-east-1", "cn-north-1", "us-gov-west-1", "ap-southeast-1", "ap-southeast-2", "us-iso-east-1", "ap-southeast-3", "us-east-1", "us-east-2", "cn-northwest-1", "us-isob-east-1", "aws-global", "aws-cn-global", "aws-us-gov-global", "aws-iso-global", "aws-iso-b-global"]
      useDefaultCredentialsProvider:
        title: Default Credentials Provider
        description: If true, the Eventbridge client loads credentials through a default credentials provider. If false, it uses the basic authentication method (access key and secret key).
        type: boolean
        default: false
      useProfileCredentialsProvider:
        title: Profile Credentials Provider
        description: Set whether the Eventbridge client should expect to load credentials through a profile credentials provider.
        type: boolean
        default: false
      useSessionCredentials:
        title: Session Credentials
        description: Set whether the Eventbridge client should expect to use Session Credentials. This is useful in situation in which the user needs to assume a IAM role for doing operations in Eventbridge.
        type: boolean
        default: false
      profileCredentialsName:
        title: Profile Credentials Name
        description: If using a profile credentials provider this parameter will set the profile name.
        type: string
      sessionToken:
        title: Session Token
        description: Amazon AWS Session Token used when the user needs to assume a IAM role.
        type: string
        format: password
        x-descriptors:
        - urn:camel:group:credentials
      uriEndpointOverride:
        title: Overwrite Endpoint URI
        description: The overriding endpoint URI. To use this option, you must also select the `overrideEndpoint` option.
        type: string
      overrideEndpoint:
        title: Endpoint Overwrite
        description: Select this option to override the endpoint URI. To use this option, you must also provide a URI for the `uriEndpointOverride` option.
        type: boolean
        default: false
  dependencies:
    - "camel:core"
    - "camel:aws2-eventbridge"
    - "camel:kamelet"
  template:
    from:
      uri: "kamelet:source"
      steps:
      - choice:
          when:
          - simple: "${header[resources-arn]}"
            steps:
            - setHeader:
                name: CamelAwsEventbridgeResourcesArn
                simple: "${header[resources-arn]}"
          - simple: "${header[ce-resources-arn]}"
            steps:
            - setHeader:
                name: CamelAwsEventbridgeResourcesArn
                simple: "${header[ce-resources-arn]}"
      - choice:
          when:
          - simple: "${header[detail-type]}"
            steps:
            - setHeader:
                name: CamelAwsEventbridgeDetailType
                simple: "${header[detail-type]}"
          - simple: "${header[ce-detail-type]}"
            steps:
            - setHeader:
                name: CamelAwsEventbridgeDetailType
                simple: "${header[ce-detail-type]}"
      - choice:
          when:
          - simple: "${header[event-source]}"
            steps:
            - setHeader:
                name: CamelAwsEventbridgeSource
                simple: "${header[event-source]}"
          - simple: "${header[ce-event-source]}"
            steps:
            - setHeader:
                name: CamelAwsEventbridgeSource
                simple: "${header[ce-event-source]}"            
      - to:
          uri: "aws2-eventbridge:{{eventbusNameOrArn}}"
          parameters:
            secretKey: "{{?secretKey}}"
            accessKey: "{{?accessKey}}"
            region: "{{region}}"
            useDefaultCredentialsProvider: "{{useDefaultCredentialsProvider}}"
            useProfileCredentialsProvider: "{{useProfileCredentialsProvider}}"
            useSessionCredentials: "{{useSessionCredentials}}"
            uriEndpointOverride: "{{?uriEndpointOverride}}"
            profileCredentialsName: "{{?profileCredentialsName}}"
            sessionToken: "{{?sessionToken}}"
            overrideEndpoint: "{{overrideEndpoint}}"
            operation: "putEvent"