frostfs-rest-gw/gen/restapi/operations/auth_parameters.go
Denis Kirillov 686588bc1a [#15] Accept list of tokens to sign
Signed-off-by: Denis Kirillov <denis@nspcc.ru>
2022-07-12 11:36:32 +03:00

156 lines
3.8 KiB
Go

// Code generated by go-swagger; DO NOT EDIT.
package operations
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"io"
"net/http"
"github.com/go-openapi/errors"
"github.com/go-openapi/runtime"
"github.com/go-openapi/runtime/middleware"
"github.com/go-openapi/strfmt"
"github.com/go-openapi/swag"
"github.com/go-openapi/validate"
"github.com/nspcc-dev/neofs-rest-gw/gen/models"
)
// NewAuthParams creates a new AuthParams object
// with the default values initialized.
func NewAuthParams() AuthParams {
var (
// initialize parameters with default values
xBearerLifetimeDefault = int64(100)
)
return AuthParams{
XBearerLifetime: &xBearerLifetimeDefault,
}
}
// AuthParams contains all the bound params for the auth operation
// typically these are obtained from a http.Request
//
// swagger:parameters auth
type AuthParams struct {
// HTTP Request Object
HTTPRequest *http.Request `json:"-"`
/*Token lifetime in epoch
In: header
Default: 100
*/
XBearerLifetime *int64
/*Owner Id (wallet address) that will sign the token
Required: true
In: header
*/
XBearerOwnerID string
/*Bearer token
Required: true
In: body
*/
Tokens []*models.Bearer
}
// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface
// for simple values it will use straight method calls.
//
// To ensure default values, the struct must have been initialized with NewAuthParams() beforehand.
func (o *AuthParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {
var res []error
o.HTTPRequest = r
if err := o.bindXBearerLifetime(r.Header[http.CanonicalHeaderKey("X-Bearer-Lifetime")], true, route.Formats); err != nil {
res = append(res, err)
}
if err := o.bindXBearerOwnerID(r.Header[http.CanonicalHeaderKey("X-Bearer-Owner-Id")], true, route.Formats); err != nil {
res = append(res, err)
}
if runtime.HasBody(r) {
defer r.Body.Close()
var body []*models.Bearer
if err := route.Consumer.Consume(r.Body, &body); err != nil {
if err == io.EOF {
res = append(res, errors.Required("tokens", "body", ""))
} else {
res = append(res, errors.NewParseError("tokens", "body", "", err))
}
} else {
// validate array of body objects
for i := range body {
if body[i] == nil {
continue
}
if err := body[i].Validate(route.Formats); err != nil {
res = append(res, err)
break
}
}
if len(res) == 0 {
o.Tokens = body
}
}
} else {
res = append(res, errors.Required("tokens", "body", ""))
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
// bindXBearerLifetime binds and validates parameter XBearerLifetime from header.
func (o *AuthParams) bindXBearerLifetime(rawData []string, hasKey bool, formats strfmt.Registry) error {
var raw string
if len(rawData) > 0 {
raw = rawData[len(rawData)-1]
}
// Required: false
if raw == "" { // empty values pass all other validations
// Default values have been previously initialized by NewAuthParams()
return nil
}
value, err := swag.ConvertInt64(raw)
if err != nil {
return errors.InvalidType("X-Bearer-Lifetime", "header", "int64", raw)
}
o.XBearerLifetime = &value
return nil
}
// bindXBearerOwnerID binds and validates parameter XBearerOwnerID from header.
func (o *AuthParams) bindXBearerOwnerID(rawData []string, hasKey bool, formats strfmt.Registry) error {
if !hasKey {
return errors.Required("X-Bearer-Owner-Id", "header", rawData)
}
var raw string
if len(rawData) > 0 {
raw = rawData[len(rawData)-1]
}
// Required: true
if err := validate.RequiredString("X-Bearer-Owner-Id", "header", raw); err != nil {
return err
}
o.XBearerOwnerID = raw
return nil
}