generator_webhook.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.
  11. */
  12. package v1alpha1
  13. import (
  14. metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  15. )
  16. // WebhookSpec controls the behavior of the external generator. Any body parameters should be passed to the server through the parameters field.
  17. type WebhookSpec struct {
  18. // Webhook Method
  19. // +optional, default GET
  20. Method string `json:"method,omitempty"`
  21. // Webhook url to call
  22. URL string `json:"url"`
  23. // Headers
  24. // +optional
  25. Headers map[string]string `json:"headers,omitempty"`
  26. // Body
  27. // +optional
  28. Body string `json:"body,omitempty"`
  29. // Timeout
  30. // +optional
  31. Timeout *metav1.Duration `json:"timeout,omitempty"`
  32. // Result formatting
  33. Result WebhookResult `json:"result"`
  34. // Secrets to fill in templates
  35. // These secrets will be passed to the templating function as key value pairs under the given name
  36. // +optional
  37. Secrets []WebhookSecret `json:"secrets,omitempty"`
  38. // PEM encoded CA bundle used to validate webhook server certificate. Only used
  39. // if the Server URL is using HTTPS protocol. This parameter is ignored for
  40. // plain HTTP protocol connection. If not set the system root certificates
  41. // are used to validate the TLS connection.
  42. // +optional
  43. CABundle []byte `json:"caBundle,omitempty"`
  44. // The provider for the CA bundle to use to validate webhook server certificate.
  45. // +optional
  46. CAProvider *WebhookCAProvider `json:"caProvider,omitempty"`
  47. }
  48. type WebhookCAProviderType string
  49. const (
  50. WebhookCAProviderTypeSecret WebhookCAProviderType = "Secret"
  51. WebhookCAProviderTypeConfigMap WebhookCAProviderType = "ConfigMap"
  52. )
  53. // Defines a location to fetch the cert for the webhook provider from.
  54. type WebhookCAProvider struct {
  55. // The type of provider to use such as "Secret", or "ConfigMap".
  56. // +kubebuilder:validation:Enum="Secret";"ConfigMap"
  57. Type WebhookCAProviderType `json:"type"`
  58. // The name of the object located at the provider type.
  59. Name string `json:"name"`
  60. // The key the value inside of the provider type to use, only used with "Secret" type
  61. // +kubebuilder:validation:Optional
  62. Key string `json:"key,omitempty"`
  63. // The namespace the Provider type is in.
  64. // +optional
  65. Namespace *string `json:"namespace,omitempty"`
  66. }
  67. type WebhookResult struct {
  68. // Json path of return value
  69. // +optional
  70. JSONPath string `json:"jsonPath,omitempty"`
  71. }
  72. type WebhookSecret struct {
  73. // Name of this secret in templates
  74. Name string `json:"name"`
  75. // Secret ref to fill in credentials
  76. SecretRef SecretKeySelector `json:"secretRef"`
  77. }
  78. type SecretKeySelector struct {
  79. // The name of the Secret resource being referred to.
  80. Name string `json:"name,omitempty"`
  81. // The key where the token is found.
  82. Key string `json:"key,omitempty"`
  83. }
  84. // Webhook connects to a third party API server to handle the secrets generation
  85. // configuration parameters in spec.
  86. // You can specify the server, the token, and additional body parameters.
  87. // See documentation for the full API specification for requests and responses.
  88. // +kubebuilder:object:root=true
  89. // +kubebuilder:storageversion
  90. // +kubebuilder:subresource:status
  91. // +kubebuilder:metadata:labels="external-secrets.io/component=controller"
  92. // +kubebuilder:resource:scope=Namespaced,categories={external-secrets, external-secrets-generators},shortName=webhookl
  93. type Webhook struct {
  94. metav1.TypeMeta `json:",inline"`
  95. metav1.ObjectMeta `json:"metadata,omitempty"`
  96. Spec WebhookSpec `json:"spec,omitempty"`
  97. }
  98. // +kubebuilder:object:root=true
  99. // ExternalList contains a list of Webhook Generator resources.
  100. type WebhookList struct {
  101. metav1.TypeMeta `json:",inline"`
  102. metav1.ListMeta `json:"metadata,omitempty"`
  103. Items []Webhook `json:"items"`
  104. }