# ---------------------------------------------------------------------------
# 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-cloudtrail-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,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB2aWV3Qm94PSIwIDAgNzQuMzc1IDg1IiBmaWxsPSIjZmZmIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiIHN0cm9rZT0iIzAwMCIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIj48dXNlIHhsaW5rOmhyZWY9IiNBIiB4PSIyLjE4OCIgeT0iMi41Ii8+PHN5bWJvbCBpZD0iQSIgb3ZlcmZsb3c9InZpc2libGUiPjxnIHN0cm9rZT0ibm9uZSI+PHBhdGggZD0iTTkuOTY2IDM1LjQ5M2wtMi4yODguMTc2TDAgMzUuMzc2bDIuMTIzLTEwLjAzOSA3Ljg0MyAxMC4xNTZ6IiBmaWxsPSIjM2M0OTI5Ii8+PHBhdGggZD0iTTkuOTY2IDQ0LjgzbC0yLjI4OC0uMTc2TDAgNDQuOTQ3bDIuMTIzIDEwLjAzOUw5Ljk2NiA0NC44M3oiIGZpb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iIgZmlsbD0iIzc1OWMzZSIvPjxwYXRoIGQ9Ik0yMC4yIDcyLjk5NUwzNC45ODkgODBsMzQuNjYtNDAtMzQuNjYtNDBMMjAuMiA3LjAwNXY2NS45OXoiIGZpbGw9IiM0YjYxMmMiLz48cGF0aCBkPSJNNzAgNjMuNDM0TDM0Ljk5IDgwVjBMNzAgMTYuNTY2djQ2Ljg2OHoiIGZpbGw9IiM3NTljM2UiLz48L2c+PC9zeW1ib2w+PC9zdmc+"
    camel.apache.org/provider: "Apache Software Foundation"
    camel.apache.org/kamelet.group: "AWS Cloudtrail"
    camel.apache.org/kamelet.namespace: "AWS"
  labels:
    camel.apache.org/kamelet.type: "source"
spec:
  definition:
    title: "AWS Cloudtrail Source"
    description: Receive data from an AWS Cloudtrail.
    required:
      - region
    type: object
    properties:
      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 Cloudtrail 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 Cloudtrail client should expect to load credentials through a profile credentials provider.
        type: boolean
        default: false
      useSessionCredentials:
        title: Session Credentials
        description: Set whether the CloudTrail 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 CloudTrail.
        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
      maxResults:
        title: Max Results
        description: Maximum number of records that will be fetched in each poll.
        type: integer
        default: 1
      eventSource:
        title: Event Source
        description: Specify an event source to select events.
        type: string
        example: secretsmanager.amazonaws.com
  dataTypes:
    out:
      default: text
      headers:
        CamelAwsCloudTrailEventId:
          title: Cloudtrail Event Id
          description: The event ID of the cloud trail event consumed
          type: string
        CamelAwsCloudTrailEventName:
          title: Cloudtrail Event Name
          description: The event Name of the cloud trail event consumed
          type: string
        CamelAwsCloudTrailEventSource:
          title: Cloudtrail Event Source
          description: The event Source of the cloud trail event consumed
          type: string
        CamelAwsCloudTrailEventUsername:
          title: Cloudtrail Event Username
          description: The associated username of the event of the cloud trail event consumed
          type: string
      types:
        text:
          format: "text-plain"
          description: Default text representation of the Cloudtrail Event
          mediaType: text/plain
        cloudevents:
          format: "aws-cloudtrail:application-cloudevents"
          description: |-
            Data type transformer converts AWS Cloudtrail lookup events response to CloudEvent v1_0 data format. The data type
            sets Camel specific CloudEvent headers with values extracted from AWS Cloudtrail lookup events response.
          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.cloudtrail.lookupEvents"
              type: string
            CamelCloudEventSource:
              title: CloudEvent Source
              description: The event source. By default, the Cloudtrail event source name with prefix "aws.cloudtrail.event.source.".
              type: string
            CamelCloudEventSubject:
              title: CloudEvent Subject
              description: The event subject. The Cloudtrail Event Id.
              type: string
            CamelCloudEventTime:
              title: CloudEvent Time
              description: The exchange creation timestamp as event time.
              type: string
  dependencies:
    - "camel:core"
    - "camel:aws-cloudtrail"
    - "camel:kamelet"
  template:
    from:
      uri: "aws-cloudtrail:cloudtrail"
      parameters:
        secretKey: "{{?secretKey}}"
        accessKey: "{{?accessKey}}"
        region: "{{region}}"
        eventSource: "{{?eventSource}}"
        useDefaultCredentialsProvider: "{{useDefaultCredentialsProvider}}"
        useProfileCredentialsProvider: "{{useProfileCredentialsProvider}}"
        useSessionCredentials: "{{useSessionCredentials}}"
        uriEndpointOverride: "{{?uriEndpointOverride}}"
        profileCredentialsName: "{{?profileCredentialsName}}"
        sessionToken: "{{?sessionToken}}"
        overrideEndpoint: "{{overrideEndpoint}}"
        maxResults: "{{maxResults}}"
      steps:
      - to: "kamelet:sink"