github.com/cilium/cilium@v1.16.2/api/v1/models/daemon_configuration_spec.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 "encoding/json" 14 15 "github.com/go-openapi/errors" 16 "github.com/go-openapi/strfmt" 17 "github.com/go-openapi/swag" 18 "github.com/go-openapi/validate" 19 ) 20 21 // DaemonConfigurationSpec The controllable configuration of the daemon. 22 // 23 // swagger:model DaemonConfigurationSpec 24 type DaemonConfigurationSpec struct { 25 26 // Changeable configuration 27 Options ConfigurationMap `json:"options,omitempty"` 28 29 // The policy-enforcement mode 30 // Enum: [default always never] 31 PolicyEnforcement string `json:"policy-enforcement,omitempty"` 32 } 33 34 // Validate validates this daemon configuration spec 35 func (m *DaemonConfigurationSpec) Validate(formats strfmt.Registry) error { 36 var res []error 37 38 if err := m.validateOptions(formats); err != nil { 39 res = append(res, err) 40 } 41 42 if err := m.validatePolicyEnforcement(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 *DaemonConfigurationSpec) validateOptions(formats strfmt.Registry) error { 53 if swag.IsZero(m.Options) { // not required 54 return nil 55 } 56 57 if m.Options != nil { 58 if err := m.Options.Validate(formats); err != nil { 59 if ve, ok := err.(*errors.Validation); ok { 60 return ve.ValidateName("options") 61 } else if ce, ok := err.(*errors.CompositeError); ok { 62 return ce.ValidateName("options") 63 } 64 return err 65 } 66 } 67 68 return nil 69 } 70 71 var daemonConfigurationSpecTypePolicyEnforcementPropEnum []interface{} 72 73 func init() { 74 var res []string 75 if err := json.Unmarshal([]byte(`["default","always","never"]`), &res); err != nil { 76 panic(err) 77 } 78 for _, v := range res { 79 daemonConfigurationSpecTypePolicyEnforcementPropEnum = append(daemonConfigurationSpecTypePolicyEnforcementPropEnum, v) 80 } 81 } 82 83 const ( 84 85 // DaemonConfigurationSpecPolicyEnforcementDefault captures enum value "default" 86 DaemonConfigurationSpecPolicyEnforcementDefault string = "default" 87 88 // DaemonConfigurationSpecPolicyEnforcementAlways captures enum value "always" 89 DaemonConfigurationSpecPolicyEnforcementAlways string = "always" 90 91 // DaemonConfigurationSpecPolicyEnforcementNever captures enum value "never" 92 DaemonConfigurationSpecPolicyEnforcementNever string = "never" 93 ) 94 95 // prop value enum 96 func (m *DaemonConfigurationSpec) validatePolicyEnforcementEnum(path, location string, value string) error { 97 if err := validate.EnumCase(path, location, value, daemonConfigurationSpecTypePolicyEnforcementPropEnum, true); err != nil { 98 return err 99 } 100 return nil 101 } 102 103 func (m *DaemonConfigurationSpec) validatePolicyEnforcement(formats strfmt.Registry) error { 104 if swag.IsZero(m.PolicyEnforcement) { // not required 105 return nil 106 } 107 108 // value enum 109 if err := m.validatePolicyEnforcementEnum("policy-enforcement", "body", m.PolicyEnforcement); err != nil { 110 return err 111 } 112 113 return nil 114 } 115 116 // ContextValidate validate this daemon configuration spec based on the context it is used 117 func (m *DaemonConfigurationSpec) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 118 var res []error 119 120 if err := m.contextValidateOptions(ctx, formats); err != nil { 121 res = append(res, err) 122 } 123 124 if len(res) > 0 { 125 return errors.CompositeValidationError(res...) 126 } 127 return nil 128 } 129 130 func (m *DaemonConfigurationSpec) contextValidateOptions(ctx context.Context, formats strfmt.Registry) error { 131 132 if swag.IsZero(m.Options) { // not required 133 return nil 134 } 135 136 if err := m.Options.ContextValidate(ctx, formats); err != nil { 137 if ve, ok := err.(*errors.Validation); ok { 138 return ve.ValidateName("options") 139 } else if ce, ok := err.(*errors.CompositeError); ok { 140 return ce.ValidateName("options") 141 } 142 return err 143 } 144 145 return nil 146 } 147 148 // MarshalBinary interface implementation 149 func (m *DaemonConfigurationSpec) MarshalBinary() ([]byte, error) { 150 if m == nil { 151 return nil, nil 152 } 153 return swag.WriteJSON(m) 154 } 155 156 // UnmarshalBinary interface implementation 157 func (m *DaemonConfigurationSpec) UnmarshalBinary(b []byte) error { 158 var res DaemonConfigurationSpec 159 if err := swag.ReadJSON(b, &res); err != nil { 160 return err 161 } 162 *m = res 163 return nil 164 }