github.com/cilium/cilium@v1.16.2/api/v1/models/endpoint_policy.go (about) 1 // Code generated by go-swagger; DO NOT EDIT. 2 3 // Copyright Authors of Cilium 4 // SPDX-License-Identifier: Apache-2.0 5 6 package models 7 8 // This file was generated by the swagger tool. 9 // Editing this file might prove futile when you re-run the swagger generate command 10 11 import ( 12 "context" 13 14 "github.com/go-openapi/errors" 15 "github.com/go-openapi/strfmt" 16 "github.com/go-openapi/swag" 17 ) 18 19 // EndpointPolicy Policy information of an endpoint 20 // 21 // +k8s:deepcopy-gen=true 22 // 23 // swagger:model EndpointPolicy 24 type EndpointPolicy struct { 25 26 // List of identities to which this endpoint is allowed to communicate 27 // 28 AllowedEgressIdentities []int64 `json:"allowed-egress-identities"` 29 30 // List of identities allowed to communicate to this endpoint 31 // 32 AllowedIngressIdentities []int64 `json:"allowed-ingress-identities"` 33 34 // Build number of calculated policy in use 35 Build int64 `json:"build,omitempty"` 36 37 // cidr policy 38 CidrPolicy *CIDRPolicy `json:"cidr-policy,omitempty"` 39 40 // List of identities to which this endpoint is not allowed to communicate 41 // 42 DeniedEgressIdentities []int64 `json:"denied-egress-identities"` 43 44 // List of identities not allowed to communicate to this endpoint 45 // 46 DeniedIngressIdentities []int64 `json:"denied-ingress-identities"` 47 48 // Own identity of endpoint 49 ID int64 `json:"id,omitempty"` 50 51 // l4 52 L4 *L4Policy `json:"l4,omitempty"` 53 54 // Whether policy enforcement is enabled (ingress, egress, both or none) 55 PolicyEnabled EndpointPolicyEnabled `json:"policy-enabled,omitempty"` 56 57 // The agent-local policy revision 58 PolicyRevision int64 `json:"policy-revision,omitempty"` 59 } 60 61 // Validate validates this endpoint policy 62 func (m *EndpointPolicy) Validate(formats strfmt.Registry) error { 63 var res []error 64 65 if err := m.validateCidrPolicy(formats); err != nil { 66 res = append(res, err) 67 } 68 69 if err := m.validateL4(formats); err != nil { 70 res = append(res, err) 71 } 72 73 if err := m.validatePolicyEnabled(formats); err != nil { 74 res = append(res, err) 75 } 76 77 if len(res) > 0 { 78 return errors.CompositeValidationError(res...) 79 } 80 return nil 81 } 82 83 func (m *EndpointPolicy) validateCidrPolicy(formats strfmt.Registry) error { 84 if swag.IsZero(m.CidrPolicy) { // not required 85 return nil 86 } 87 88 if m.CidrPolicy != nil { 89 if err := m.CidrPolicy.Validate(formats); err != nil { 90 if ve, ok := err.(*errors.Validation); ok { 91 return ve.ValidateName("cidr-policy") 92 } else if ce, ok := err.(*errors.CompositeError); ok { 93 return ce.ValidateName("cidr-policy") 94 } 95 return err 96 } 97 } 98 99 return nil 100 } 101 102 func (m *EndpointPolicy) validateL4(formats strfmt.Registry) error { 103 if swag.IsZero(m.L4) { // not required 104 return nil 105 } 106 107 if m.L4 != nil { 108 if err := m.L4.Validate(formats); err != nil { 109 if ve, ok := err.(*errors.Validation); ok { 110 return ve.ValidateName("l4") 111 } else if ce, ok := err.(*errors.CompositeError); ok { 112 return ce.ValidateName("l4") 113 } 114 return err 115 } 116 } 117 118 return nil 119 } 120 121 func (m *EndpointPolicy) validatePolicyEnabled(formats strfmt.Registry) error { 122 if swag.IsZero(m.PolicyEnabled) { // not required 123 return nil 124 } 125 126 if err := m.PolicyEnabled.Validate(formats); err != nil { 127 if ve, ok := err.(*errors.Validation); ok { 128 return ve.ValidateName("policy-enabled") 129 } else if ce, ok := err.(*errors.CompositeError); ok { 130 return ce.ValidateName("policy-enabled") 131 } 132 return err 133 } 134 135 return nil 136 } 137 138 // ContextValidate validate this endpoint policy based on the context it is used 139 func (m *EndpointPolicy) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 140 var res []error 141 142 if err := m.contextValidateCidrPolicy(ctx, formats); err != nil { 143 res = append(res, err) 144 } 145 146 if err := m.contextValidateL4(ctx, formats); err != nil { 147 res = append(res, err) 148 } 149 150 if err := m.contextValidatePolicyEnabled(ctx, formats); err != nil { 151 res = append(res, err) 152 } 153 154 if len(res) > 0 { 155 return errors.CompositeValidationError(res...) 156 } 157 return nil 158 } 159 160 func (m *EndpointPolicy) contextValidateCidrPolicy(ctx context.Context, formats strfmt.Registry) error { 161 162 if m.CidrPolicy != nil { 163 164 if swag.IsZero(m.CidrPolicy) { // not required 165 return nil 166 } 167 168 if err := m.CidrPolicy.ContextValidate(ctx, formats); err != nil { 169 if ve, ok := err.(*errors.Validation); ok { 170 return ve.ValidateName("cidr-policy") 171 } else if ce, ok := err.(*errors.CompositeError); ok { 172 return ce.ValidateName("cidr-policy") 173 } 174 return err 175 } 176 } 177 178 return nil 179 } 180 181 func (m *EndpointPolicy) contextValidateL4(ctx context.Context, formats strfmt.Registry) error { 182 183 if m.L4 != nil { 184 185 if swag.IsZero(m.L4) { // not required 186 return nil 187 } 188 189 if err := m.L4.ContextValidate(ctx, formats); err != nil { 190 if ve, ok := err.(*errors.Validation); ok { 191 return ve.ValidateName("l4") 192 } else if ce, ok := err.(*errors.CompositeError); ok { 193 return ce.ValidateName("l4") 194 } 195 return err 196 } 197 } 198 199 return nil 200 } 201 202 func (m *EndpointPolicy) contextValidatePolicyEnabled(ctx context.Context, formats strfmt.Registry) error { 203 204 if swag.IsZero(m.PolicyEnabled) { // not required 205 return nil 206 } 207 208 if err := m.PolicyEnabled.ContextValidate(ctx, formats); err != nil { 209 if ve, ok := err.(*errors.Validation); ok { 210 return ve.ValidateName("policy-enabled") 211 } else if ce, ok := err.(*errors.CompositeError); ok { 212 return ce.ValidateName("policy-enabled") 213 } 214 return err 215 } 216 217 return nil 218 } 219 220 // MarshalBinary interface implementation 221 func (m *EndpointPolicy) MarshalBinary() ([]byte, error) { 222 if m == nil { 223 return nil, nil 224 } 225 return swag.WriteJSON(m) 226 } 227 228 // UnmarshalBinary interface implementation 229 func (m *EndpointPolicy) UnmarshalBinary(b []byte) error { 230 var res EndpointPolicy 231 if err := swag.ReadJSON(b, &res); err != nil { 232 return err 233 } 234 *m = res 235 return nil 236 }