github.com/cilium/cilium@v1.16.2/api/v1/models/wireguard_interface.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 // WireguardInterface Status of a WireGuard interface 21 // 22 // +k8s:deepcopy-gen=true 23 // 24 // swagger:model WireguardInterface 25 type WireguardInterface struct { 26 27 // Port on which the WireGuard endpoint is exposed 28 ListenPort int64 `json:"listen-port,omitempty"` 29 30 // Name of the interface 31 Name string `json:"name,omitempty"` 32 33 // Number of peers configured on this interface 34 PeerCount int64 `json:"peer-count,omitempty"` 35 36 // Optional list of WireGuard peers 37 Peers []*WireguardPeer `json:"peers"` 38 39 // Public key of this interface 40 PublicKey string `json:"public-key,omitempty"` 41 } 42 43 // Validate validates this wireguard interface 44 func (m *WireguardInterface) Validate(formats strfmt.Registry) error { 45 var res []error 46 47 if err := m.validatePeers(formats); err != nil { 48 res = append(res, err) 49 } 50 51 if len(res) > 0 { 52 return errors.CompositeValidationError(res...) 53 } 54 return nil 55 } 56 57 func (m *WireguardInterface) validatePeers(formats strfmt.Registry) error { 58 if swag.IsZero(m.Peers) { // not required 59 return nil 60 } 61 62 for i := 0; i < len(m.Peers); i++ { 63 if swag.IsZero(m.Peers[i]) { // not required 64 continue 65 } 66 67 if m.Peers[i] != nil { 68 if err := m.Peers[i].Validate(formats); err != nil { 69 if ve, ok := err.(*errors.Validation); ok { 70 return ve.ValidateName("peers" + "." + strconv.Itoa(i)) 71 } else if ce, ok := err.(*errors.CompositeError); ok { 72 return ce.ValidateName("peers" + "." + strconv.Itoa(i)) 73 } 74 return err 75 } 76 } 77 78 } 79 80 return nil 81 } 82 83 // ContextValidate validate this wireguard interface based on the context it is used 84 func (m *WireguardInterface) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 85 var res []error 86 87 if err := m.contextValidatePeers(ctx, formats); err != nil { 88 res = append(res, err) 89 } 90 91 if len(res) > 0 { 92 return errors.CompositeValidationError(res...) 93 } 94 return nil 95 } 96 97 func (m *WireguardInterface) contextValidatePeers(ctx context.Context, formats strfmt.Registry) error { 98 99 for i := 0; i < len(m.Peers); i++ { 100 101 if m.Peers[i] != nil { 102 103 if swag.IsZero(m.Peers[i]) { // not required 104 return nil 105 } 106 107 if err := m.Peers[i].ContextValidate(ctx, formats); err != nil { 108 if ve, ok := err.(*errors.Validation); ok { 109 return ve.ValidateName("peers" + "." + strconv.Itoa(i)) 110 } else if ce, ok := err.(*errors.CompositeError); ok { 111 return ce.ValidateName("peers" + "." + strconv.Itoa(i)) 112 } 113 return err 114 } 115 } 116 117 } 118 119 return nil 120 } 121 122 // MarshalBinary interface implementation 123 func (m *WireguardInterface) MarshalBinary() ([]byte, error) { 124 if m == nil { 125 return nil, nil 126 } 127 return swag.WriteJSON(m) 128 } 129 130 // UnmarshalBinary interface implementation 131 func (m *WireguardInterface) UnmarshalBinary(b []byte) error { 132 var res WireguardInterface 133 if err := swag.ReadJSON(b, &res); err != nil { 134 return err 135 } 136 *m = res 137 return nil 138 }