github.com/cilium/cilium@v1.16.2/api/v1/client/policy/put_policy_parameters.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 policy 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 "net/http" 14 "time" 15 16 "github.com/go-openapi/errors" 17 "github.com/go-openapi/runtime" 18 cr "github.com/go-openapi/runtime/client" 19 "github.com/go-openapi/strfmt" 20 "github.com/go-openapi/swag" 21 ) 22 23 // NewPutPolicyParams creates a new PutPolicyParams object, 24 // with the default timeout for this client. 25 // 26 // Default values are not hydrated, since defaults are normally applied by the API server side. 27 // 28 // To enforce default values in parameter, use SetDefaults or WithDefaults. 29 func NewPutPolicyParams() *PutPolicyParams { 30 return &PutPolicyParams{ 31 timeout: cr.DefaultTimeout, 32 } 33 } 34 35 // NewPutPolicyParamsWithTimeout creates a new PutPolicyParams object 36 // with the ability to set a timeout on a request. 37 func NewPutPolicyParamsWithTimeout(timeout time.Duration) *PutPolicyParams { 38 return &PutPolicyParams{ 39 timeout: timeout, 40 } 41 } 42 43 // NewPutPolicyParamsWithContext creates a new PutPolicyParams object 44 // with the ability to set a context for a request. 45 func NewPutPolicyParamsWithContext(ctx context.Context) *PutPolicyParams { 46 return &PutPolicyParams{ 47 Context: ctx, 48 } 49 } 50 51 // NewPutPolicyParamsWithHTTPClient creates a new PutPolicyParams object 52 // with the ability to set a custom HTTPClient for a request. 53 func NewPutPolicyParamsWithHTTPClient(client *http.Client) *PutPolicyParams { 54 return &PutPolicyParams{ 55 HTTPClient: client, 56 } 57 } 58 59 /* 60 PutPolicyParams contains all the parameters to send to the API endpoint 61 62 for the put policy operation. 63 64 Typically these are written to a http.Request. 65 */ 66 type PutPolicyParams struct { 67 68 /* Policy. 69 70 Policy rules 71 */ 72 Policy string 73 74 /* Replace. 75 76 If true, indicates that existing rules with identical labels should be replaced. 77 */ 78 Replace *bool 79 80 /* ReplaceWithLabels. 81 82 If present, indicates that existing rules with the given labels should be deleted. 83 */ 84 ReplaceWithLabels []string 85 86 timeout time.Duration 87 Context context.Context 88 HTTPClient *http.Client 89 } 90 91 // WithDefaults hydrates default values in the put policy params (not the query body). 92 // 93 // All values with no default are reset to their zero value. 94 func (o *PutPolicyParams) WithDefaults() *PutPolicyParams { 95 o.SetDefaults() 96 return o 97 } 98 99 // SetDefaults hydrates default values in the put policy params (not the query body). 100 // 101 // All values with no default are reset to their zero value. 102 func (o *PutPolicyParams) SetDefaults() { 103 // no default values defined for this parameter 104 } 105 106 // WithTimeout adds the timeout to the put policy params 107 func (o *PutPolicyParams) WithTimeout(timeout time.Duration) *PutPolicyParams { 108 o.SetTimeout(timeout) 109 return o 110 } 111 112 // SetTimeout adds the timeout to the put policy params 113 func (o *PutPolicyParams) SetTimeout(timeout time.Duration) { 114 o.timeout = timeout 115 } 116 117 // WithContext adds the context to the put policy params 118 func (o *PutPolicyParams) WithContext(ctx context.Context) *PutPolicyParams { 119 o.SetContext(ctx) 120 return o 121 } 122 123 // SetContext adds the context to the put policy params 124 func (o *PutPolicyParams) SetContext(ctx context.Context) { 125 o.Context = ctx 126 } 127 128 // WithHTTPClient adds the HTTPClient to the put policy params 129 func (o *PutPolicyParams) WithHTTPClient(client *http.Client) *PutPolicyParams { 130 o.SetHTTPClient(client) 131 return o 132 } 133 134 // SetHTTPClient adds the HTTPClient to the put policy params 135 func (o *PutPolicyParams) SetHTTPClient(client *http.Client) { 136 o.HTTPClient = client 137 } 138 139 // WithPolicy adds the policy to the put policy params 140 func (o *PutPolicyParams) WithPolicy(policy string) *PutPolicyParams { 141 o.SetPolicy(policy) 142 return o 143 } 144 145 // SetPolicy adds the policy to the put policy params 146 func (o *PutPolicyParams) SetPolicy(policy string) { 147 o.Policy = policy 148 } 149 150 // WithReplace adds the replace to the put policy params 151 func (o *PutPolicyParams) WithReplace(replace *bool) *PutPolicyParams { 152 o.SetReplace(replace) 153 return o 154 } 155 156 // SetReplace adds the replace to the put policy params 157 func (o *PutPolicyParams) SetReplace(replace *bool) { 158 o.Replace = replace 159 } 160 161 // WithReplaceWithLabels adds the replaceWithLabels to the put policy params 162 func (o *PutPolicyParams) WithReplaceWithLabels(replaceWithLabels []string) *PutPolicyParams { 163 o.SetReplaceWithLabels(replaceWithLabels) 164 return o 165 } 166 167 // SetReplaceWithLabels adds the replaceWithLabels to the put policy params 168 func (o *PutPolicyParams) SetReplaceWithLabels(replaceWithLabels []string) { 169 o.ReplaceWithLabels = replaceWithLabels 170 } 171 172 // WriteToRequest writes these params to a swagger request 173 func (o *PutPolicyParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { 174 175 if err := r.SetTimeout(o.timeout); err != nil { 176 return err 177 } 178 var res []error 179 if err := r.SetBodyParam(o.Policy); err != nil { 180 return err 181 } 182 183 if o.Replace != nil { 184 185 // query param replace 186 var qrReplace bool 187 188 if o.Replace != nil { 189 qrReplace = *o.Replace 190 } 191 qReplace := swag.FormatBool(qrReplace) 192 if qReplace != "" { 193 194 if err := r.SetQueryParam("replace", qReplace); err != nil { 195 return err 196 } 197 } 198 } 199 200 if o.ReplaceWithLabels != nil { 201 202 // binding items for replace-with-labels 203 joinedReplaceWithLabels := o.bindParamReplaceWithLabels(reg) 204 205 // query array param replace-with-labels 206 if err := r.SetQueryParam("replace-with-labels", joinedReplaceWithLabels...); err != nil { 207 return err 208 } 209 } 210 211 if len(res) > 0 { 212 return errors.CompositeValidationError(res...) 213 } 214 return nil 215 } 216 217 // bindParamPutPolicy binds the parameter replace-with-labels 218 func (o *PutPolicyParams) bindParamReplaceWithLabels(formats strfmt.Registry) []string { 219 replaceWithLabelsIR := o.ReplaceWithLabels 220 221 var replaceWithLabelsIC []string 222 for _, replaceWithLabelsIIR := range replaceWithLabelsIR { // explode []string 223 224 replaceWithLabelsIIV := replaceWithLabelsIIR // string as string 225 replaceWithLabelsIC = append(replaceWithLabelsIC, replaceWithLabelsIIV) 226 } 227 228 // items.CollectionFormat: "" 229 replaceWithLabelsIS := swag.JoinByFormat(replaceWithLabelsIC, "") 230 231 return replaceWithLabelsIS 232 }