forked from TrueCloudLab/frostfs-rest-gw
[#1] Add route to list containers
Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
parent
d1cb88672c
commit
26f0ae93f4
12 changed files with 913 additions and 30 deletions
|
@ -94,10 +94,60 @@ func init() {
|
|||
}
|
||||
},
|
||||
"/containers": {
|
||||
"get": {
|
||||
"security": [],
|
||||
"summary": "Get list of containers",
|
||||
"operationId": "listContainers",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Base58 encoded owner id",
|
||||
"name": "ownerId",
|
||||
"in": "query",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"default": 0,
|
||||
"description": "The number of containers to skip before starting to collect the result set.",
|
||||
"name": "offset",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"maximum": 10000,
|
||||
"minimum": 1,
|
||||
"type": "integer",
|
||||
"default": 100,
|
||||
"description": "The numbers of containers to return.",
|
||||
"name": "limit",
|
||||
"in": "query"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Containers info",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/ContainerList"
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Bad request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"put": {
|
||||
"summary": "Create new container in NeoFS",
|
||||
"operationId": "putContainer",
|
||||
"parameters": [
|
||||
{
|
||||
"$ref": "#/parameters/signatureParam"
|
||||
},
|
||||
{
|
||||
"$ref": "#/parameters/signatureKeyParam"
|
||||
},
|
||||
{
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
|
@ -159,15 +209,7 @@ func init() {
|
|||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"parameters": [
|
||||
{
|
||||
"$ref": "#/parameters/signatureParam"
|
||||
},
|
||||
{
|
||||
"$ref": "#/parameters/signatureKeyParam"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"/containers/{containerId}": {
|
||||
"get": {
|
||||
|
@ -433,6 +475,20 @@ func init() {
|
|||
}
|
||||
}
|
||||
},
|
||||
"ContainerBaseInfo": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"containerId"
|
||||
],
|
||||
"properties": {
|
||||
"containerId": {
|
||||
"type": "string"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"ContainerInfo": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
|
@ -484,6 +540,24 @@ func init() {
|
|||
"version": "2.11"
|
||||
}
|
||||
},
|
||||
"ContainerList": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"size",
|
||||
"containers"
|
||||
],
|
||||
"properties": {
|
||||
"containers": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/ContainerBaseInfo"
|
||||
}
|
||||
},
|
||||
"size": {
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
},
|
||||
"Eacl": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
|
@ -853,10 +927,69 @@ func init() {
|
|||
}
|
||||
},
|
||||
"/containers": {
|
||||
"get": {
|
||||
"security": [],
|
||||
"summary": "Get list of containers",
|
||||
"operationId": "listContainers",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Base58 encoded owner id",
|
||||
"name": "ownerId",
|
||||
"in": "query",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"minimum": 0,
|
||||
"type": "integer",
|
||||
"default": 0,
|
||||
"description": "The number of containers to skip before starting to collect the result set.",
|
||||
"name": "offset",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"maximum": 10000,
|
||||
"minimum": 1,
|
||||
"type": "integer",
|
||||
"default": 100,
|
||||
"description": "The numbers of containers to return.",
|
||||
"name": "limit",
|
||||
"in": "query"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Containers info",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/ContainerList"
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Bad request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"put": {
|
||||
"summary": "Create new container in NeoFS",
|
||||
"operationId": "putContainer",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Base64 encoded signature for bearer token",
|
||||
"name": "X-Neofs-Token-Signature",
|
||||
"in": "header",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Hex encoded the public part of the key that signed the bearer token",
|
||||
"name": "X-Neofs-Token-Signature-Key",
|
||||
"in": "header",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
|
@ -918,23 +1051,7 @@ func init() {
|
|||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Base64 encoded signature for bearer token",
|
||||
"name": "X-Neofs-Token-Signature",
|
||||
"in": "header",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Hex encoded the public part of the key that signed the bearer token",
|
||||
"name": "X-Neofs-Token-Signature-Key",
|
||||
"in": "header",
|
||||
"required": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"/containers/{containerId}": {
|
||||
"get": {
|
||||
|
@ -1244,6 +1361,20 @@ func init() {
|
|||
}
|
||||
}
|
||||
},
|
||||
"ContainerBaseInfo": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"containerId"
|
||||
],
|
||||
"properties": {
|
||||
"containerId": {
|
||||
"type": "string"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"ContainerInfo": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
|
@ -1295,6 +1426,24 @@ func init() {
|
|||
"version": "2.11"
|
||||
}
|
||||
},
|
||||
"ContainerList": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"size",
|
||||
"containers"
|
||||
],
|
||||
"properties": {
|
||||
"containers": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/ContainerBaseInfo"
|
||||
}
|
||||
},
|
||||
"size": {
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
},
|
||||
"Eacl": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
|
|
56
gen/restapi/operations/list_containers.go
Normal file
56
gen/restapi/operations/list_containers.go
Normal file
|
@ -0,0 +1,56 @@
|
|||
// 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 generate command
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/go-openapi/runtime/middleware"
|
||||
)
|
||||
|
||||
// ListContainersHandlerFunc turns a function with the right signature into a list containers handler
|
||||
type ListContainersHandlerFunc func(ListContainersParams) middleware.Responder
|
||||
|
||||
// Handle executing the request and returning a response
|
||||
func (fn ListContainersHandlerFunc) Handle(params ListContainersParams) middleware.Responder {
|
||||
return fn(params)
|
||||
}
|
||||
|
||||
// ListContainersHandler interface for that can handle valid list containers params
|
||||
type ListContainersHandler interface {
|
||||
Handle(ListContainersParams) middleware.Responder
|
||||
}
|
||||
|
||||
// NewListContainers creates a new http.Handler for the list containers operation
|
||||
func NewListContainers(ctx *middleware.Context, handler ListContainersHandler) *ListContainers {
|
||||
return &ListContainers{Context: ctx, Handler: handler}
|
||||
}
|
||||
|
||||
/* ListContainers swagger:route GET /containers listContainers
|
||||
|
||||
Get list of containers
|
||||
|
||||
*/
|
||||
type ListContainers struct {
|
||||
Context *middleware.Context
|
||||
Handler ListContainersHandler
|
||||
}
|
||||
|
||||
func (o *ListContainers) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
|
||||
route, rCtx, _ := o.Context.RouteInfo(r)
|
||||
if rCtx != nil {
|
||||
*r = *rCtx
|
||||
}
|
||||
var Params = NewListContainersParams()
|
||||
if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params
|
||||
o.Context.Respond(rw, r, route.Produces, route, err)
|
||||
return
|
||||
}
|
||||
|
||||
res := o.Handler.Handle(Params) // actually handle the request
|
||||
o.Context.Respond(rw, r, route.Produces, route, res)
|
||||
|
||||
}
|
196
gen/restapi/operations/list_containers_parameters.go
Normal file
196
gen/restapi/operations/list_containers_parameters.go
Normal file
|
@ -0,0 +1,196 @@
|
|||
// 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 (
|
||||
"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"
|
||||
)
|
||||
|
||||
// NewListContainersParams creates a new ListContainersParams object
|
||||
// with the default values initialized.
|
||||
func NewListContainersParams() ListContainersParams {
|
||||
|
||||
var (
|
||||
// initialize parameters with default values
|
||||
|
||||
limitDefault = int64(100)
|
||||
offsetDefault = int64(0)
|
||||
)
|
||||
|
||||
return ListContainersParams{
|
||||
Limit: &limitDefault,
|
||||
|
||||
Offset: &offsetDefault,
|
||||
}
|
||||
}
|
||||
|
||||
// ListContainersParams contains all the bound params for the list containers operation
|
||||
// typically these are obtained from a http.Request
|
||||
//
|
||||
// swagger:parameters listContainers
|
||||
type ListContainersParams struct {
|
||||
|
||||
// HTTP Request Object
|
||||
HTTPRequest *http.Request `json:"-"`
|
||||
|
||||
/*The numbers of containers to return.
|
||||
Maximum: 10000
|
||||
Minimum: 1
|
||||
In: query
|
||||
Default: 100
|
||||
*/
|
||||
Limit *int64
|
||||
/*The number of containers to skip before starting to collect the result set.
|
||||
Minimum: 0
|
||||
In: query
|
||||
Default: 0
|
||||
*/
|
||||
Offset *int64
|
||||
/*Base58 encoded owner id
|
||||
Required: true
|
||||
In: query
|
||||
*/
|
||||
OwnerID string
|
||||
}
|
||||
|
||||
// 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 NewListContainersParams() beforehand.
|
||||
func (o *ListContainersParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {
|
||||
var res []error
|
||||
|
||||
o.HTTPRequest = r
|
||||
|
||||
qs := runtime.Values(r.URL.Query())
|
||||
|
||||
qLimit, qhkLimit, _ := qs.GetOK("limit")
|
||||
if err := o.bindLimit(qLimit, qhkLimit, route.Formats); err != nil {
|
||||
res = append(res, err)
|
||||
}
|
||||
|
||||
qOffset, qhkOffset, _ := qs.GetOK("offset")
|
||||
if err := o.bindOffset(qOffset, qhkOffset, route.Formats); err != nil {
|
||||
res = append(res, err)
|
||||
}
|
||||
|
||||
qOwnerID, qhkOwnerID, _ := qs.GetOK("ownerId")
|
||||
if err := o.bindOwnerID(qOwnerID, qhkOwnerID, route.Formats); err != nil {
|
||||
res = append(res, err)
|
||||
}
|
||||
if len(res) > 0 {
|
||||
return errors.CompositeValidationError(res...)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// bindLimit binds and validates parameter Limit from query.
|
||||
func (o *ListContainersParams) bindLimit(rawData []string, hasKey bool, formats strfmt.Registry) error {
|
||||
var raw string
|
||||
if len(rawData) > 0 {
|
||||
raw = rawData[len(rawData)-1]
|
||||
}
|
||||
|
||||
// Required: false
|
||||
// AllowEmptyValue: false
|
||||
|
||||
if raw == "" { // empty values pass all other validations
|
||||
// Default values have been previously initialized by NewListContainersParams()
|
||||
return nil
|
||||
}
|
||||
|
||||
value, err := swag.ConvertInt64(raw)
|
||||
if err != nil {
|
||||
return errors.InvalidType("limit", "query", "int64", raw)
|
||||
}
|
||||
o.Limit = &value
|
||||
|
||||
if err := o.validateLimit(formats); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// validateLimit carries on validations for parameter Limit
|
||||
func (o *ListContainersParams) validateLimit(formats strfmt.Registry) error {
|
||||
|
||||
if err := validate.MinimumInt("limit", "query", *o.Limit, 1, false); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := validate.MaximumInt("limit", "query", *o.Limit, 10000, false); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// bindOffset binds and validates parameter Offset from query.
|
||||
func (o *ListContainersParams) bindOffset(rawData []string, hasKey bool, formats strfmt.Registry) error {
|
||||
var raw string
|
||||
if len(rawData) > 0 {
|
||||
raw = rawData[len(rawData)-1]
|
||||
}
|
||||
|
||||
// Required: false
|
||||
// AllowEmptyValue: false
|
||||
|
||||
if raw == "" { // empty values pass all other validations
|
||||
// Default values have been previously initialized by NewListContainersParams()
|
||||
return nil
|
||||
}
|
||||
|
||||
value, err := swag.ConvertInt64(raw)
|
||||
if err != nil {
|
||||
return errors.InvalidType("offset", "query", "int64", raw)
|
||||
}
|
||||
o.Offset = &value
|
||||
|
||||
if err := o.validateOffset(formats); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// validateOffset carries on validations for parameter Offset
|
||||
func (o *ListContainersParams) validateOffset(formats strfmt.Registry) error {
|
||||
|
||||
if err := validate.MinimumInt("offset", "query", *o.Offset, 0, false); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// bindOwnerID binds and validates parameter OwnerID from query.
|
||||
func (o *ListContainersParams) bindOwnerID(rawData []string, hasKey bool, formats strfmt.Registry) error {
|
||||
if !hasKey {
|
||||
return errors.Required("ownerId", "query", rawData)
|
||||
}
|
||||
var raw string
|
||||
if len(rawData) > 0 {
|
||||
raw = rawData[len(rawData)-1]
|
||||
}
|
||||
|
||||
// Required: true
|
||||
// AllowEmptyValue: false
|
||||
|
||||
if err := validate.RequiredString("ownerId", "query", raw); err != nil {
|
||||
return err
|
||||
}
|
||||
o.OwnerID = raw
|
||||
|
||||
return nil
|
||||
}
|
100
gen/restapi/operations/list_containers_responses.go
Normal file
100
gen/restapi/operations/list_containers_responses.go
Normal file
|
@ -0,0 +1,100 @@
|
|||
// 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 (
|
||||
"net/http"
|
||||
|
||||
"github.com/go-openapi/runtime"
|
||||
|
||||
"github.com/nspcc-dev/neofs-rest-gw/gen/models"
|
||||
)
|
||||
|
||||
// ListContainersOKCode is the HTTP code returned for type ListContainersOK
|
||||
const ListContainersOKCode int = 200
|
||||
|
||||
/*ListContainersOK Containers info
|
||||
|
||||
swagger:response listContainersOK
|
||||
*/
|
||||
type ListContainersOK struct {
|
||||
|
||||
/*
|
||||
In: Body
|
||||
*/
|
||||
Payload *models.ContainerList `json:"body,omitempty"`
|
||||
}
|
||||
|
||||
// NewListContainersOK creates ListContainersOK with default headers values
|
||||
func NewListContainersOK() *ListContainersOK {
|
||||
|
||||
return &ListContainersOK{}
|
||||
}
|
||||
|
||||
// WithPayload adds the payload to the list containers o k response
|
||||
func (o *ListContainersOK) WithPayload(payload *models.ContainerList) *ListContainersOK {
|
||||
o.Payload = payload
|
||||
return o
|
||||
}
|
||||
|
||||
// SetPayload sets the payload to the list containers o k response
|
||||
func (o *ListContainersOK) SetPayload(payload *models.ContainerList) {
|
||||
o.Payload = payload
|
||||
}
|
||||
|
||||
// WriteResponse to the client
|
||||
func (o *ListContainersOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
|
||||
|
||||
rw.WriteHeader(200)
|
||||
if o.Payload != nil {
|
||||
payload := o.Payload
|
||||
if err := producer.Produce(rw, payload); err != nil {
|
||||
panic(err) // let the recovery middleware deal with this
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ListContainersBadRequestCode is the HTTP code returned for type ListContainersBadRequest
|
||||
const ListContainersBadRequestCode int = 400
|
||||
|
||||
/*ListContainersBadRequest Bad request
|
||||
|
||||
swagger:response listContainersBadRequest
|
||||
*/
|
||||
type ListContainersBadRequest struct {
|
||||
|
||||
/*
|
||||
In: Body
|
||||
*/
|
||||
Payload models.Error `json:"body,omitempty"`
|
||||
}
|
||||
|
||||
// NewListContainersBadRequest creates ListContainersBadRequest with default headers values
|
||||
func NewListContainersBadRequest() *ListContainersBadRequest {
|
||||
|
||||
return &ListContainersBadRequest{}
|
||||
}
|
||||
|
||||
// WithPayload adds the payload to the list containers bad request response
|
||||
func (o *ListContainersBadRequest) WithPayload(payload models.Error) *ListContainersBadRequest {
|
||||
o.Payload = payload
|
||||
return o
|
||||
}
|
||||
|
||||
// SetPayload sets the payload to the list containers bad request response
|
||||
func (o *ListContainersBadRequest) SetPayload(payload models.Error) {
|
||||
o.Payload = payload
|
||||
}
|
||||
|
||||
// WriteResponse to the client
|
||||
func (o *ListContainersBadRequest) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
|
||||
|
||||
rw.WriteHeader(400)
|
||||
payload := o.Payload
|
||||
if err := producer.Produce(rw, payload); err != nil {
|
||||
panic(err) // let the recovery middleware deal with this
|
||||
}
|
||||
}
|
|
@ -59,6 +59,9 @@ func NewNeofsRestGwAPI(spec *loads.Document) *NeofsRestGwAPI {
|
|||
GetObjectInfoHandler: GetObjectInfoHandlerFunc(func(params GetObjectInfoParams, principal *models.Principal) middleware.Responder {
|
||||
return middleware.NotImplemented("operation GetObjectInfo has not yet been implemented")
|
||||
}),
|
||||
ListContainersHandler: ListContainersHandlerFunc(func(params ListContainersParams) middleware.Responder {
|
||||
return middleware.NotImplemented("operation ListContainers has not yet been implemented")
|
||||
}),
|
||||
PutContainerHandler: PutContainerHandlerFunc(func(params PutContainerParams, principal *models.Principal) middleware.Responder {
|
||||
return middleware.NotImplemented("operation PutContainer has not yet been implemented")
|
||||
}),
|
||||
|
@ -128,6 +131,8 @@ type NeofsRestGwAPI struct {
|
|||
GetContainerEACLHandler GetContainerEACLHandler
|
||||
// GetObjectInfoHandler sets the operation handler for the get object info operation
|
||||
GetObjectInfoHandler GetObjectInfoHandler
|
||||
// ListContainersHandler sets the operation handler for the list containers operation
|
||||
ListContainersHandler ListContainersHandler
|
||||
// PutContainerHandler sets the operation handler for the put container operation
|
||||
PutContainerHandler PutContainerHandler
|
||||
// PutContainerEACLHandler sets the operation handler for the put container e ACL operation
|
||||
|
@ -230,6 +235,9 @@ func (o *NeofsRestGwAPI) Validate() error {
|
|||
if o.GetObjectInfoHandler == nil {
|
||||
unregistered = append(unregistered, "GetObjectInfoHandler")
|
||||
}
|
||||
if o.ListContainersHandler == nil {
|
||||
unregistered = append(unregistered, "ListContainersHandler")
|
||||
}
|
||||
if o.PutContainerHandler == nil {
|
||||
unregistered = append(unregistered, "PutContainerHandler")
|
||||
}
|
||||
|
@ -358,6 +366,10 @@ func (o *NeofsRestGwAPI) initHandlerCache() {
|
|||
o.handlers["GET"] = make(map[string]http.Handler)
|
||||
}
|
||||
o.handlers["GET"]["/objects/{containerId}/{objectId}"] = NewGetObjectInfo(o.context, o.GetObjectInfoHandler)
|
||||
if o.handlers["GET"] == nil {
|
||||
o.handlers["GET"] = make(map[string]http.Handler)
|
||||
}
|
||||
o.handlers["GET"]["/containers"] = NewListContainers(o.context, o.ListContainersHandler)
|
||||
if o.handlers["PUT"] == nil {
|
||||
o.handlers["PUT"] = make(map[string]http.Handler)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue