# ---------------------------------------------------------------------------
# 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-ses-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,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+Cjxzdmcgd2lkdGg9IjI1NnB4IiBoZWlnaHQ9IjI5OXB4IiB2aWV3Qm94PSIwIDAgMjU2IDI5OSIgdmVyc2lvbj0iMS4xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiBwcmVzZXJ2ZUFzcGVjdFJhdGlvPSJ4TWlkWU1pZCI+Cgk8Zz4KCQk8cGF0aCBkPSJNNjAuNTU2LDQ3LjYwMiBMMCwxNDQuMDEgTDYwLjU1NiwyNDAuNDM0IEw2MS42MTIsMjM5LjY4MSBMNjAuODM3LDQ3LjggTDYwLjU1Niw0Ny42MDIiIGZpbGw9IiM4NzY5MjkiPjwvcGF0aD4KCQk8cGF0aCBkPSJNMTI4LjE4NywyMjMuMTA1IEw2MC41NTYsMjQwLjQzNCBMNjAuNTU2LDQ3LjYwMiBMMTI4LjE4Nyw2NC45MjcgTDEyOC4xODcsMjIzLjEwNSIgZmlsbD0iI0Q5QTc0MSI+PC9wYXRoPgoJCTxwYXRoIGQ9Ik0yNTUuOTc5LDcxLjg2OCBMMjIzLjM3OSw3Ny4yNTkgTDE0OC41MzgsMCBMMTExLjMzMSwxNi4yOTIgTDExNi4yMzksMjUuNDQ1IEw4OS45MDYsMzUuOTcxIEw4OS45MDYsMjc5LjM5OSBMMTI4LjE4NiwyOTguNTUyIEwxMjguODIzLDI5OC4wNTMgTDEyOC4yMzQsNDcuODE4IEwyMDkuMzc2LDE3MC43ODYgTDI1NS45NzksNzEuODY4IiBmaWxsPSIjODc2OTI5Ij48L3BhdGg+CgkJPHBhdGggZD0iTTE0OC41MzgsMCBMMjQ4LjIxNyw0OS44MzcgTDIwOC44LDEyMS4zNTcgTDE0OC41MzgsMCIgZmlsbD0iI0Q5QTc0MSI+PC9wYXRoPgoJCTxwYXRoIGQ9Ik0yNTUuOTc1LDcxLjg2OCBMMjU2LDIzNC41OTYgTDEyOC4xODcsMjk4LjU1MiBMMTI4LjE3LDIwLjY4MyBMMjA4LjgsMTY2Ljk3NCBMMjU1Ljk3NSw3MS44NjgiIGZpbGw9IiNEOUE3NDEiPjwvcGF0aD4KCTwvZz4KPC9zdmc+"
    camel.apache.org/provider: "Apache Software Foundation"
    camel.apache.org/kamelet.group: "AWS SES"
    camel.apache.org/kamelet.namespace: "AWS"
  labels:
    camel.apache.org/kamelet.type: "sink"
spec:
  definition:
    title: "AWS SES Sink"
    description: Send email through the Amazon Simple Email Service (SES).
    required:
      - from
      - region
    type: object
    properties:
      from:
        title: From 
        description: From address
        type: string
        example: user@example.com
      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 SES 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 SES client should expect to load credentials through a profile credentials provider.
        type: boolean
        default: false
      useSessionCredentials:
        title: Session Credentials
        description: Set whether the SES 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 SES.
        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
  dependencies:
    - "camel:core"
    - "camel:aws2-ses"
    - "camel:kamelet"
  template:
    from:
      uri: "kamelet:source"
      steps:
      - choice:
          when:
          - simple: "${header[subject]}"
            steps:
            - setHeader:
                name: CamelAwsSesSubject
                simple: "${header[subject]}"
          - simple: "${header[ce-subject]}"
            steps:
            - setHeader:
                name: CamelAwsSesSubject
                simple: "${header[ce-subject]}"
          otherwise:
            steps:
            - setHeader:
                name: CamelAwsSesSubject
                simple: "${exchangeId}"
      - choice:
          when:
          - simple: "${header[to]}"
            steps:
            - setHeader:
                name: CamelAwsSesTo
                simple: "${header[to]}"
          - simple: "${header[ce-to]}"
            steps:
            - setHeader:
                name: CamelAwsSesTo
                simple: "${header[ce-to]}"
      - choice:
          when:
          - simple: "${header[reply-to-addresses]}"
            steps:
            - setHeader:
                name: CamelAwsSesReplyToAddresses
                simple: "${header[reply-to-addresses]}"
          - simple: "${header[ce-reply-to-addresses]}"
            steps:
            - setHeader:
                name: CamelAwsSesReplyToAddresses
                simple: "${header[ce-reply-to-addresses]}"
      - to:
          uri: "aws2-ses://{{from}}"
          parameters:
            secretKey: "{{?secretKey}}"
            accessKey: "{{?accessKey}}"
            region: "{{region}}"
            useDefaultCredentialsProvider: "{{useDefaultCredentialsProvider}}"
            useProfileCredentialsProvider: "{{useProfileCredentialsProvider}}"
            useSessionCredentials: "{{useSessionCredentials}}"
            profileCredentialsName: "{{?profileCredentialsName}}"
            sessionToken: "{{?sessionToken}}"