github.com/cilium/cilium@v1.16.2/api/v1/server/restapi/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  	"io"
    13  	"net/http"
    14  
    15  	"github.com/go-openapi/errors"
    16  	"github.com/go-openapi/runtime"
    17  	"github.com/go-openapi/runtime/middleware"
    18  	"github.com/go-openapi/strfmt"
    19  	"github.com/go-openapi/swag"
    20  )
    21  
    22  // NewPutPolicyParams creates a new PutPolicyParams object
    23  //
    24  // There are no default values defined in the spec.
    25  func NewPutPolicyParams() PutPolicyParams {
    26  
    27  	return PutPolicyParams{}
    28  }
    29  
    30  // PutPolicyParams contains all the bound params for the put policy operation
    31  // typically these are obtained from a http.Request
    32  //
    33  // swagger:parameters PutPolicy
    34  type PutPolicyParams struct {
    35  
    36  	// HTTP Request Object
    37  	HTTPRequest *http.Request `json:"-"`
    38  
    39  	/*Policy rules
    40  	  Required: true
    41  	  In: body
    42  	*/
    43  	Policy string
    44  	/*If true, indicates that existing rules with identical labels should be replaced.
    45  	  In: query
    46  	*/
    47  	Replace *bool
    48  	/*If present, indicates that existing rules with the given labels should be deleted.
    49  	  In: query
    50  	*/
    51  	ReplaceWithLabels []string
    52  }
    53  
    54  // BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface
    55  // for simple values it will use straight method calls.
    56  //
    57  // To ensure default values, the struct must have been initialized with NewPutPolicyParams() beforehand.
    58  func (o *PutPolicyParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {
    59  	var res []error
    60  
    61  	o.HTTPRequest = r
    62  
    63  	qs := runtime.Values(r.URL.Query())
    64  
    65  	if runtime.HasBody(r) {
    66  		defer r.Body.Close()
    67  		var body string
    68  		if err := route.Consumer.Consume(r.Body, &body); err != nil {
    69  			if err == io.EOF {
    70  				res = append(res, errors.Required("policy", "body", ""))
    71  			} else {
    72  				res = append(res, errors.NewParseError("policy", "body", "", err))
    73  			}
    74  		} else {
    75  			// no validation required on inline body
    76  			o.Policy = body
    77  		}
    78  	} else {
    79  		res = append(res, errors.Required("policy", "body", ""))
    80  	}
    81  
    82  	qReplace, qhkReplace, _ := qs.GetOK("replace")
    83  	if err := o.bindReplace(qReplace, qhkReplace, route.Formats); err != nil {
    84  		res = append(res, err)
    85  	}
    86  
    87  	qReplaceWithLabels, qhkReplaceWithLabels, _ := qs.GetOK("replace-with-labels")
    88  	if err := o.bindReplaceWithLabels(qReplaceWithLabels, qhkReplaceWithLabels, route.Formats); err != nil {
    89  		res = append(res, err)
    90  	}
    91  	if len(res) > 0 {
    92  		return errors.CompositeValidationError(res...)
    93  	}
    94  	return nil
    95  }
    96  
    97  // bindReplace binds and validates parameter Replace from query.
    98  func (o *PutPolicyParams) bindReplace(rawData []string, hasKey bool, formats strfmt.Registry) error {
    99  	var raw string
   100  	if len(rawData) > 0 {
   101  		raw = rawData[len(rawData)-1]
   102  	}
   103  
   104  	// Required: false
   105  	// AllowEmptyValue: false
   106  
   107  	if raw == "" { // empty values pass all other validations
   108  		return nil
   109  	}
   110  
   111  	value, err := swag.ConvertBool(raw)
   112  	if err != nil {
   113  		return errors.InvalidType("replace", "query", "bool", raw)
   114  	}
   115  	o.Replace = &value
   116  
   117  	return nil
   118  }
   119  
   120  // bindReplaceWithLabels binds and validates array parameter ReplaceWithLabels from query.
   121  //
   122  // Arrays are parsed according to CollectionFormat: "" (defaults to "csv" when empty).
   123  func (o *PutPolicyParams) bindReplaceWithLabels(rawData []string, hasKey bool, formats strfmt.Registry) error {
   124  	var qvReplaceWithLabels string
   125  	if len(rawData) > 0 {
   126  		qvReplaceWithLabels = rawData[len(rawData)-1]
   127  	}
   128  
   129  	// CollectionFormat:
   130  	replaceWithLabelsIC := swag.SplitByFormat(qvReplaceWithLabels, "")
   131  	if len(replaceWithLabelsIC) == 0 {
   132  		return nil
   133  	}
   134  
   135  	var replaceWithLabelsIR []string
   136  	for _, replaceWithLabelsIV := range replaceWithLabelsIC {
   137  		replaceWithLabelsI := replaceWithLabelsIV
   138  
   139  		replaceWithLabelsIR = append(replaceWithLabelsIR, replaceWithLabelsI)
   140  	}
   141  
   142  	o.ReplaceWithLabels = replaceWithLabelsIR
   143  
   144  	return nil
   145  }