apiVersion: camel.apache.org/v1alpha1
kind: Kamelet
metadata:
  name: aws-s3-experimental-source
  annotations:
    camel.apache.org/kamelet.support.level: "Experimental"
    camel.apache.org/catalog.version: "3.21.0"
    camel.apache.org/kamelet.icon: "data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIGlkPSJMYXllcl8xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHg9IjAiIHk9IjAiIHZpZXdCb3g9IjAgMCAyNDguMiAzMDAiIHhtbDpzcGFjZT0icHJlc2VydmUiPjxzdHlsZT4uc3QyOHtmaWxsOiM4YzMxMjN9LnN0Mjl7ZmlsbDojZTA1MjQzfTwvc3R5bGU+PHBhdGggY2xhc3M9InN0MjgiIGQ9Ik0yMCA1Mi4xTDAgNjJ2MTc1LjVsMjAgOS45LjEtLjFWNTIuMmwtLjEtLjEiLz48cGF0aCBjbGFzcz0ic3QyOSIgZD0iTTEyNyAyMjJMMjAgMjQ3LjVWNTIuMUwxMjcgNzd2MTQ1Ii8+PHBhdGggY2xhc3M9InN0MjgiIGQ9Ik03OC43IDE4Mi4xbDQ1LjQgNS44LjMtLjcuMy03NC40LS41LS42LTQ1LjQgNS43LS4xIDY0LjIiLz48cGF0aCBjbGFzcz0ic3QyOCIgZD0iTTEyNC4xIDIyMi4zbDEwNC4xIDI1LjIuMi0uM1Y1Mi4xbC0uMi0uMi0xMDQuMSAyNS40djE0NSIvPjxwYXRoIGNsYXNzPSJzdDI5IiBkPSJNMTY5LjUgMTgyLjFsLTQ1LjQgNS44di03NS43bDQ1LjQgNS43djY0LjIiLz48cGF0aCBkPSJNMTY5LjUgODYuOWwtNDUuNCA4LjMtNDUuNC04LjNMMTI0IDc1bDQ1LjUgMTEuOSIgZmlsbD0iIzVlMWYxOCIvPjxwYXRoIGQ9Ik0xNjkuNSAyMTMuMWwtNDUuNC04LjMtNDUuNCA4LjMgNDUuMyAxMi43IDQ1LjUtMTIuNyIgZmlsbD0iI2YyYjBhOSIvPjxwYXRoIGNsYXNzPSJzdDI4IiBkPSJNNzguNyA4Ni45bDQ1LjQtMTEuMi40LS4xVi4zbC0uNC0uMy00NS40IDIyLjd2NjQuMiIvPjxwYXRoIGNsYXNzPSJzdDI5IiBkPSJNMTY5LjUgODYuOWwtNDUuNC0xMS4yVjBsNDUuNCAyMi43djY0LjIiLz48cGF0aCBjbGFzcz0ic3QyOCIgZD0iTTEyNC4xIDMwMGwtNDUuNC0yMi43di02NC4ybDQ1LjQgMTEuMi43LjgtLjIgNzMuNi0uNSAxLjMiLz48cGF0aCBjbGFzcz0ic3QyOSIgZD0iTTEyNC4xIDMwMGw0NS40LTIyLjd2LTY0LjJsLTQ1LjQgMTEuMlYzMDBNMjI4LjIgNTIuMWwyMCAxMHYxNzUuNWwtMjAgMTBWNTIuMSIvPjwvc3ZnPg=="
    camel.apache.org/provider: "Apache Software Foundation"
    camel.apache.org/kamelet.group: "AWS S3"
    camel.apache.org/kamelet.namespace: "AWS"
  labels:
    camel.apache.org/kamelet.type: "source"
