forked from TrueCloudLab/frostfs-rest-gw
e68cda7f9c
Signed-off-by: Denis Kirillov <denis@nspcc.ru>
191 lines
4.8 KiB
Go
191 lines
4.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
|
|
|
|
xBearerForAllUsersDefault = bool(false)
|
|
xBearerLifetimeDefault = int64(100)
|
|
)
|
|
|
|
return AuthParams{
|
|
XBearerForAllUsers: &xBearerForAllUsersDefault,
|
|
|
|
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:"-"`
|
|
|
|
/*Form token for all users or only for this gate.
|
|
In: header
|
|
Default: false
|
|
*/
|
|
XBearerForAllUsers *bool
|
|
/*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 tokens to form.
|
|
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.bindXBearerForAllUsers(r.Header[http.CanonicalHeaderKey("X-Bearer-For-All-Users")], true, route.Formats); err != nil {
|
|
res = append(res, err)
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
// bindXBearerForAllUsers binds and validates parameter XBearerForAllUsers from header.
|
|
func (o *AuthParams) bindXBearerForAllUsers(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.ConvertBool(raw)
|
|
if err != nil {
|
|
return errors.InvalidType("X-Bearer-For-All-Users", "header", "bool", raw)
|
|
}
|
|
o.XBearerForAllUsers = &value
|
|
|
|
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
|
|
}
|