[#1] Support GET/RANGE object payload

Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
Denis Kirillov 2022-04-20 17:10:43 +03:00 committed by Alex Vanin
parent dc1926f9c6
commit 3727f5561d
8 changed files with 395 additions and 10 deletions

View file

@ -454,8 +454,29 @@ func init() {
},
"/objects/{containerId}/{objectId}": {
"get": {
"summary": "Get object info by address and",
"summary": "Get object info by address",
"operationId": "getObjectInfo",
"parameters": [
{
"type": "integer",
"name": "range-offset",
"in": "query"
},
{
"minimum": 1,
"type": "integer",
"name": "range-length",
"in": "query"
},
{
"maximum": 524288000,
"type": "integer",
"default": 4194304,
"description": "Max payload size (in bytes) that can be included in the response.\nIf the actual size is greater than this params the payload won't be included in the response.\n",
"name": "max-payload-size",
"in": "query"
}
],
"responses": {
"200": {
"description": "Object info",
@ -729,7 +750,9 @@ func init() {
"containerId",
"objectId",
"ownerId",
"attributes"
"attributes",
"objectSize",
"payloadSize"
],
"properties": {
"attributes": {
@ -744,8 +767,20 @@ func init() {
"objectId": {
"type": "string"
},
"objectSize": {
"description": "Object full payload size",
"type": "integer"
},
"ownerId": {
"type": "string"
},
"payload": {
"description": "Base64 encoded object payload",
"type": "string"
},
"payloadSize": {
"description": "Payload size in response",
"type": "integer"
}
},
"example": {
@ -1532,8 +1567,31 @@ func init() {
},
"/objects/{containerId}/{objectId}": {
"get": {
"summary": "Get object info by address and",
"summary": "Get object info by address",
"operationId": "getObjectInfo",
"parameters": [
{
"minimum": 0,
"type": "integer",
"name": "range-offset",
"in": "query"
},
{
"minimum": 1,
"type": "integer",
"name": "range-length",
"in": "query"
},
{
"maximum": 524288000,
"minimum": 0,
"type": "integer",
"default": 4194304,
"description": "Max payload size (in bytes) that can be included in the response.\nIf the actual size is greater than this params the payload won't be included in the response.\n",
"name": "max-payload-size",
"in": "query"
}
],
"responses": {
"200": {
"description": "Object info",
@ -1827,7 +1885,9 @@ func init() {
"containerId",
"objectId",
"ownerId",
"attributes"
"attributes",
"objectSize",
"payloadSize"
],
"properties": {
"attributes": {
@ -1842,8 +1902,20 @@ func init() {
"objectId": {
"type": "string"
},
"objectSize": {
"description": "Object full payload size",
"type": "integer"
},
"ownerId": {
"type": "string"
},
"payload": {
"description": "Base64 encoded object payload",
"type": "string"
},
"payloadSize": {
"description": "Payload size in response",
"type": "integer"
}
},
"example": {

View file

@ -33,7 +33,7 @@ func NewGetObjectInfo(ctx *middleware.Context, handler GetObjectInfoHandler) *Ge
/* GetObjectInfo swagger:route GET /objects/{containerId}/{objectId} getObjectInfo
Get object info by address and
Get object info by address
*/
type GetObjectInfo struct {

View file

@ -23,10 +23,14 @@ func NewGetObjectInfoParams() GetObjectInfoParams {
var (
// initialize parameters with default values
maxPayloadSizeDefault = int64(4.194304e+06)
walletConnectDefault = bool(false)
)
return GetObjectInfoParams{
MaxPayloadSize: &maxPayloadSizeDefault,
WalletConnect: &walletConnectDefault,
}
}
@ -55,11 +59,30 @@ type GetObjectInfoParams struct {
In: path
*/
ContainerID string
/*Max payload size (in bytes) that can be included in the response.
If the actual size is greater than this params the payload won't be included in the response.
Maximum: 5.24288e+08
Minimum: 0
In: query
Default: 4.194304e+06
*/
MaxPayloadSize *int64
/*Base58 encoded object id
Required: true
In: path
*/
ObjectID string
/*
Minimum: 1
In: query
*/
RangeLength *int64
/*
Minimum: 0
In: query
*/
RangeOffset *int64
/*Use wallect connect signature scheme or not
In: query
Default: false
@ -91,11 +114,26 @@ func (o *GetObjectInfoParams) BindRequest(r *http.Request, route *middleware.Mat
res = append(res, err)
}
qMaxPayloadSize, qhkMaxPayloadSize, _ := qs.GetOK("max-payload-size")
if err := o.bindMaxPayloadSize(qMaxPayloadSize, qhkMaxPayloadSize, route.Formats); err != nil {
res = append(res, err)
}
rObjectID, rhkObjectID, _ := route.Params.GetOK("objectId")
if err := o.bindObjectID(rObjectID, rhkObjectID, route.Formats); err != nil {
res = append(res, err)
}
qRangeLength, qhkRangeLength, _ := qs.GetOK("range-length")
if err := o.bindRangeLength(qRangeLength, qhkRangeLength, route.Formats); err != nil {
res = append(res, err)
}
qRangeOffset, qhkRangeOffset, _ := qs.GetOK("range-offset")
if err := o.bindRangeOffset(qRangeOffset, qhkRangeOffset, route.Formats); err != nil {
res = append(res, err)
}
qWalletConnect, qhkWalletConnect, _ := qs.GetOK("walletConnect")
if err := o.bindWalletConnect(qWalletConnect, qhkWalletConnect, route.Formats); err != nil {
res = append(res, err)
@ -160,6 +198,48 @@ func (o *GetObjectInfoParams) bindContainerID(rawData []string, hasKey bool, for
return nil
}
// bindMaxPayloadSize binds and validates parameter MaxPayloadSize from query.
func (o *GetObjectInfoParams) bindMaxPayloadSize(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 NewGetObjectInfoParams()
return nil
}
value, err := swag.ConvertInt64(raw)
if err != nil {
return errors.InvalidType("max-payload-size", "query", "int64", raw)
}
o.MaxPayloadSize = &value
if err := o.validateMaxPayloadSize(formats); err != nil {
return err
}
return nil
}
// validateMaxPayloadSize carries on validations for parameter MaxPayloadSize
func (o *GetObjectInfoParams) validateMaxPayloadSize(formats strfmt.Registry) error {
if err := validate.MinimumInt("max-payload-size", "query", *o.MaxPayloadSize, 0, false); err != nil {
return err
}
if err := validate.MaximumInt("max-payload-size", "query", *o.MaxPayloadSize, 5.24288e+08, false); err != nil {
return err
}
return nil
}
// bindObjectID binds and validates parameter ObjectID from path.
func (o *GetObjectInfoParams) bindObjectID(rawData []string, hasKey bool, formats strfmt.Registry) error {
var raw string
@ -174,6 +254,80 @@ func (o *GetObjectInfoParams) bindObjectID(rawData []string, hasKey bool, format
return nil
}
// bindRangeLength binds and validates parameter RangeLength from query.
func (o *GetObjectInfoParams) bindRangeLength(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
return nil
}
value, err := swag.ConvertInt64(raw)
if err != nil {
return errors.InvalidType("range-length", "query", "int64", raw)
}
o.RangeLength = &value
if err := o.validateRangeLength(formats); err != nil {
return err
}
return nil
}
// validateRangeLength carries on validations for parameter RangeLength
func (o *GetObjectInfoParams) validateRangeLength(formats strfmt.Registry) error {
if err := validate.MinimumInt("range-length", "query", *o.RangeLength, 1, false); err != nil {
return err
}
return nil
}
// bindRangeOffset binds and validates parameter RangeOffset from query.
func (o *GetObjectInfoParams) bindRangeOffset(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
return nil
}
value, err := swag.ConvertInt64(raw)
if err != nil {
return errors.InvalidType("range-offset", "query", "int64", raw)
}
o.RangeOffset = &value
if err := o.validateRangeOffset(formats); err != nil {
return err
}
return nil
}
// validateRangeOffset carries on validations for parameter RangeOffset
func (o *GetObjectInfoParams) validateRangeOffset(formats strfmt.Registry) error {
if err := validate.MinimumInt("range-offset", "query", *o.RangeOffset, 0, false); err != nil {
return err
}
return nil
}
// bindWalletConnect binds and validates parameter WalletConnect from query.
func (o *GetObjectInfoParams) bindWalletConnect(rawData []string, hasKey bool, formats strfmt.Registry) error {
var raw string