[#180] api: Add continuation-token check

Signed-off-by: Angira Kekteeva <kira@nspcc.ru>
This commit is contained in:
Angira Kekteeva 2021-07-29 19:16:43 +03:00
parent 7291b81040
commit 88aaad361a

View file

@ -2,9 +2,11 @@ package handler
import ( import (
"net/http" "net/http"
"net/url"
"strconv" "strconv"
"time" "time"
"github.com/nspcc-dev/neofs-api-go/pkg/object"
"github.com/nspcc-dev/neofs-s3-gw/api" "github.com/nspcc-dev/neofs-s3-gw/api"
"github.com/nspcc-dev/neofs-s3-gw/api/layer" "github.com/nspcc-dev/neofs-s3-gw/api/layer"
) )
@ -120,7 +122,11 @@ func parseListObjectsArgsV2(r *http.Request) (*layer.ListObjectsParamsV2, error)
} }
res.ListObjectsParamsCommon = *common res.ListObjectsParamsCommon = *common
res.ContinuationToken = queryValues.Get("continuation-token") res.ContinuationToken, err = parseContinuationToken(queryValues)
if err != nil {
return nil, err
}
res.StartAfter = queryValues.Get("start-after") res.StartAfter = queryValues.Get("start-after")
res.FetchOwner, _ = strconv.ParseBool(queryValues.Get("fetch-owner")) res.FetchOwner, _ = strconv.ParseBool(queryValues.Get("fetch-owner"))
return &res, nil return &res, nil
@ -151,6 +157,16 @@ func parseListObjectArgs(r *http.Request) (*layer.ListObjectsParamsCommon, error
return &res, nil return &res, nil
} }
func parseContinuationToken(queryValues url.Values) (string, error) {
if val, ok := queryValues["continuation-token"]; ok {
if err := object.NewID().Parse(val[0]); err != nil {
return "", api.GetAPIError(api.ErrIncorrectContinuationToken)
}
return val[0], nil
}
return "", nil
}
func fillPrefixes(src []string, encode string) []CommonPrefix { func fillPrefixes(src []string, encode string) []CommonPrefix {
var dst []CommonPrefix var dst []CommonPrefix
for _, obj := range src { for _, obj := range src {