# ---------------------------------------------------------------------------
# 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: ceph-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,[encoded data, 4928 characters]"
    camel.apache.org/provider: "Apache Software Foundation"
    camel.apache.org/kamelet.group: "Ceph"
    camel.apache.org/kamelet.namespace: "Cloud"
  labels:
    camel.apache.org/kamelet.type: "sink"
spec:
  definition:
    title: "Ceph Sink"
    description: |-
      Upload data to an Ceph Bucket managed by a Object Storage Gateway.

      In the header, you can optionally set the `file` / `ce-file` property to specify the name of the file to upload.

      If you do not set the property in the header, the Kamelet uses the exchange ID for the file name.
    required:
      - cephUrl
      - accessKey
      - secretKey
      - bucketName
      - zoneGroup
    type: object
    properties:
      bucketName:
        title: Bucket Name
        description: The Ceph Bucket name.
        type: string
      accessKey:
        title: Access Key
        description: The access key.
        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.
        type: string
        format: password
        x-descriptors:
        - urn:alm:descriptor:com.tectonic.ui:password
        - urn:camel:group:credentials
      zoneGroup:
        title: Bucket Zone Group
        description: The bucket zone group.
        type: string
      autoCreateBucket:
        title: Autocreate Bucket
        description: Specifies to automatically create the bucket.
        type: boolean
        x-descriptors:
        - 'urn:alm:descriptor:com.tectonic.ui:checkbox'
        default: false
      cephUrl:
        title: Ceph Url Address
        description: Set the Ceph Object Storage Address Url.
        type: string
        example: "http://ceph-storage-address.com"
      keyName:
        title: Key Name
        description: The key name for saving an element in the bucket.
        type: string
  dependencies:
    - "camel:core"
    - "camel:aws2-s3"
    - "camel:kamelet"
  template:
    from:
      uri: "kamelet:source"
      steps:
      - choice:
          when:
          - simple: "${header[file]}"
            steps:
            - set-header:
                name: CamelAwsS3Key
                simple: "${header[file]}"
          - simple: "${header[ce-file]}"
            steps:
            - set-header:
                name: CamelAwsS3Key
                simple: "${header[ce-file]}"
          - simple: "'{{?keyName}}' == ''"
            steps:
            - set-header:
                name: CamelAwsS3Key
                simple: "${exchangeId}"
      - to:
          uri: "aws2-s3:{{bucketName}}"
          parameters:
            secretKey: "{{?secretKey}}"
            accessKey: "{{?accessKey}}"
            region: "{{zoneGroup}}"
            autoCreateBucket: "{{autoCreateBucket}}"
            uriEndpointOverride: "{{?cephUrl}}"
            overrideEndpoint: "true"
            keyName: "{{?keyName}}"