spec:
  definition:
    title: "AWS S3 Experimental Source"
    description: |-
      Receive data from an Amazon S3 Bucket.

      The basic authentication method for the S3 service is to specify an access key and a secret key. These parameters are optional because the Kamelet provides a default credentials provider.
      
      If you use the default credentials provider, the S3 client loads the credentials through this provider and doesn't use the basic authentication method.

      Two headers will be duplicated with different names for clarity at sink level, CamelAwsS3Key will be duplicated into aws.s3.key and CamelAwsS3BucketName will be duplicated in aws.s3.bucket.name.
      
      This Kamelet supports experimental output format to specify the data type produced by this source. Users of the Kamelet are able to choose from different output types.
    required:
      - bucketNameOrArn
      - region
    type: object
    properties:
      bucketNameOrArn:
        title: Bucket Name
        description: The S3 Bucket name or Amazon Resource Name (ARN).
        type: string
      deleteAfterRead:
        title: Auto-delete Objects
        description: Specifies to delete objects after consuming them.
        type: boolean
        x-descriptors:
        - 'urn:alm:descriptor:com.tectonic.ui:checkbox'
        default: true
      accessKey:
        title: Access Key
        description: The access key obtained from AWS.
        type: string
        format: password
        x-descriptors:
        - urn:alm:descriptor:com.tectonic.ui:password
        - urn:camel:group:credentials
      secretKey:
        title: Secret Key
        description: The secret key obtained from AWS.
        type: string
        format: password
        x-descriptors:
        - urn:alm:descriptor:com.tectonic.ui:password
        - 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"]
      autoCreateBucket:
        title: Autocreate Bucket
        description: Specifies to automatically create the S3 bucket.
        type: boolean
        x-descriptors:
        - 'urn:alm:descriptor:com.tectonic.ui:checkbox'
        default: false
      includeBody:
        title: Include Body
        description: If true, the exchange is consumed and put into the body and closed. If false, the S3Object stream is put raw into the body and the headers are set with the S3 object metadata.
        type: boolean
        x-descriptors:
        - 'urn:alm:descriptor:com.tectonic.ui:checkbox'
        default: true
      prefix:
        title: Prefix
        description: The AWS S3 bucket prefix to consider while searching.
        type: string
        example: 'folder/'
      ignoreBody:
        title: Ignore Body
        description: If true, the S3 Object body is ignored. Setting this to true overrides any behavior defined by the `includeBody` option. If false, the S3 object is put in the body.
        type: boolean
        x-descriptors:
        - 'urn:alm:descriptor:com.tectonic.ui:checkbox'
        default: false
      useDefaultCredentialsProvider:
        title: Default Credentials Provider
        description: If true, the S3 client loads credentials through a default credentials provider. If false, it uses the basic authentication method (access key and secret key).
        type: boolean
        x-descriptors:
        - 'urn:alm:descriptor:com.tectonic.ui:checkbox'
        default: false
      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
        x-descriptors:
          - 'urn:alm:descriptor:com.tectonic.ui:checkbox'
        default: false
      delay:
        title: Delay
        description: The number of milliseconds before the next poll of the selected bucket.
        type: integer
        default: 500
      outputFormat:
        title: Output Type
        description: Choose the output type for this Kamelet. The Kamelet supports different output types and performs automatic message conversion according to this data type.
        type: string
        default: binary
        example: binary
  dependencies:
    - "camel:core"
    - "camel:aws2-s3"
    - "mvn:org.apache.camel.kamelets:camel-kamelets-utils:3.21.0"
    - "camel:kamelet"
  template:
    beans:
      - name: dataTypeRegistry
        type: "#class:org.apache.camel.kamelets.utils.format.DefaultDataTypeRegistry"
      - name: outputTypeProcessor
        type: "#class:org.apache.camel.kamelets.utils.format.DataTypeProcessor"
        property:
          - key: scheme
            value: 'aws2-s3'
          - key: format
            value: '{{outputFormat}}'
          - key: registry
            value: '#bean:{{dataTypeRegistry}}'
      - name: renameHeaders
        type: "#class:org.apache.camel.kamelets.utils.headers.DuplicateNamingHeaders"
        property:
          - key: prefix
            value: 'CamelAwsS3'
          - key: renamingPrefix
            value: 'aws.s3.'
          - key: mode
            value: 'filtering'
          - key: selectedHeaders
            value: 'CamelAwsS3Key,CamelAwsS3BucketName'
    from:
      uri: "aws2-s3:{{bucketNameOrArn}}"
      parameters:
        autoCreateBucket: "{{autoCreateBucket}}"
        secretKey: "{{?secretKey}}"
        accessKey: "{{?accessKey}}"
        region: "{{region}}"
        includeBody: "{{includeBody}}"
        ignoreBody: "{{ignoreBody}}"
        deleteAfterRead: "{{deleteAfterRead}}"
        prefix: "{{?prefix}}"
        useDefaultCredentialsProvider: "{{useDefaultCredentialsProvider}}"
        uriEndpointOverride: "{{?uriEndpointOverride}}"
        overrideEndpoint: "{{overrideEndpoint}}"
        delay: "{{delay}}"
      steps:
      - process:
          ref: "{{renameHeaders}}"
      - process:
          ref: "{{outputTypeProcessor}}"
      - to: "kamelet:sink"