# ---------------------------------------------------------------------------
# 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: azure-storage-blob-source
  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,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB2aWV3Qm94PSIwIDAgOTEgODEiIGZpbGw9IiNmZmYiIGZpbGwtcnVsZT0iZXZlbm9kZCIgc3Ryb2tlPSIjMDAwIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiPjx1c2UgeGxpbms6aHJlZj0iI0EiIHg9Ii41IiB5PSIuNSIvPjxzeW1ib2wgaWQ9IkEiIG92ZXJmbG93PSJ2aXNpYmxlIj48cGF0aCBkPSJNNjcuNTU4IDBIMjIuNDQxTDAgNDBsMjIuNDQxIDQwaDQ1LjExN0w5MCA0MCA2Ny41NTggMHptLjIzNCA1Ny45NjRjMCAzLjM1My0yLjgwNSA2LjIyNy02LjA3OCA2LjIyN0gyOC41MmMtMy4yNzMgMC02LjA3OC0yLjg3NC02LjA3OC02LjIyN1YyMi4yNzZjMC0zLjM1MyAyLjgwNS02LjIyOCA2LjA3OC02LjIyOGgyOS45MjJsOS4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group: "Azure Storage Blob"
    camel.apache.org/kamelet.namespace: "Azure"
  labels:
    camel.apache.org/kamelet.type: "source"
spec:
  definition:
    title: "Azure Storage Blob Source"
    description: |-
      Consume files from Azure Storage Blob.

      Two headers will be duplicated with different names for clarity at sink level, CamelAzureStorageBlobETag will be duplicated into azure.storage.blob.e.tag and CamelAzureStorageBlobBlobSize will be duplicated in azure.storage.blob.blob.size
    required:
      - accountName
      - containerName
    type: object
    properties:
      accountName:
        title: Account Name
        description: The Azure Storage Blob account name.
        type: string
        x-descriptors:
        - urn:camel:group:credentials
      containerName:
        title: Container Name
        description: The Azure Storage Blob container name.
        type: string
      accessKey:
        title: Access Key
        description: The Azure Storage Blob access key.
        type: string
        format: password
        x-descriptors:
        - urn:alm:descriptor:com.tectonic.ui:password
        - urn:camel:group:credentials
      delay:
        title: Delay
        description: The number of milliseconds before the next poll of the selected blob.
        type: integer
        default: 500
      deleteAfterRead:
        title: Auto-delete Blob 
        description: Specifies to delete blobs after consuming them
        type: boolean
        x-descriptors:
        - 'urn:alm:descriptor:com.tectonic.ui:checkbox'
        default: false
      credentialType:
        title: Credential Type
        description: Determines the credential strategy to adopt.
        type: string
        enum: ["SHARED_ACCOUNT_KEY", "AZURE_IDENTITY"]
        default: "SHARED_ACCOUNT_KEY"
  dependencies:
    - "camel:azure-storage-blob"
    - "camel:kamelet"
    - "camel:core"
    - "camel:jsonpath"
    - "camel:timer"
    - "mvn:org.apache.camel.kamelets:camel-kamelets-utils:3.21.0"
  template:
    beans:
      - name: duplicateHeaders
        type: "#class:org.apache.camel.kamelets.utils.headers.DuplicateNamingHeaders"
        property:
          - key: prefix
            value: 'CamelAzureStorageBlob'
          - key: renamingPrefix
            value: 'azure.storage.blob.'
          - key: mode
            value: 'filtering'
          - key: selectedHeaders
            value: 'CamelAzureStorageBlobETag,CamelAzureStorageBlobBlobSize'
    from:
      uri: "azure-storage-blob:{{accountName}}/{{containerName}}"
      parameters:
        accessKey: "{{?accessKey}}"
        credentialType: "{{credentialType}}"
        delay: "{{delay}}"
      steps:
        - process:
            ref: "{{duplicateHeaders}}"
        - to: "kamelet:sink"
        - choice:
            precondition: true
            when:
              - simple: '${properties:deleteAfterRead:true}'
                steps:
                  - to:
                      uri: "azure-storage-blob:{{accountName}}/{{containerName}}"
                      parameters:
                        operation: "deleteBlob"
                        accessKey: "{{?accessKey}}"
                        credentialType: "{{credentialType}}"