# Copyright 2020-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: webhooksources.sources.triggermesh.io
  labels:
    eventing.knative.dev/source: 'true'
    duck.knative.dev/source: 'true'
    knative.dev/crd-install: 'true'
    triggermesh.io/crd-install: 'true'
spec:
  group: sources.triggermesh.io
  scope: Namespaced
  names:
    kind: WebhookSource
    plural: webhooksources
    categories:
    - all
    - knative
    - eventing
    - sources
  versions:
  - name: v1alpha1
    served: true
    storage: true
    subresources:
      status: {}
    schema:
      openAPIV3Schema:
        description: TriggerMesh event source for receiving arbitrary events over a HTTP/S webhook.
        type: object
        properties:
          spec:
            description: Desired state of the event source.
            type: object
            properties:
              eventType:
                description: "Value of the CloudEvents 'type' attribute to set on ingested events. Describes the type of
                  event related to the originating occurrence. Please refer to the CloudEvents specification for more
                  details: https://github.com/cloudevents/spec/blob/v1.0.1/spec.md#type"
                type: string
              eventSource:
                description: "Value of the CloudEvents 'source' attribute to set on ingested events. Identifies the
                  context in which an event happened. Must be expressed as a URI-reference. Please refer to the
                  CloudEvents specification for more details: https://github.com/cloudevents/spec/blob/v1.0.1/spec.md#source-1"
                type: string
              basicAuthUsername:
                description: User name HTTP clients must set to authenticate with the webhook using HTTP Basic authentication.
                type: string
              basicAuthPassword:
                description: Password HTTP clients must set to authenticate with the webhook using HTTP Basic authentication.
                type: object
                properties:
                  value:
                    description: Literal value of the password.
                    type: string
                  valueFromSecret:
                    description: A reference to a Kubernetes Secret object containing the password.
                    type: object
                    properties:
                      name:
                        description: Name of the Secret object.
                        type: string
                      key:
                        description: Key from the Secret object.
                        type: string
                    required:
                    - name
                    - key
                oneOf:
                - required: [value]
                - required: [valueFromSecret]
              sink:
                description: The destination of events generated from requests to the webhook.
                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]
            required:
            - eventType
            - sink
          status:
            description: Reported status of the event source.
            type: object
            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 exposing the webhook.
                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

