github.com/cilium/cilium@v1.16.2/api/v1/models/c_id_r_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 "strconv" 14 15 "github.com/go-openapi/errors" 16 "github.com/go-openapi/strfmt" 17 "github.com/go-openapi/swag" 18 ) 19 20 // CIDRPolicy CIDR endpoint policy 21 // 22 // +k8s:deepcopy-gen=true 23 // 24 // swagger:model CIDRPolicy 25 type CIDRPolicy struct { 26 27 // List of CIDR egress rules 28 Egress []*PolicyRule `json:"egress"` 29 30 // List of CIDR ingress rules 31 Ingress []*PolicyRule `json:"ingress"` 32 } 33 34 // Validate validates this c ID r policy 35 func (m *CIDRPolicy) Validate(formats strfmt.Registry) error { 36 var res []error 37 38 if err := m.validateEgress(formats); err != nil { 39 res = append(res, err) 40 } 41 42 if err := m.validateIngress(formats); err != nil { 43 res = append(res, err) 44 } 45 46 if len(res) > 0 { 47 return errors.CompositeValidationError(res...) 48 } 49 return nil 50 } 51 52 func (m *CIDRPolicy) validateEgress(formats strfmt.Registry) error { 53 if swag.IsZero(m.Egress) { // not required 54 return nil 55 } 56 57 for i := 0; i < len(m.Egress); i++ { 58 if swag.IsZero(m.Egress[i]) { // not required 59 continue 60 } 61 62 if m.Egress[i] != nil { 63 if err := m.Egress[i].Validate(formats); err != nil { 64 if ve, ok := err.(*errors.Validation); ok { 65 return ve.ValidateName("egress" + "." + strconv.Itoa(i)) 66 } else if ce, ok := err.(*errors.CompositeError); ok { 67 return ce.ValidateName("egress" + "." + strconv.Itoa(i)) 68 } 69 return err 70 } 71 } 72 73 } 74 75 return nil 76 } 77 78 func (m *CIDRPolicy) validateIngress(formats strfmt.Registry) error { 79 if swag.IsZero(m.Ingress) { // not required 80 return nil 81 } 82 83 for i := 0; i < len(m.Ingress); i++ { 84 if swag.IsZero(m.Ingress[i]) { // not required 85 continue 86 } 87 88 if m.Ingress[i] != nil { 89 if err := m.Ingress[i].Validate(formats); err != nil { 90 if ve, ok := err.(*errors.Validation); ok { 91 return ve.ValidateName("ingress" + "." + strconv.Itoa(i)) 92 } else if ce, ok := err.(*errors.CompositeError); ok { 93 return ce.ValidateName("ingress" + "." + strconv.Itoa(i)) 94 } 95 return err 96 } 97 } 98 99 } 100 101 return nil 102 } 103 104 // ContextValidate validate this c ID r policy based on the context it is used 105 func (m *CIDRPolicy) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 106 var res []error 107 108 if err := m.contextValidateEgress(ctx, formats); err != nil { 109 res = append(res, err) 110 } 111 112 if err := m.contextValidateIngress(ctx, formats); err != nil { 113 res = append(res, err) 114 } 115 116 if len(res) > 0 { 117 return errors.CompositeValidationError(res...) 118 } 119 return nil 120 } 121 122 func (m *CIDRPolicy) contextValidateEgress(ctx context.Context, formats strfmt.Registry) error { 123 124 for i := 0; i < len(m.Egress); i++ { 125 126 if m.Egress[i] != nil { 127 128 if swag.IsZero(m.Egress[i]) { // not required 129 return nil 130 } 131 132 if err := m.Egress[i].ContextValidate(ctx, formats); err != nil { 133 if ve, ok := err.(*errors.Validation); ok { 134 return ve.ValidateName("egress" + "." + strconv.Itoa(i)) 135 } else if ce, ok := err.(*errors.CompositeError); ok { 136 return ce.ValidateName("egress" + "." + strconv.Itoa(i)) 137 } 138 return err 139 } 140 } 141 142 } 143 144 return nil 145 } 146 147 func (m *CIDRPolicy) contextValidateIngress(ctx context.Context, formats strfmt.Registry) error { 148 149 for i := 0; i < len(m.Ingress); i++ { 150 151 if m.Ingress[i] != nil { 152 153 if swag.IsZero(m.Ingress[i]) { // not required 154 return nil 155 } 156 157 if err := m.Ingress[i].ContextValidate(ctx, formats); err != nil { 158 if ve, ok := err.(*errors.Validation); ok { 159 return ve.ValidateName("ingress" + "." + strconv.Itoa(i)) 160 } else if ce, ok := err.(*errors.CompositeError); ok { 161 return ce.ValidateName("ingress" + "." + strconv.Itoa(i)) 162 } 163 return err 164 } 165 } 166 167 } 168 169 return nil 170 } 171 172 // MarshalBinary interface implementation 173 func (m *CIDRPolicy) MarshalBinary() ([]byte, error) { 174 if m == nil { 175 return nil, nil 176 } 177 return swag.WriteJSON(m) 178 } 179 180 // UnmarshalBinary interface implementation 181 func (m *CIDRPolicy) UnmarshalBinary(b []byte) error { 182 var res CIDRPolicy 183 if err := swag.ReadJSON(b, &res); err != nil { 184 return err 185 } 186 *m = res 187 return nil 188 }