github.com/tigera/api@v0.0.0-20240320170621-278e89a8c5fb/pkg/apis/projectcalico/v3/securityeventwebhook.go (about)

     1  // Copyright (c) 2023 Tigera, Inc. All rights reserved.
     2  
     3  package v3
     4  
     5  import (
     6  	corev1 "k8s.io/api/core/v1"
     7  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
     8  )
     9  
    10  type SecurityEventWebhookConsumer string
    11  type SecurityEventWebhookState string
    12  
    13  const (
    14  	KindSecurityEventWebhook     = "SecurityEventWebhook"
    15  	KindSecurityEventWebhookList = "SecurityEventWebhookList"
    16  
    17  	SecurityEventWebhookConsumerSlack   SecurityEventWebhookConsumer = "Slack"
    18  	SecurityEventWebhookConsumerJira    SecurityEventWebhookConsumer = "Jira"
    19  	SecurityEventWebhookConsumerGeneric SecurityEventWebhookConsumer = "Generic"
    20  
    21  	SecurityEventWebhookStateEnabled  SecurityEventWebhookState = "Enabled"
    22  	SecurityEventWebhookStateDisabled SecurityEventWebhookState = "Disabled"
    23  	SecurityEventWebhookStateDebug    SecurityEventWebhookState = "Debug"
    24  )
    25  
    26  // +genclient
    27  // +genclient:nonNamespaced
    28  // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
    29  
    30  type SecurityEventWebhook struct {
    31  	metav1.TypeMeta   `json:",inline"`
    32  	metav1.ObjectMeta `json:"metadata,omitempty"`
    33  	Status            []metav1.Condition       `json:"status,omitempty" validate:"omitempty"`
    34  	Spec              SecurityEventWebhookSpec `json:"spec" validate:"required"`
    35  }
    36  
    37  // +genclient:nonNamespaced
    38  // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
    39  
    40  type SecurityEventWebhookList struct {
    41  	metav1.TypeMeta `json:",inline"`
    42  	metav1.ListMeta `json:"metadata"`
    43  	Items           []SecurityEventWebhook `json:"items"`
    44  }
    45  
    46  type SecurityEventWebhookSpec struct {
    47  	// indicates the SecurityEventWebhook intended consumer, one of: Slack, Jira
    48  	Consumer SecurityEventWebhookConsumer `json:"consumer" validate:"required,oneof=Slack Jira Generic"`
    49  	// defines the webhook desired state, one of: Enabled, Disabled or Debug
    50  	State SecurityEventWebhookState `json:"state" validate:"required,oneof=Enabled Disabled Debug"`
    51  	// defines the SecurityEventWebhook query to be executed against fields of SecurityEvents
    52  	Query string `json:"query" validate:"required"`
    53  	// contains the SecurityEventWebhook's configuration associated with the intended Consumer
    54  	Config []SecurityEventWebhookConfigVar `json:"config" validate:"required"`
    55  }
    56  
    57  type SecurityEventWebhookConfigVar struct {
    58  	Name string `json:"name" protobuf:"bytes,1,opt,name=name"`
    59  	// +optional
    60  	Value string `json:"value,omitempty"`
    61  	// +optional
    62  	ValueFrom *SecurityEventWebhookConfigVarSource `json:"valueFrom,omitempty"`
    63  }
    64  
    65  type SecurityEventWebhookConfigVarSource struct {
    66  	// +optional
    67  	ConfigMapKeyRef *corev1.ConfigMapKeySelector `json:"configMapKeyRef,omitempty" protobuf:"bytes,3,opt,name=configMapKeyRef"`
    68  	// +optional
    69  	SecretKeyRef *corev1.SecretKeySelector `json:"secretKeyRef,omitempty" protobuf:"bytes,4,opt,name=secretKeyRef"`
    70  }
    71  
    72  // NewSecurityEventWebhook creates a new SecurityEventWebhook struct
    73  // with the TypeMetadata initialized to the current API version.
    74  func NewSecurityEventWebhook() *SecurityEventWebhook {
    75  	return &SecurityEventWebhook{
    76  		TypeMeta: metav1.TypeMeta{
    77  			Kind:       KindSecurityEventWebhook,
    78  			APIVersion: GroupVersionCurrent,
    79  		},
    80  	}
    81  }
    82  
    83  // NewSecurityEventWebhookList creates a new SecurityEventWebhookList struct
    84  // with the TypeMetadata initialized to the current API version.
    85  func NewSecurityEventWebhookList() *SecurityEventWebhookList {
    86  	return &SecurityEventWebhookList{
    87  		TypeMeta: metav1.TypeMeta{
    88  			Kind:       KindSecurityEventWebhookList,
    89  			APIVersion: GroupVersionCurrent,
    90  		},
    91  	}
    92  }