# ---------------------------------------------------------------------------
# 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/v1alpha1
kind: Kamelet
metadata:
  name: aws-secrets-manager-sink
  annotations:
    camel.apache.org/kamelet.support.level: "Stable"
    camel.apache.org/catalog.version: "3.21.0"
    camel.apache.org/kamelet.icon: "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB2aWV3Qm94PSIwIDAgNzUgNzUiIHdpZHRoPSIyNTYiIGhlaWdodD0iMjU2Ij48ZGVmcz48c3R5bGU+LmNscy0xe2ZpbGw6dXJsKCNSZWRHcmFkaWVudCk7fS5jbHMtMntmaWxsOiNmZmY7fTwvc3R5bGU+PGxpbmVhckdyYWRpZW50IGlkPSJSZWRHcmFkaWVudCIgeDE9Ii0yMDQyLjU0IiB5MT0iMTk4NS40NyIgeDI9Ii0xOTM2LjQ3IiB5Mj0iMjA5MS41NCIgZ3JhZGllbnRUcmFuc2Zvcm09InRyYW5zbGF0ZSgtMjAwMSAtMTk1Mikgcm90YXRlKC05MCkiIGdyYWRpZW50VW5pdHM9InVzZXJTcGFjZU9uVXNlIj48c3RvcCBvZmZzZXQ9IjAiIHN0b3AtY29sb3I9IiNiZDA4MTYiLz48c3RvcCBvZmZzZXQ9IjEiIHN0b3AtY29sb3I9IiNmZjUyNTIiLz48L2xp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LDAtLjcxLS4zaC0ydi00LjlBNS43MSw1LjcxLDAsMCwwLDQyLjM5LDI0LjI1Wk0zMi41LDI4LjYxYzAtMi4yNiwyLjI1LTQuMDksNS00LjA5aDBhNS41NSw1LjU1LDAsMCwxLDMuNiwxLjI1LDMuNzYsMy43NiwwLDAsMSwxLjQxLDIuODV2NC45aC0xMFptMTMsOS45MWgtM3YyaDN2MmgtM3YyaDN2M2gtMTZ2LTEyaDE2WiIvPjxwYXRoIGNsYXNzPSJjbHMtMiIgZD0iTTM2LjUsNDIuNzZ2Mi43NmgyVjQyLjc2YTIuOTMsMi45MywwLDEsMC0yLDBabTEtMy44MkExLjA4LDEuMDgsMCwxLDEsMzYuNDMsNDAsMS4wNywxLjA3LDAsMCwxLDM3LjUsMzguOTRaIi8+PC9nPjwvZz48L3N2Zz4K"
    camel.apache.org/provider: "Apache Software Foundation"
    camel.apache.org/kamelet.group: "AWS Secrets Manager"
    camel.apache.org/kamelet.namespace: "AWS"
  labels:
    camel.apache.org/kamelet.type: "sink"
spec:
  definition:
    title: "AWS Secrets Manager Sink"
    description: |-
      Create a secret in AWS Secrets Manager.

      Access Key/Secret Key are the basic method for authenticating to the AWS Secrets Manager Service. These parameters are optional because the Kamelet provides the 'useDefaultCredentialsProvider'.
      
      When using a default Credentials Provider the Secrets Manager client will load the credentials through this provider and won't use the static credential. This is reason for not having the access key and secret key as mandatory parameter for this Kamelet.

      The Kamelet expects the following headers to be set:

      - `secret-name` / `ce-secret-name`: as the secret name to create.

      If the header won't be set the exchange ID will be used as secret name.
    required:
      - region
    type: object
    properties:
      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"]
      useDefaultCredentialsProvider:
        title: Default Credentials Provider
        description: Set whether the Secrets Manager client should expect to load credentials through a default credentials provider or to expect static credentials to be passed in.
        type: boolean
        x-descriptors:
        - 'urn:alm:descriptor:com.tectonic.ui:checkbox'
        default: false
  dependencies:
    - "camel:core"
    - "camel:aws-secrets-manager"
    - "camel:kamelet"
  template:
    from:
      uri: "kamelet:source"
      steps:
      - choice:
          when:
          - simple: "${header[secret-name]}"
            steps:
            - set-header:
                name: CamelAwsSecretsManagerSecretName
                simple: "${header[secret-name]}"
          - simple: "${header[ce-secret-name]}"
            steps:
            - set-header:
                name: CamelAwsSecretsManagerSecretName
                simple: "${header[ce-secret-name]}"
          otherwise:
            steps:
            - set-header:
                name: CamelAwsSecretsManagerSecretName
                simple: "${exchangeId}"
      - to:
          uri: "aws-secrets-manager:kamelet"
          parameters:
            secretKey: "{{?secretKey}}"
            accessKey: "{{?accessKey}}"
            region: "{{region}}"
            useDefaultCredentialsProvider: "{{useDefaultCredentialsProvider}}"
            operation: "createSecret"