# ---------------------------------------------------------------------------
# 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-eventhubs-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,PHN2ZyBoZWlnaHQ9IjI1MDAiIHZpZXdCb3g9Ii0uMDc1IC0uMTc0IDE1OC40IDE2My4xMDEiIHdpZHRoPSIyNDM5IiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxnIGZpbGw9IiMwMDZmZDQiPjxwYXRoIGQ9Im02LjIyNS4wMjZoMTQ2LjZjMS4zIDAgMy0uMiA0LjEuNS45LjYuOCAxLjUuOCAyLjR2MzEuOGMwIC45LS4xIDEuOC0uOCAyLjQtLjguOC0xLjcuOC0yLjguOGgtMTQuMWMtMS4yIDAtMi40LS4xLTMuMi0xLS43LS44LS43LTEuOS0uNy0yLjl2LTEyLjVoLTExNHYxMi44YzAgMS0uMSAyLS44IDIuOC0uOC44LTEuOC44LTIuOC44aC0xNC44Yy0xIDAtMiAwLTIuOC0uOC0uOC0uOC0uOC0xLjctLjktMi44di0yOC44YzAtMS4xLS4xLTIuMy4xLTMuNC4yLTEgMS4xLTEuOCAyLjEtMiAxLjQtLjIgMi43LS4xIDQtLjF6Ii8+PHBhdGggZD0ibTM2LjYyNSAzNy42MjdoMTkuNGMxLjIgMCAy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jkuNy0uOCAxLjYtLjggMi42LS45em0tMzYuMSAxNmgxNy44YzEgMCAxLjkuMSAyLjYuOXMuNyAxLjcuNyAyLjd2MTQuMWMwIDEgMCAxLjktLjcgMi43cy0xLjcuOS0yLjcuOWgtMTkuOGMtMS4xIDAtMi4yIDAtMi45LTEtLjctLjktLjctMS45LS43LTN2LTE0LjFjMC0xLjMuNS0yLjQgMS43LTIuOSAxLjItLjQgMi43LS4yIDQtLjN6bS0zNC41IDIxLjZoMTQuNGMxLjEgMCAyLjIuMSAzIDEgLjcuOC42IDEuNy43IDIuN3YxMi43aDExNC40di0xMi40YzAtMSAwLTIgLjgtMi44LjktLjkgMS45LS45IDMuMS0uOWgxMy40YzEgMCAyLjIgMCAzIC42LjkuNyAxLjMgMS45IDEuMyAzdjMwLjVjMCAxLjEtLjEgMi0uOSAyLjctMSAxLTIuOC42LTQuMS43aC0xNDkuM2MtLjkgMC0xLjctLjEtMi4zLS43LS44LS43LS45LTEuNy0uOS0yLjd2LTMwLjhjMC0xLjIuMi0yLjMgMS4xLTMuMS41LS41IDEuNC0uNCAyLjMtLjV6Ii8+PC9nPjwvc3ZnPg=="
    camel.apache.org/provider: "Apache Software Foundation"
    camel.apache.org/kamelet.group: "Azure Eventhubs"
    camel.apache.org/kamelet.namespace: "Azure"
  labels:
    camel.apache.org/kamelet.type: "sink"
spec:
  definition:
    title: "Azure Eventhubs Sink"
    description: |-
      Send events to Azure Event Hubs.

      The Kamelet checks for the `partition-id` / `ce-partition-id` header which is an identifier of the Event Hub partition that the event will be sent to. If the identifier is not specified, the Event Hubs service will be responsible for routing events that are sent to an available partition.
         
      A header is optional. If the header is not set, the partition is assigned by Event Hubs.
    required:
      - namespaceName
      - eventhubName
      - sharedAccessName
      - sharedAccessKey
    type: object
    properties:
      namespaceName:
        title: Eventhubs Namespace
        description: The Event Hubs namespace.
        type: string
      eventhubName:
        title: Eventhubs Name
        description: The Event Hub name.
        type: string
      sharedAccessName:
        title: Share Access Name
        description: The Event Hubs SAS key name.
        type: string
        x-descriptors:
        - urn:camel:group:credentials
      sharedAccessKey:
        title: Share Access Key
        description: The key for the Event Hubs SAS key name.
        type: string
        format: password
        x-descriptors:
        - urn:alm:descriptor:com.tectonic.ui:password
        - urn:camel:group:credentials
  dependencies:
    - "camel:core"
    - "camel:azure-eventhubs"
    - "camel:kamelet"
  template:
    from:
      uri: "kamelet:source"
      steps:
      - choice:
          when:
          - simple: "${header[partition-id]}"
            steps:
            - set-header:
                name: CamelAzureEventHubsPartitionId
                simple: "${header[partition-id]}"
          - simple: "${header[ce-partition-id]}"
            steps:
            - set-header:
                name: CamelAzureEventHubsPartitionId
                simple: "${header[ce-partition-id]}"
      - to:
          uri: "azure-eventhubs://{{namespaceName}}/{{eventhubName}}"
          parameters:
            sharedAccessName: "{{sharedAccessName}}"
            sharedAccessKey: "{{sharedAccessKey}}"