# ---------------------------------------------------------------------------
# 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-sqs-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,[encoded data, 4228 characters]"
    camel.apache.org/provider: "Apache Software Foundation"
    camel.apache.org/kamelet.group: "AWS SQS"
    camel.apache.org/keda.type: "aws-sqs-queue"
    camel.apache.org/kamelet.namespace: "AWS"
  labels:
    camel.apache.org/kamelet.type: "source"
spec:
  definition:
    title: "AWS SQS Source"
    description: Receive data from AWS SQS.
    required:
      - queueNameOrArn
      - region
    type: object
    properties:
      queueNameOrArn:
        title: Queue Name
        description: The SQS Queue Name or ARN
        type: string
      deleteAfterRead:
        title: Auto-delete Messages
        description: Delete messages after consuming them
        type: boolean
        default: true
      accessKey:
        title: Access Key
        description: The access key obtained from AWS.
        type: string
        format: password
        x-descriptors:
        - urn:camel:group:credentials
        - urn:keda:authentication:awsAccessKeyID
        - urn:keda:required
      secretKey:
        title: Secret Key
        description: The secret key obtained from AWS.
        type: string
        format: password
        x-descriptors:
        - urn:camel:group:credentials
        - urn:keda:authentication:awsSecretAccessKey
        - urn:keda:required
      region:
        title: AWS Region
        description: The AWS region to access.
        type: string
        x-descriptors:
        - urn:keda:metadata:awsRegion
        - urn:keda:required
        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"]
      autoCreateQueue:
        title: Autocreate Queue
        description: Setting the autocreation of the SQS queue.
        type: boolean
        default: false
      amazonAWSHost:
        title: AWS Host
        description: The hostname of the Amazon AWS cloud.
        type: string
        default: amazonaws.com
      protocol:
        title: Protocol
        description: The underlying protocol used to communicate with SQS
        type: string
        example: http or https
        default: https
      queueURL:
        title: Queue URL
        description: The full SQS Queue URL (required if using KEDA)
        type: string
        x-descriptors:
        - urn:keda:metadata:queueURL
        - urn:keda:required
      useDefaultCredentialsProvider:
        title: Default Credentials Provider
        description: If true, the SQS 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 SQS client should expect to load credentials through a profile credentials provider.
        type: boolean
        default: false
      useSessionCredentials:
        title: Session Credentials
        description: Set whether the SQS 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 SQS.
        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
      delay:
        title: Delay
        description: The number of milliseconds before the next poll of the selected stream
        type: integer
        default: 500
      greedy:
        title: Greedy Scheduler
        description: If greedy is enabled, then the polling will happen immediately again, if the previous run polled 1 or more messages.
        type: boolean
        default: false
      maxMessagesPerPoll:
        title: Max Messages Per Poll
        description: The maximum number of messages to return. Amazon SQS never returns more messages than this value (however, fewer messages might be returned). Valid values 1 to 10. Default 1.
        type: integer
        minimum: "1"
        maximum: "10"
        default: 1
      waitTimeSeconds:
        title: Wait Time Seconds
        description: The duration (in seconds) for which the call waits for a message to arrive in the queue before returning. If a message is available, the call returns sooner than WaitTimeSeconds. If no messages are available and the wait time expires, the call does not return a message list.
        type: integer
        minimum: "0"
      visibilityTimeout:
        title: Visibility Timeout
        description: The duration (in seconds) that the received messages are hidden from subsequent retrieve requests after being retrieved by a ReceiveMessage request.
        type: integer
        minimum: "0"
  dataTypes:
    out:
      default: text
      headers:
        CamelAwsSqsMessageId:
          title: The SQS Message Id
          description: The Amazon SQS message ID
          type: string
        CamelAwsSqsReceiptHandle:
          title: The SQS Message Receipt Handle
          description: The Amazon SQS message receipt handle.
          type: string
        CamelAwsSqsMD5OfBody:
          title: The SQS Message MD5 Checksum
          description: The content type of the retrieved object.
          default: application/octet-stream
          type: string
        CamelAwsSqsAttributes:
          title: The SQS Message System Attributes
          description: |-
            A map of the attributes requested in ReceiveMessage to their respective values, the Map type is Map<MessageSystemAttributeName, String>
          type: object
        CamelAwsSqsMessageAttributes:
          title: The SQS Message Attributes
          description: |-
            The Amazon SQS message attributes, the Map type is Map<String, MessageAttributeValue>
          type: object
      types:
        text:
          format: "text-plain"
          description: Default String representation of the SQS message received from the queue.
          mediaType: text/plain
        cloudevents:
          format: "aws2-sqs:application-cloudevents"
          description: |-
            Output data type represents AWS SQS receive message response as CloudEvent V1. The data type sets Camel specific CloudEvent headers on the exchange with
            respective data from the SQS message 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.aws.sqs.receiveMessage"
              type: string
            CamelCloudEventSource:
              title: CloudEvent Source
              description: The event source. By default, the SQS Received message receipt handle with prefix "aws.sqs.queue.".
              type: string
            CamelCloudEventSubject:
              title: CloudEvent Subject
              description: The event subject. The SQS message ID
              type: string
            CamelCloudEventTime:
              title: CloudEvent Time
              description: The exchange creation timestamp as event time.
              type: string
  dependencies:
    - "camel:core"
    - "camel:aws2-sqs"
    - "camel:kamelet"
  template:
    from:
      uri: "aws2-sqs:{{queueNameOrArn}}"
      parameters:
        autoCreateQueue: "{{autoCreateQueue}}"
        secretKey: "{{?secretKey}}"
        accessKey: "{{?accessKey}}"
        region: "{{region}}"
        deleteAfterRead: "{{deleteAfterRead}}"
        amazonAWSHost: "{{?amazonAWSHost}}"
        protocol: "{{?protocol}}"
        useDefaultCredentialsProvider: "{{useDefaultCredentialsProvider}}"
        useProfileCredentialsProvider: "{{useProfileCredentialsProvider}}"
        useSessionCredentials: "{{useSessionCredentials}}"
        uriEndpointOverride: "{{?uriEndpointOverride}}"
        profileCredentialsName: "{{?profileCredentialsName}}"
        sessionToken: "{{?sessionToken}}"
        overrideEndpoint: "{{overrideEndpoint}}"
        delay: "{{delay}}"
        greedy: "{{greedy}}"
        maxMessagesPerPoll: "{{maxMessagesPerPoll}}"
        waitTimeSeconds: "{{?waitTimeSeconds}}"
        visibilityTimeout: "{{?visibilityTimeout}}"
      steps:
      - to: "kamelet:sink"