[#1] Add route to delete container

Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
Denis Kirillov 2022-04-13 11:41:04 +03:00 committed by Alex Vanin
parent 066656ac48
commit 63fdb08f14
12 changed files with 637 additions and 96 deletions

View file

@ -98,6 +98,13 @@ func init() {
"summary": "Create new container in NeoFS",
"operationId": "putContainer",
"parameters": [
{
"type": "boolean",
"default": false,
"description": "Provide this parameter to skip registration container name in NNS service",
"name": "skip-native-name",
"in": "query"
},
{
"description": "Container info",
"name": "container",
@ -167,15 +174,6 @@ func init() {
"security": [],
"summary": "Get container by id",
"operationId": "getContainer",
"parameters": [
{
"type": "string",
"description": "Base58 encoded container id",
"name": "containerId",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "Container info",
@ -190,7 +188,39 @@ func init() {
}
}
}
}
},
"delete": {
"summary": "Delete container by id",
"operationId": "deleteContainer",
"parameters": [
{
"$ref": "#/parameters/signatureParam"
},
{
"$ref": "#/parameters/signatureKeyParam"
}
],
"responses": {
"204": {
"description": "Successul deletion"
},
"400": {
"description": "Bad request",
"schema": {
"$ref": "#/definitions/Error"
}
}
}
},
"parameters": [
{
"type": "string",
"description": "Base58 encoded container id",
"name": "containerId",
"in": "path",
"required": true
}
]
},
"/objects": {
"put": {
@ -745,6 +775,13 @@ func init() {
"summary": "Create new container in NeoFS",
"operationId": "putContainer",
"parameters": [
{
"type": "boolean",
"default": false,
"description": "Provide this parameter to skip registration container name in NNS service",
"name": "skip-native-name",
"in": "query"
},
{
"description": "Container info",
"name": "container",
@ -822,15 +859,6 @@ func init() {
"security": [],
"summary": "Get container by id",
"operationId": "getContainer",
"parameters": [
{
"type": "string",
"description": "Base58 encoded container id",
"name": "containerId",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "Container info",
@ -845,7 +873,47 @@ func init() {
}
}
}
}
},
"delete": {
"summary": "Delete container by id",
"operationId": "deleteContainer",
"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
}
],
"responses": {
"204": {
"description": "Successul deletion"
},
"400": {
"description": "Bad request",
"schema": {
"$ref": "#/definitions/Error"
}
}
}
},
"parameters": [
{
"type": "string",
"description": "Base58 encoded container id",
"name": "containerId",
"in": "path",
"required": true
}
]
},
"/objects": {
"put": {

View file

@ -0,0 +1,71 @@
// 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"
"github.com/nspcc-dev/neofs-rest-gw/gen/models"
)
// DeleteContainerHandlerFunc turns a function with the right signature into a delete container handler
type DeleteContainerHandlerFunc func(DeleteContainerParams, *models.Principal) middleware.Responder
// Handle executing the request and returning a response
func (fn DeleteContainerHandlerFunc) Handle(params DeleteContainerParams, principal *models.Principal) middleware.Responder {
return fn(params, principal)
}
// DeleteContainerHandler interface for that can handle valid delete container params
type DeleteContainerHandler interface {
Handle(DeleteContainerParams, *models.Principal) middleware.Responder
}
// NewDeleteContainer creates a new http.Handler for the delete container operation
func NewDeleteContainer(ctx *middleware.Context, handler DeleteContainerHandler) *DeleteContainer {
return &DeleteContainer{Context: ctx, Handler: handler}
}
/* DeleteContainer swagger:route DELETE /containers/{containerId} deleteContainer
Delete container by id
*/
type DeleteContainer struct {
Context *middleware.Context
Handler DeleteContainerHandler
}
func (o *DeleteContainer) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
route, rCtx, _ := o.Context.RouteInfo(r)
if rCtx != nil {
*r = *rCtx
}
var Params = NewDeleteContainerParams()
uprinc, aCtx, err := o.Context.Authorize(r, route)
if err != nil {
o.Context.Respond(rw, r, route.Produces, route, err)
return
}
if aCtx != nil {
*r = *aCtx
}
var principal *models.Principal
if uprinc != nil {
principal = uprinc.(*models.Principal) // this is really a models.Principal, I promise
}
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, principal) // actually handle the request
o.Context.Respond(rw, r, route.Produces, route, res)
}

View file

@ -0,0 +1,130 @@
// 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/middleware"
"github.com/go-openapi/strfmt"
"github.com/go-openapi/validate"
)
// NewDeleteContainerParams creates a new DeleteContainerParams object
//
// There are no default values defined in the spec.
func NewDeleteContainerParams() DeleteContainerParams {
return DeleteContainerParams{}
}
// DeleteContainerParams contains all the bound params for the delete container operation
// typically these are obtained from a http.Request
//
// swagger:parameters deleteContainer
type DeleteContainerParams struct {
// HTTP Request Object
HTTPRequest *http.Request `json:"-"`
/*Base64 encoded signature for bearer token
Required: true
In: header
*/
XNeofsTokenSignature string
/*Hex encoded the public part of the key that signed the bearer token
Required: true
In: header
*/
XNeofsTokenSignatureKey string
/*Base58 encoded container id
Required: true
In: path
*/
ContainerID 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 NewDeleteContainerParams() beforehand.
func (o *DeleteContainerParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {
var res []error
o.HTTPRequest = r
if err := o.bindXNeofsTokenSignature(r.Header[http.CanonicalHeaderKey("X-Neofs-Token-Signature")], true, route.Formats); err != nil {
res = append(res, err)
}
if err := o.bindXNeofsTokenSignatureKey(r.Header[http.CanonicalHeaderKey("X-Neofs-Token-Signature-Key")], true, route.Formats); err != nil {
res = append(res, err)
}
rContainerID, rhkContainerID, _ := route.Params.GetOK("containerId")
if err := o.bindContainerID(rContainerID, rhkContainerID, route.Formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
// bindXNeofsTokenSignature binds and validates parameter XNeofsTokenSignature from header.
func (o *DeleteContainerParams) bindXNeofsTokenSignature(rawData []string, hasKey bool, formats strfmt.Registry) error {
if !hasKey {
return errors.Required("X-Neofs-Token-Signature", "header", rawData)
}
var raw string
if len(rawData) > 0 {
raw = rawData[len(rawData)-1]
}
// Required: true
if err := validate.RequiredString("X-Neofs-Token-Signature", "header", raw); err != nil {
return err
}
o.XNeofsTokenSignature = raw
return nil
}
// bindXNeofsTokenSignatureKey binds and validates parameter XNeofsTokenSignatureKey from header.
func (o *DeleteContainerParams) bindXNeofsTokenSignatureKey(rawData []string, hasKey bool, formats strfmt.Registry) error {
if !hasKey {
return errors.Required("X-Neofs-Token-Signature-Key", "header", rawData)
}
var raw string
if len(rawData) > 0 {
raw = rawData[len(rawData)-1]
}
// Required: true
if err := validate.RequiredString("X-Neofs-Token-Signature-Key", "header", raw); err != nil {
return err
}
o.XNeofsTokenSignatureKey = raw
return nil
}
// bindContainerID binds and validates parameter ContainerID from path.
func (o *DeleteContainerParams) bindContainerID(rawData []string, hasKey bool, formats strfmt.Registry) error {
var raw string
if len(rawData) > 0 {
raw = rawData[len(rawData)-1]
}
// Required: true
// Parameter is provided by construction from the route
o.ContainerID = raw
return nil
}

View file

@ -0,0 +1,80 @@
// 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"
)
// DeleteContainerNoContentCode is the HTTP code returned for type DeleteContainerNoContent
const DeleteContainerNoContentCode int = 204
/*DeleteContainerNoContent Successul deletion
swagger:response deleteContainerNoContent
*/
type DeleteContainerNoContent struct {
}
// NewDeleteContainerNoContent creates DeleteContainerNoContent with default headers values
func NewDeleteContainerNoContent() *DeleteContainerNoContent {
return &DeleteContainerNoContent{}
}
// WriteResponse to the client
func (o *DeleteContainerNoContent) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
rw.Header().Del(runtime.HeaderContentType) //Remove Content-Type on empty responses
rw.WriteHeader(204)
}
// DeleteContainerBadRequestCode is the HTTP code returned for type DeleteContainerBadRequest
const DeleteContainerBadRequestCode int = 400
/*DeleteContainerBadRequest Bad request
swagger:response deleteContainerBadRequest
*/
type DeleteContainerBadRequest struct {
/*
In: Body
*/
Payload models.Error `json:"body,omitempty"`
}
// NewDeleteContainerBadRequest creates DeleteContainerBadRequest with default headers values
func NewDeleteContainerBadRequest() *DeleteContainerBadRequest {
return &DeleteContainerBadRequest{}
}
// WithPayload adds the payload to the delete container bad request response
func (o *DeleteContainerBadRequest) WithPayload(payload models.Error) *DeleteContainerBadRequest {
o.Payload = payload
return o
}
// SetPayload sets the payload to the delete container bad request response
func (o *DeleteContainerBadRequest) SetPayload(payload models.Error) {
o.Payload = payload
}
// WriteResponse to the client
func (o *DeleteContainerBadRequest) 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
}
}

View file

@ -47,6 +47,9 @@ func NewNeofsRestGwAPI(spec *loads.Document) *NeofsRestGwAPI {
AuthHandler: AuthHandlerFunc(func(params AuthParams) middleware.Responder {
return middleware.NotImplemented("operation Auth has not yet been implemented")
}),
DeleteContainerHandler: DeleteContainerHandlerFunc(func(params DeleteContainerParams, principal *models.Principal) middleware.Responder {
return middleware.NotImplemented("operation DeleteContainer has not yet been implemented")
}),
GetContainerHandler: GetContainerHandlerFunc(func(params GetContainerParams) middleware.Responder {
return middleware.NotImplemented("operation GetContainer has not yet been implemented")
}),
@ -111,6 +114,8 @@ type NeofsRestGwAPI struct {
// AuthHandler sets the operation handler for the auth operation
AuthHandler AuthHandler
// DeleteContainerHandler sets the operation handler for the delete container operation
DeleteContainerHandler DeleteContainerHandler
// GetContainerHandler sets the operation handler for the get container operation
GetContainerHandler GetContainerHandler
// GetObjectInfoHandler sets the operation handler for the get object info operation
@ -203,6 +208,9 @@ func (o *NeofsRestGwAPI) Validate() error {
if o.AuthHandler == nil {
unregistered = append(unregistered, "AuthHandler")
}
if o.DeleteContainerHandler == nil {
unregistered = append(unregistered, "DeleteContainerHandler")
}
if o.GetContainerHandler == nil {
unregistered = append(unregistered, "GetContainerHandler")
}
@ -318,6 +326,10 @@ func (o *NeofsRestGwAPI) initHandlerCache() {
o.handlers["POST"] = make(map[string]http.Handler)
}
o.handlers["POST"]["/auth"] = NewAuth(o.context, o.AuthHandler)
if o.handlers["DELETE"] == nil {
o.handlers["DELETE"] = make(map[string]http.Handler)
}
o.handlers["DELETE"]["/containers/{containerId}"] = NewDeleteContainer(o.context, o.DeleteContainerHandler)
if o.handlers["GET"] == nil {
o.handlers["GET"] = make(map[string]http.Handler)
}

View file

@ -14,15 +14,23 @@ import (
"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"
)
// NewPutContainerParams creates a new PutContainerParams object
//
// There are no default values defined in the spec.
// with the default values initialized.
func NewPutContainerParams() PutContainerParams {
return PutContainerParams{}
var (
// initialize parameters with default values
skipNativeNameDefault = bool(false)
)
return PutContainerParams{
SkipNativeName: &skipNativeNameDefault,
}
}
// PutContainerParams contains all the bound params for the put container operation
@ -49,6 +57,11 @@ type PutContainerParams struct {
In: body
*/
Container PutContainerBody
/*Provide this parameter to skip registration container name in NNS service
In: query
Default: false
*/
SkipNativeName *bool
}
// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface
@ -60,6 +73,8 @@ func (o *PutContainerParams) BindRequest(r *http.Request, route *middleware.Matc
o.HTTPRequest = r
qs := runtime.Values(r.URL.Query())
if err := o.bindXNeofsTokenSignature(r.Header[http.CanonicalHeaderKey("X-Neofs-Token-Signature")], true, route.Formats); err != nil {
res = append(res, err)
}
@ -95,6 +110,11 @@ func (o *PutContainerParams) BindRequest(r *http.Request, route *middleware.Matc
} else {
res = append(res, errors.Required("container", "body", ""))
}
qSkipNativeName, qhkSkipNativeName, _ := qs.GetOK("skip-native-name")
if err := o.bindSkipNativeName(qSkipNativeName, qhkSkipNativeName, route.Formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
@ -140,3 +160,27 @@ func (o *PutContainerParams) bindXNeofsTokenSignatureKey(rawData []string, hasKe
return nil
}
// bindSkipNativeName binds and validates parameter SkipNativeName from query.
func (o *PutContainerParams) bindSkipNativeName(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 NewPutContainerParams()
return nil
}
value, err := swag.ConvertBool(raw)
if err != nil {
return errors.InvalidType("skip-native-name", "query", "bool", raw)
}
o.SkipNativeName = &value
return nil
}