github.com/cilium/cilium@v1.16.2/api/v1/models/identity.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 // Identity Security identity 20 // 21 // swagger:model Identity 22 type Identity struct { 23 24 // Unique identifier 25 ID int64 `json:"id,omitempty"` 26 27 // Labels describing the identity 28 Labels Labels `json:"labels,omitempty"` 29 30 // SHA256 of labels 31 LabelsSHA256 string `json:"labelsSHA256,omitempty"` 32 } 33 34 // Validate validates this identity 35 func (m *Identity) Validate(formats strfmt.Registry) error { 36 var res []error 37 38 if err := m.validateLabels(formats); err != nil { 39 res = append(res, err) 40 } 41 42 if len(res) > 0 { 43 return errors.CompositeValidationError(res...) 44 } 45 return nil 46 } 47 48 func (m *Identity) validateLabels(formats strfmt.Registry) error { 49 if swag.IsZero(m.Labels) { // not required 50 return nil 51 } 52 53 if err := m.Labels.Validate(formats); err != nil { 54 if ve, ok := err.(*errors.Validation); ok { 55 return ve.ValidateName("labels") 56 } else if ce, ok := err.(*errors.CompositeError); ok { 57 return ce.ValidateName("labels") 58 } 59 return err 60 } 61 62 return nil 63 } 64 65 // ContextValidate validate this identity based on the context it is used 66 func (m *Identity) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 67 var res []error 68 69 if err := m.contextValidateLabels(ctx, formats); err != nil { 70 res = append(res, err) 71 } 72 73 if len(res) > 0 { 74 return errors.CompositeValidationError(res...) 75 } 76 return nil 77 } 78 79 func (m *Identity) contextValidateLabels(ctx context.Context, formats strfmt.Registry) error { 80 81 if err := m.Labels.ContextValidate(ctx, formats); err != nil { 82 if ve, ok := err.(*errors.Validation); ok { 83 return ve.ValidateName("labels") 84 } else if ce, ok := err.(*errors.CompositeError); ok { 85 return ce.ValidateName("labels") 86 } 87 return err 88 } 89 90 return nil 91 } 92 93 // MarshalBinary interface implementation 94 func (m *Identity) MarshalBinary() ([]byte, error) { 95 if m == nil { 96 return nil, nil 97 } 98 return swag.WriteJSON(m) 99 } 100 101 // UnmarshalBinary interface implementation 102 func (m *Identity) UnmarshalBinary(b []byte) error { 103 var res Identity 104 if err := swag.ReadJSON(b, &res); err != nil { 105 return err 106 } 107 *m = res 108 return nil 109 }