# Copyright 2021 TriggerMesh Inc.
#
# Licensed 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: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: ibmmqsources.sources.triggermesh.io
  labels:
    duck.knative.dev/addressable: 'true'
    triggermesh.io/crd-install: 'true'
  annotations:
    registry.knative.dev/eventTypes: |
      [
        { "type": "io.triggermesh.ibm.mq.message" }
      ]
spec:
  group: sources.triggermesh.io
  names:
    kind: IBMMQSource
    plural: ibmmqsources
    categories:
    - all
    - knative
    - eventing
    - sources
  scope: Namespaced
  versions:
  - name: v1alpha1
    served: true
    storage: true
    subresources:
      status: {}
    schema:
      openAPIV3Schema:
        type: object
        description: TriggerMesh event source for IBM MQ.
        properties:
          spec:
            description: Desired state of the event source.
            type: object
            properties:
              connectionName:
                description: IBM MQ server URI, e.g. ibm-mq.default.svc.cluster.local(1414).
                type: string
              channelName:
                description: The name of IBM MQ Channel to listen to events on. For more information,
                  please refer to the IBM MQ documentation at
                  https://www.ibm.com/docs/en/ibm-mq/9.2?topic=types-channels.
                type: string
              queueManager:
                description: IBM MQ Queue Manager name. For more information, please refer to the IBM MQ
                  documentation at https://www.ibm.com/docs/en/ibm-mq/9.2?topic=types-mq-queue-managers.
                type: string
              queueName:
                description: IBM MQ Queue name. For more information, please refer to the IBM MQ
                  documentation at https://www.ibm.com/docs/en/ibm-mq/9.2?topic=types-queues.
                type: string
              delivery:
                description: Events delivery parameters.
                type: object
                properties:
                  deadLetterQueueManager:
                    description: The name of the Dead Letter Queue Manager. For more information,
                      please refer to the IBM MQ documentation at
                      https://www.ibm.com/docs/en/ibm-mq/9.2?topic=components-dead-letter-queues
                    type: string
                  deadLetterQueue:
                    description: The name of the Dead Letter Queue. For more information,
                      please refer to the IBM MQ documentation at
                      https://www.ibm.com/docs/en/ibm-mq/9.2?topic=components-dead-letter-queues
                    type: string
                  backoffDelay:
                    description: Delay between delivery retries for failed messages.
                    type: integer
                  retry:
                    description: The number of delivery retries before moving the message to DLQ.
                    type: integer
                required:
                - deadLetterQueue
              sink:
                description: The destination of events sourced from IBM MQ.
                type: object
                properties:
                  ref:
                    description: Reference to an addressable Kubernetes object to be used as the destination of events.
                    type: object
                    properties:
                      apiVersion:
                        type: string
                      kind:
                        type: string
                      namespace:
                        type: string
                      name:
                        type: string
                    required:
                    - apiVersion
                    - kind
                    - name
                  uri:
                    description: URI to use as the destination of events.
                    type: string
                    format: uri
                oneOf:
                - required: [ref]
                - required: [uri]
              credentials:
                description: IBM MQ server connection authentication parameters. For more information about
                  authentication, please refer to the IBM MQ documentation at
                  https://www.ibm.com/docs/en/ibm-mq/9.0?topic=mechanisms-connection-authentication.
                type: object
                properties:
                  username:
                    description: IBM MQ user identifier for client application. For more information, please refer
                      to the IBM MQ documentation at https://www.ibm.com/docs/en/ibm-mq/9.2?topic=application-user-ids.
                    type: object
                    properties:
                      value:
                        description: Plain text user ID.
                        type: string
                      valueFromSecret:
                        description: A reference to a Kubernetes Secret object containing the user ID.
                        type: object
                        properties:
                          name:
                            type: string
                          key:
                            type: string
                        required:
                        - name
                        - key
                  password:
                    description: IBM MQ client application password. For more information, please refer to the
                      IBM MQ documentation at https://www.ibm.com/docs/en/ibm-mq/9.2?topic=mq-mqcsp-password-protection.
                    type: object
                    properties:
                      value:
                        description: Plain text password.
                        type: string
                      valueFromSecret:
                        description: A reference to a Kubernetes Secret object containing the password.
                        type: object
                        properties:
                          name:
                            type: string
                          key:
                            type: string
                        required:
                        - name
                        - key
                    oneOf:
                    - required: [value]
                    - required: [valueFromSecret]
                  tls:
                    description: TLS configuration for IBM MQ client. For more information, please refer to the IBM MQ
                      documentation at
                      https://www.ibm.com/docs/en/ibm-mq/9.2?topic=mechanisms-tls-security-protocols-in-mq.
                    type: object
                    properties:
                      cipher:
                        description: Message encryption and authentication algorithm.
                          For more information, please refer to the IBM MQ documentation at
                          https://www.ibm.com/docs/en/ibm-mq/9.2?topic=tls-cipherspecs-ciphersuites.
                        type: string
                      clientAuthRequired:
                        description: Parameter to specify whether TLS client authentication is required. For more
                          information, please refer to the IBM MQ documentation at
                          https://www.ibm.com/docs/en/ibm-mq/9.2?topic=fields-sslclientauth-mqlong.
                        type: boolean
                      certLabel:
                        description: Unique identifier representing a digital certificate stored in a key repository.
                          For more information, please refer to the IBM MQ documentation at
                          https://www.ibm.com/docs/en/ibm-mq/9.2?topic=repository-digital-certificate-labels-understanding-requirements.
                        type: string
                      keyRepository:
                        description: Key repository for (m)TLS connection. For more information, please refer to the
                          IBM MQ documentation at https://www.ibm.com/docs/en/ibm-mq/9.2?topic=mq-ssltls-key-repository.
                        type: object
                        properties:
                          keyDatabase:
                            type: object
                            properties:
                              valueFromSecret:
                                description: A reference to a Kubernetes Secret object containing the key database.
                                type: object
                                properties:
                                  name:
                                    type: string
                                  key:
                                    type: string
                                required:
                                - name
                                - key
                            required:
                            - valueFromSecret
                          passwordStash:
                            type: object
                            properties:
                              valueFromSecret:
                                description: A reference to a Kubernetes Secret object containing the password stash.
                                type: object
                                properties:
                                  name:
                                    type: string
                                  key:
                                    type: string
                                required:
                                - name
                                - key
                            required:
                            - valueFromSecret
                        required:
                        - keyDatabase
                        - passwordStash
                    required:
                    - cipher
                    - clientAuthRequired
                    - keyRepository
                anyOf:
                - required: [username, password]
                - required: [tls]
            required:
            - connectionName
            - channelName
            - queueManager
            - queueName
            - sink
            - credentials
          status:
            type: object
            description: Reported status of the event source.
            properties:
              sinkUri:
                description: URI of the sink where events are currently sent to.
                type: string
                format: uri
              ceAttributes:
                type: array
                items:
                  type: object
                  properties:
                    type:
                      type: string
                    source:
                      type: string
                  required:
                  - type
                  - source
              observedGeneration:
                type: integer
                format: int64
              conditions:
                type: array
                items:
                  type: object
                  properties:
                    type:
                      type: string
                    status:
                      type: string
                      enum: ['True', 'False', Unknown]
                    severity:
                      type: string
                      enum: [Error, Warning, Info]
                    reason:
                      type: string
                    message:
                      type: string
                    lastTransitionTime:
                      type: string
                      format: date-time
                  required:
                  - type
                  - status
              address:
                description: Public address of the HTTP/S endpoint that is subscribed to the Amazon SNS topic.
                type: object
                properties:
                  url:
                    type: string
    additionalPrinterColumns:
    - name: Ready
      type: string
      jsonPath: .status.conditions[?(@.type=='Ready')].status
    - name: Reason
      type: string
      jsonPath: .status.conditions[?(@.type=='Ready')].reason
    - name: URL
      type: string
      jsonPath: .status.address.url
    - name: Sink
      type: string
      jsonPath: .status.sinkUri
    - name: Age
      type: date
      jsonPath: .metadata.creationTimestamp
