forked from TrueCloudLab/frostfs-rest-gw
[#1] Make walletconnect package internal
Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
parent
3f4adfdc12
commit
808aff5c66
9 changed files with 86 additions and 78 deletions
|
@ -24,7 +24,8 @@ import (
|
||||||
"github.com/nspcc-dev/neofs-rest-gw/gen/restapi"
|
"github.com/nspcc-dev/neofs-rest-gw/gen/restapi"
|
||||||
"github.com/nspcc-dev/neofs-rest-gw/gen/restapi/operations"
|
"github.com/nspcc-dev/neofs-rest-gw/gen/restapi/operations"
|
||||||
"github.com/nspcc-dev/neofs-rest-gw/handlers"
|
"github.com/nspcc-dev/neofs-rest-gw/handlers"
|
||||||
walletconnect "github.com/nspcc-dev/neofs-rest-gw/wallet-connect"
|
"github.com/nspcc-dev/neofs-rest-gw/internal/util"
|
||||||
|
"github.com/nspcc-dev/neofs-rest-gw/internal/wallet-connect"
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/container"
|
"github.com/nspcc-dev/neofs-sdk-go/container"
|
||||||
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/eacl"
|
"github.com/nspcc-dev/neofs-sdk-go/eacl"
|
||||||
|
@ -252,8 +253,8 @@ func restObjectPut(ctx context.Context, t *testing.T, clientPool *pool.Pool, cnr
|
||||||
}
|
}
|
||||||
|
|
||||||
req := &models.ObjectUpload{
|
req := &models.ObjectUpload{
|
||||||
ContainerID: handlers.NewString(cnrID.String()),
|
ContainerID: util.NewString(cnrID.String()),
|
||||||
FileName: handlers.NewString("newFile.txt"),
|
FileName: util.NewString("newFile.txt"),
|
||||||
Payload: base64.StdEncoding.EncodeToString([]byte(content)),
|
Payload: base64.StdEncoding.EncodeToString([]byte(content)),
|
||||||
Attributes: []*models.Attribute{{
|
Attributes: []*models.Attribute{{
|
||||||
Key: &attrKey,
|
Key: &attrKey,
|
||||||
|
@ -473,9 +474,9 @@ func restObjectsSearch(ctx context.Context, t *testing.T, p *pool.Pool, cnrID *c
|
||||||
search := &models.SearchFilters{
|
search := &models.SearchFilters{
|
||||||
Filters: []*models.SearchFilter{
|
Filters: []*models.SearchFilter{
|
||||||
{
|
{
|
||||||
Key: handlers.NewString(userKey),
|
Key: util.NewString(userKey),
|
||||||
Match: models.NewSearchMatch(models.SearchMatchMatchStringEqual),
|
Match: models.NewSearchMatch(models.SearchMatchMatchStringEqual),
|
||||||
Value: handlers.NewString(userValue),
|
Value: util.NewString(userValue),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -609,7 +610,7 @@ func restContainerEACLPut(ctx context.Context, t *testing.T, clientPool *pool.Po
|
||||||
table, err := clientPool.GetEACL(ctx, prm)
|
table, err := clientPool.GetEACL(ctx, prm)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expectedTable, err := handlers.ToNativeTable(req.Records)
|
expectedTable, err := util.ToNativeTable(req.Records)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
expectedTable.SetCID(cnrID)
|
expectedTable.SetCID(cnrID)
|
||||||
|
|
||||||
|
@ -633,7 +634,7 @@ func restContainerEACLGet(ctx context.Context, t *testing.T, p *pool.Pool, cnrID
|
||||||
|
|
||||||
require.Equal(t, cnrID.String(), responseTable.ContainerID)
|
require.Equal(t, cnrID.String(), responseTable.ContainerID)
|
||||||
|
|
||||||
actualTable, err := handlers.ToNativeTable(responseTable.Records)
|
actualTable, err := util.ToNativeTable(responseTable.Records)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
actualTable.SetCID(cnrID)
|
actualTable.SetCID(cnrID)
|
||||||
|
|
||||||
|
@ -662,7 +663,7 @@ func restContainerList(ctx context.Context, t *testing.T, p *pool.Pool, cnrID *c
|
||||||
require.Equal(t, len(ids), int(*list.Size))
|
require.Equal(t, len(ids), int(*list.Size))
|
||||||
|
|
||||||
expected := &models.ContainerBaseInfo{
|
expected := &models.ContainerBaseInfo{
|
||||||
ContainerID: handlers.NewString(cnrID.String()),
|
ContainerID: util.NewString(cnrID.String()),
|
||||||
Name: containerName,
|
Name: containerName,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -768,7 +769,7 @@ func restContainerPut(ctx context.Context, t *testing.T, clientPool *pool.Pool)
|
||||||
}
|
}
|
||||||
|
|
||||||
req := operations.PutContainerBody{
|
req := operations.PutContainerBody{
|
||||||
ContainerName: handlers.NewString("cnr"),
|
ContainerName: util.NewString("cnr"),
|
||||||
}
|
}
|
||||||
body, err := json.Marshal(&req)
|
body, err := json.Marshal(&req)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
"github.com/nspcc-dev/neofs-rest-gw/gen/models"
|
"github.com/nspcc-dev/neofs-rest-gw/gen/models"
|
||||||
"github.com/nspcc-dev/neofs-rest-gw/gen/restapi/operations"
|
"github.com/nspcc-dev/neofs-rest-gw/gen/restapi/operations"
|
||||||
|
"github.com/nspcc-dev/neofs-rest-gw/internal/util"
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/owner"
|
"github.com/nspcc-dev/neofs-sdk-go/owner"
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/pool"
|
"github.com/nspcc-dev/neofs-sdk-go/pool"
|
||||||
)
|
)
|
||||||
|
@ -39,7 +40,7 @@ func (a *API) PostAuth(params operations.AuthParams) middleware.Responder {
|
||||||
func prepareObjectToken(params operations.AuthParams, pool *pool.Pool) (*models.TokenResponse, error) {
|
func prepareObjectToken(params operations.AuthParams, pool *pool.Pool) (*models.TokenResponse, error) {
|
||||||
ctx := params.HTTPRequest.Context()
|
ctx := params.HTTPRequest.Context()
|
||||||
|
|
||||||
btoken, err := ToNativeObjectToken(params.Token)
|
btoken, err := util.ToNativeObjectToken(params.Token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("couldn't transform token to native: %w", err)
|
return nil, fmt.Errorf("couldn't transform token to native: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -58,7 +59,7 @@ func prepareObjectToken(params operations.AuthParams, pool *pool.Pool) (*models.
|
||||||
|
|
||||||
var resp models.TokenResponse
|
var resp models.TokenResponse
|
||||||
resp.Type = models.NewTokenType(models.TokenTypeObject)
|
resp.Type = models.NewTokenType(models.TokenTypeObject)
|
||||||
resp.Token = NewString(base64.StdEncoding.EncodeToString(binaryBearer))
|
resp.Token = util.NewString(base64.StdEncoding.EncodeToString(binaryBearer))
|
||||||
|
|
||||||
return &resp, nil
|
return &resp, nil
|
||||||
}
|
}
|
||||||
|
@ -79,7 +80,7 @@ func prepareContainerTokens(params operations.AuthParams, pool *pool.Pool, key *
|
||||||
var resp models.TokenResponse
|
var resp models.TokenResponse
|
||||||
resp.Type = models.NewTokenType(models.TokenTypeContainer)
|
resp.Type = models.NewTokenType(models.TokenTypeContainer)
|
||||||
|
|
||||||
stoken, err := ToNativeContainerToken(params.Token)
|
stoken, err := util.ToNativeContainerToken(params.Token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("couldn't transform rule to native session token: %w", err)
|
return nil, fmt.Errorf("couldn't transform rule to native session token: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -101,7 +102,7 @@ func prepareContainerTokens(params operations.AuthParams, pool *pool.Pool, key *
|
||||||
return nil, fmt.Errorf("couldn't marshal session token: %w", err)
|
return nil, fmt.Errorf("couldn't marshal session token: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
resp.Token = NewString(base64.StdEncoding.EncodeToString(binaryToken))
|
resp.Token = util.NewString(base64.StdEncoding.EncodeToString(binaryToken))
|
||||||
|
|
||||||
return &resp, nil
|
return &resp, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
"github.com/nspcc-dev/neofs-rest-gw/gen/models"
|
"github.com/nspcc-dev/neofs-rest-gw/gen/models"
|
||||||
|
"github.com/nspcc-dev/neofs-rest-gw/internal/util"
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/owner"
|
"github.com/nspcc-dev/neofs-sdk-go/owner"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
@ -35,7 +36,7 @@ func TestSign(t *testing.T) {
|
||||||
}},
|
}},
|
||||||
}
|
}
|
||||||
|
|
||||||
btoken, err := ToNativeObjectToken(b)
|
btoken, err := util.ToNativeObjectToken(b)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
ownerKey, err := keys.NewPublicKeyFromString(pubKeyHex)
|
ownerKey, err := keys.NewPublicKeyFromString(pubKeyHex)
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
walletconnect "github.com/nspcc-dev/neofs-rest-gw/wallet-connect"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -17,6 +16,8 @@ import (
|
||||||
sessionv2 "github.com/nspcc-dev/neofs-api-go/v2/session"
|
sessionv2 "github.com/nspcc-dev/neofs-api-go/v2/session"
|
||||||
"github.com/nspcc-dev/neofs-rest-gw/gen/models"
|
"github.com/nspcc-dev/neofs-rest-gw/gen/models"
|
||||||
"github.com/nspcc-dev/neofs-rest-gw/gen/restapi/operations"
|
"github.com/nspcc-dev/neofs-rest-gw/gen/restapi/operations"
|
||||||
|
"github.com/nspcc-dev/neofs-rest-gw/internal/util"
|
||||||
|
"github.com/nspcc-dev/neofs-rest-gw/internal/wallet-connect"
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/acl"
|
"github.com/nspcc-dev/neofs-sdk-go/acl"
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/container"
|
"github.com/nspcc-dev/neofs-sdk-go/container"
|
||||||
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
||||||
|
@ -52,7 +53,7 @@ func (a *API) PutContainers(params operations.PutContainerParams, principal *mod
|
||||||
}
|
}
|
||||||
|
|
||||||
var resp operations.PutContainerOKBody
|
var resp operations.PutContainerOKBody
|
||||||
resp.ContainerID = NewString(cnrID.String())
|
resp.ContainerID = util.NewString(cnrID.String())
|
||||||
|
|
||||||
return operations.NewPutContainerOK().WithPayload(&resp)
|
return operations.NewPutContainerOK().WithPayload(&resp)
|
||||||
}
|
}
|
||||||
|
@ -67,17 +68,17 @@ func (a *API) GetContainer(params operations.GetContainerParams) middleware.Resp
|
||||||
attrs := make([]*models.Attribute, len(cnr.Attributes()))
|
attrs := make([]*models.Attribute, len(cnr.Attributes()))
|
||||||
for i, attr := range cnr.Attributes() {
|
for i, attr := range cnr.Attributes() {
|
||||||
attrs[i] = &models.Attribute{
|
attrs[i] = &models.Attribute{
|
||||||
Key: NewString(attr.Key()),
|
Key: util.NewString(attr.Key()),
|
||||||
Value: NewString(attr.Value()),
|
Value: util.NewString(attr.Value()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := &models.ContainerInfo{
|
resp := &models.ContainerInfo{
|
||||||
ContainerID: NewString(params.ContainerID),
|
ContainerID: util.NewString(params.ContainerID),
|
||||||
Version: NewString(cnr.Version().String()),
|
Version: util.NewString(cnr.Version().String()),
|
||||||
OwnerID: NewString(cnr.OwnerID().String()),
|
OwnerID: util.NewString(cnr.OwnerID().String()),
|
||||||
BasicACL: NewString(acl.BasicACL(cnr.BasicACL()).String()),
|
BasicACL: util.NewString(acl.BasicACL(cnr.BasicACL()).String()),
|
||||||
PlacementPolicy: NewString(strings.Join(policy.Encode(cnr.PlacementPolicy()), " ")),
|
PlacementPolicy: util.NewString(strings.Join(policy.Encode(cnr.PlacementPolicy()), " ")),
|
||||||
Attributes: attrs,
|
Attributes: attrs,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,7 +105,7 @@ func (a *API) PutContainerEACL(params operations.PutContainerEACLParams, princip
|
||||||
|
|
||||||
if err = setContainerEACL(params.HTTPRequest.Context(), a.pool, cnrID, stoken, params.Eacl); err != nil {
|
if err = setContainerEACL(params.HTTPRequest.Context(), a.pool, cnrID, stoken, params.Eacl); err != nil {
|
||||||
a.log.Error("failed set container eacl", zap.Error(err))
|
a.log.Error("failed set container eacl", zap.Error(err))
|
||||||
return operations.NewPutContainerEACLBadRequest().WithPayload(NewError(err))
|
return operations.NewPutContainerEACLBadRequest().WithPayload(util.NewError(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
return operations.NewPutContainerEACLOK()
|
return operations.NewPutContainerEACLOK()
|
||||||
|
@ -151,7 +152,7 @@ func (a *API) ListContainer(params operations.ListContainersParams) middleware.R
|
||||||
|
|
||||||
if offset > len(ids)-1 {
|
if offset > len(ids)-1 {
|
||||||
res := &models.ContainerList{
|
res := &models.ContainerList{
|
||||||
Size: NewInteger(0),
|
Size: util.NewInteger(0),
|
||||||
Containers: []*models.ContainerBaseInfo{},
|
Containers: []*models.ContainerBaseInfo{},
|
||||||
}
|
}
|
||||||
return operations.NewListContainersOK().WithPayload(res)
|
return operations.NewListContainersOK().WithPayload(res)
|
||||||
|
@ -162,7 +163,7 @@ func (a *API) ListContainer(params operations.ListContainersParams) middleware.R
|
||||||
}
|
}
|
||||||
|
|
||||||
res := &models.ContainerList{
|
res := &models.ContainerList{
|
||||||
Size: NewInteger(int64(size)),
|
Size: util.NewInteger(int64(size)),
|
||||||
Containers: make([]*models.ContainerBaseInfo, 0, size),
|
Containers: make([]*models.ContainerBaseInfo, 0, size),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,13 +189,13 @@ func (a *API) DeleteContainer(params operations.DeleteContainerParams, principal
|
||||||
stoken, err := prepareSessionToken(bt, *params.WalletConnect)
|
stoken, err := prepareSessionToken(bt, *params.WalletConnect)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.log.Error("failed parse session token", zap.Error(err))
|
a.log.Error("failed parse session token", zap.Error(err))
|
||||||
return operations.NewDeleteContainerBadRequest().WithPayload(NewError(err))
|
return operations.NewDeleteContainerBadRequest().WithPayload(util.NewError(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
cnrID, err := parseContainerID(params.ContainerID)
|
cnrID, err := parseContainerID(params.ContainerID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.log.Error("failed get container id", zap.Error(err))
|
a.log.Error("failed get container id", zap.Error(err))
|
||||||
return operations.NewDeleteContainerBadRequest().WithPayload(NewError(err))
|
return operations.NewDeleteContainerBadRequest().WithPayload(util.NewError(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
var prm pool.PrmContainerDelete
|
var prm pool.PrmContainerDelete
|
||||||
|
@ -203,7 +204,7 @@ func (a *API) DeleteContainer(params operations.DeleteContainerParams, principal
|
||||||
|
|
||||||
if err = a.pool.DeleteContainer(params.HTTPRequest.Context(), prm); err != nil {
|
if err = a.pool.DeleteContainer(params.HTTPRequest.Context(), prm); err != nil {
|
||||||
a.log.Error("failed delete container", zap.String("container", params.ContainerID), zap.Error(err))
|
a.log.Error("failed delete container", zap.String("container", params.ContainerID), zap.Error(err))
|
||||||
return operations.NewDeleteContainerBadRequest().WithPayload(NewError(err))
|
return operations.NewDeleteContainerBadRequest().WithPayload(util.NewError(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
return operations.NewDeleteContainerNoContent()
|
return operations.NewDeleteContainerNoContent()
|
||||||
|
@ -218,7 +219,7 @@ func getContainerBaseInfo(ctx context.Context, p *pool.Pool, cnrID cid.ID) (*mod
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
baseInfo := &models.ContainerBaseInfo{ContainerID: NewString(cnrID.String())}
|
baseInfo := &models.ContainerBaseInfo{ContainerID: util.NewString(cnrID.String())}
|
||||||
|
|
||||||
for _, attr := range cnr.Attributes() {
|
for _, attr := range cnr.Attributes() {
|
||||||
if attr.Key() == container.AttributeName {
|
if attr.Key() == container.AttributeName {
|
||||||
|
@ -258,7 +259,7 @@ func parseContainerID(containerID string) (*cid.ID, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func setContainerEACL(ctx context.Context, p *pool.Pool, cnrID *cid.ID, stoken *session.Token, eaclPrm *models.Eacl) error {
|
func setContainerEACL(ctx context.Context, p *pool.Pool, cnrID *cid.ID, stoken *session.Token, eaclPrm *models.Eacl) error {
|
||||||
table, err := ToNativeTable(eaclPrm.Records)
|
table, err := util.ToNativeTable(eaclPrm.Records)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -287,7 +288,7 @@ func getContainerEACL(ctx context.Context, p *pool.Pool, cnrID *cid.ID) (*models
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, rec := range table.Records() {
|
for i, rec := range table.Records() {
|
||||||
record, err := FromNativeRecord(rec)
|
record, err := util.FromNativeRecord(rec)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("couldn't transform record from native: %w", err)
|
return nil, fmt.Errorf("couldn't transform record from native: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,8 @@ import (
|
||||||
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
||||||
"github.com/nspcc-dev/neofs-rest-gw/gen/models"
|
"github.com/nspcc-dev/neofs-rest-gw/gen/models"
|
||||||
"github.com/nspcc-dev/neofs-rest-gw/gen/restapi/operations"
|
"github.com/nspcc-dev/neofs-rest-gw/gen/restapi/operations"
|
||||||
walletconnect "github.com/nspcc-dev/neofs-rest-gw/wallet-connect"
|
"github.com/nspcc-dev/neofs-rest-gw/internal/util"
|
||||||
|
"github.com/nspcc-dev/neofs-rest-gw/internal/wallet-connect"
|
||||||
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/object"
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/object/address"
|
"github.com/nspcc-dev/neofs-sdk-go/object/address"
|
||||||
|
@ -67,12 +68,12 @@ func (a *API) PutObjects(params operations.PutObjectParams, principal *models.Pr
|
||||||
objID, err := a.pool.PutObject(ctx, prmPut)
|
objID, err := a.pool.PutObject(ctx, prmPut)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.log.Error("put object", zap.Error(err))
|
a.log.Error("put object", zap.Error(err))
|
||||||
return errorResponse.WithPayload(NewError(err))
|
return errorResponse.WithPayload(util.NewError(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
var resp models.Address
|
var resp models.Address
|
||||||
resp.ContainerID = params.Object.ContainerID
|
resp.ContainerID = params.Object.ContainerID
|
||||||
resp.ObjectID = NewString(objID.String())
|
resp.ObjectID = util.NewString(objID.String())
|
||||||
|
|
||||||
return operations.NewPutObjectOK().WithPayload(&resp)
|
return operations.NewPutObjectOK().WithPayload(&resp)
|
||||||
}
|
}
|
||||||
|
@ -91,7 +92,7 @@ func (a *API) GetObjectInfo(params operations.GetObjectInfoParams, principal *mo
|
||||||
btoken, err := getBearerToken(principal, params.XBearerSignature, params.XBearerSignatureKey, *params.WalletConnect)
|
btoken, err := getBearerToken(principal, params.XBearerSignature, params.XBearerSignatureKey, *params.WalletConnect)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.log.Error("get bearer token", zap.Error(err))
|
a.log.Error("get bearer token", zap.Error(err))
|
||||||
return errorResponse.WithPayload(NewError(err))
|
return errorResponse.WithPayload(util.NewError(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
var prm pool.PrmObjectHead
|
var prm pool.PrmObjectHead
|
||||||
|
@ -101,21 +102,21 @@ func (a *API) GetObjectInfo(params operations.GetObjectInfoParams, principal *mo
|
||||||
objInfo, err := a.pool.HeadObject(ctx, prm)
|
objInfo, err := a.pool.HeadObject(ctx, prm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.log.Error("head object", zap.Error(err))
|
a.log.Error("head object", zap.Error(err))
|
||||||
return errorResponse.WithPayload(NewError(err))
|
return errorResponse.WithPayload(util.NewError(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
var resp models.ObjectInfo
|
var resp models.ObjectInfo
|
||||||
resp.ContainerID = NewString(params.ContainerID)
|
resp.ContainerID = util.NewString(params.ContainerID)
|
||||||
resp.ObjectID = NewString(params.ObjectID)
|
resp.ObjectID = util.NewString(params.ObjectID)
|
||||||
resp.OwnerID = NewString(objInfo.OwnerID().String())
|
resp.OwnerID = util.NewString(objInfo.OwnerID().String())
|
||||||
resp.Attributes = make([]*models.Attribute, len(objInfo.Attributes()))
|
resp.Attributes = make([]*models.Attribute, len(objInfo.Attributes()))
|
||||||
resp.ObjectSize = NewInteger(int64(objInfo.PayloadSize()))
|
resp.ObjectSize = util.NewInteger(int64(objInfo.PayloadSize()))
|
||||||
resp.PayloadSize = NewInteger(0)
|
resp.PayloadSize = util.NewInteger(0)
|
||||||
|
|
||||||
for i, attr := range objInfo.Attributes() {
|
for i, attr := range objInfo.Attributes() {
|
||||||
resp.Attributes[i] = &models.Attribute{
|
resp.Attributes[i] = &models.Attribute{
|
||||||
Key: NewString(attr.Key()),
|
Key: util.NewString(attr.Key()),
|
||||||
Value: NewString(attr.Value()),
|
Value: util.NewString(attr.Value()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,7 +128,7 @@ func (a *API) GetObjectInfo(params operations.GetObjectInfoParams, principal *mo
|
||||||
if params.RangeOffset != nil || params.RangeLength != nil {
|
if params.RangeOffset != nil || params.RangeLength != nil {
|
||||||
if params.RangeOffset == nil || params.RangeLength == nil {
|
if params.RangeOffset == nil || params.RangeLength == nil {
|
||||||
a.log.Error("both offset and length must be provided")
|
a.log.Error("both offset and length must be provided")
|
||||||
return errorResponse.WithPayload(NewError(fmt.Errorf("both offset and length must be provided")))
|
return errorResponse.WithPayload(util.NewError(fmt.Errorf("both offset and length must be provided")))
|
||||||
}
|
}
|
||||||
offset = uint64(*params.RangeOffset)
|
offset = uint64(*params.RangeOffset)
|
||||||
length = uint64(*params.RangeLength)
|
length = uint64(*params.RangeLength)
|
||||||
|
@ -144,7 +145,7 @@ func (a *API) GetObjectInfo(params operations.GetObjectInfoParams, principal *mo
|
||||||
rangeRes, err := a.pool.ObjectRange(ctx, prmRange)
|
rangeRes, err := a.pool.ObjectRange(ctx, prmRange)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.log.Error("range object", zap.Error(err))
|
a.log.Error("range object", zap.Error(err))
|
||||||
return errorResponse.WithPayload(NewError(err))
|
return errorResponse.WithPayload(util.NewError(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
|
@ -158,15 +159,15 @@ func (a *API) GetObjectInfo(params operations.GetObjectInfoParams, principal *mo
|
||||||
payloadSize, err := io.Copy(encoder, rangeRes)
|
payloadSize, err := io.Copy(encoder, rangeRes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.log.Error("encode object payload", zap.Error(err))
|
a.log.Error("encode object payload", zap.Error(err))
|
||||||
return errorResponse.WithPayload(NewError(err))
|
return errorResponse.WithPayload(util.NewError(err))
|
||||||
}
|
}
|
||||||
if err = encoder.Close(); err != nil {
|
if err = encoder.Close(); err != nil {
|
||||||
a.log.Error("close encoder", zap.Error(err))
|
a.log.Error("close encoder", zap.Error(err))
|
||||||
return errorResponse.WithPayload(NewError(err))
|
return errorResponse.WithPayload(util.NewError(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
resp.Payload = sb.String()
|
resp.Payload = sb.String()
|
||||||
resp.PayloadSize = NewInteger(payloadSize)
|
resp.PayloadSize = util.NewInteger(payloadSize)
|
||||||
|
|
||||||
return operations.NewGetObjectInfoOK().WithPayload(&resp)
|
return operations.NewGetObjectInfoOK().WithPayload(&resp)
|
||||||
}
|
}
|
||||||
|
@ -185,7 +186,7 @@ func (a *API) DeleteObject(params operations.DeleteObjectParams, principal *mode
|
||||||
btoken, err := getBearerToken(principal, params.XBearerSignature, params.XBearerSignatureKey, *params.WalletConnect)
|
btoken, err := getBearerToken(principal, params.XBearerSignature, params.XBearerSignatureKey, *params.WalletConnect)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.log.Error("failed to get bearer token", zap.Error(err))
|
a.log.Error("failed to get bearer token", zap.Error(err))
|
||||||
return errorResponse.WithPayload(NewError(err))
|
return errorResponse.WithPayload(util.NewError(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
var prm pool.PrmObjectDelete
|
var prm pool.PrmObjectDelete
|
||||||
|
@ -194,7 +195,7 @@ func (a *API) DeleteObject(params operations.DeleteObjectParams, principal *mode
|
||||||
|
|
||||||
if err = a.pool.DeleteObject(ctx, prm); err != nil {
|
if err = a.pool.DeleteObject(ctx, prm); err != nil {
|
||||||
a.log.Error("failed to delete object", zap.Error(err))
|
a.log.Error("failed to delete object", zap.Error(err))
|
||||||
return errorResponse.WithPayload(NewError(err))
|
return errorResponse.WithPayload(util.NewError(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
return operations.NewDeleteObjectNoContent()
|
return operations.NewDeleteObjectNoContent()
|
||||||
|
@ -214,13 +215,13 @@ func (a *API) SearchObjects(params operations.SearchObjectsParams, principal *mo
|
||||||
btoken, err := getBearerToken(principal, params.XBearerSignature, params.XBearerSignatureKey, *params.WalletConnect)
|
btoken, err := getBearerToken(principal, params.XBearerSignature, params.XBearerSignatureKey, *params.WalletConnect)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.log.Error("failed to get bearer token", zap.Error(err))
|
a.log.Error("failed to get bearer token", zap.Error(err))
|
||||||
return errorResponse.WithPayload(NewError(err))
|
return errorResponse.WithPayload(util.NewError(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
filters, err := ToNativeFilters(params.SearchFilters)
|
filters, err := util.ToNativeFilters(params.SearchFilters)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.log.Error("failed to transform to native", zap.Error(err))
|
a.log.Error("failed to transform to native", zap.Error(err))
|
||||||
return errorResponse.WithPayload(NewError(err))
|
return errorResponse.WithPayload(util.NewError(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
var prm pool.PrmObjectSearch
|
var prm pool.PrmObjectSearch
|
||||||
|
@ -231,7 +232,7 @@ func (a *API) SearchObjects(params operations.SearchObjectsParams, principal *mo
|
||||||
resSearch, err := a.pool.SearchObjects(ctx, prm)
|
resSearch, err := a.pool.SearchObjects(ctx, prm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.log.Error("failed to search objects", zap.Error(err))
|
a.log.Error("failed to search objects", zap.Error(err))
|
||||||
return errorResponse.WithPayload(NewError(err))
|
return errorResponse.WithPayload(util.NewError(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
offset := int(*params.Offset)
|
offset := int(*params.Offset)
|
||||||
|
@ -261,11 +262,11 @@ func (a *API) SearchObjects(params operations.SearchObjectsParams, principal *mo
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.log.Error("failed to search objects", zap.Error(err))
|
a.log.Error("failed to search objects", zap.Error(err))
|
||||||
return errorResponse.WithPayload(NewError(err))
|
return errorResponse.WithPayload(util.NewError(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
list := &models.ObjectList{
|
list := &models.ObjectList{
|
||||||
Size: NewInteger(int64(len(objects))),
|
Size: util.NewInteger(int64(len(objects))),
|
||||||
Objects: objects,
|
Objects: objects,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -288,8 +289,8 @@ func headObjectBaseInfo(ctx context.Context, p *pool.Pool, cnrID *cid.ID, objID
|
||||||
|
|
||||||
resp := &models.ObjectBaseInfo{
|
resp := &models.ObjectBaseInfo{
|
||||||
Address: &models.Address{
|
Address: &models.Address{
|
||||||
ContainerID: NewString(cnrID.String()),
|
ContainerID: util.NewString(cnrID.String()),
|
||||||
ObjectID: NewString(objID.String()),
|
ObjectID: util.NewString(objID.String()),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,9 +9,8 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-rest-gw/gen/models"
|
|
||||||
|
|
||||||
objectv2 "github.com/nspcc-dev/neofs-api-go/v2/object"
|
objectv2 "github.com/nspcc-dev/neofs-api-go/v2/object"
|
||||||
|
"github.com/nspcc-dev/neofs-rest-gw/gen/models"
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/netmap"
|
"github.com/nspcc-dev/neofs-sdk-go/netmap"
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/object"
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/pool"
|
"github.com/nspcc-dev/neofs-sdk-go/pool"
|
||||||
|
@ -217,15 +216,3 @@ func updateExpirationHeader(headers map[string]string, durations *epochDurations
|
||||||
numEpoch := expDuration.Milliseconds() / epochDuration
|
numEpoch := expDuration.Milliseconds() / epochDuration
|
||||||
headers[objectv2.SysAttributeExpEpoch] = strconv.FormatInt(int64(durations.currentEpoch)+numEpoch, 10)
|
headers[objectv2.SysAttributeExpEpoch] = strconv.FormatInt(int64(durations.currentEpoch)+numEpoch, 10)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewString(val string) *string {
|
|
||||||
return &val
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewInteger(val int64) *int64 {
|
|
||||||
return &val
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewError(err error) models.Error {
|
|
||||||
return models.Error(err.Error())
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
package handlers
|
package util
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/object"
|
|
||||||
|
|
||||||
sessionv2 "github.com/nspcc-dev/neofs-api-go/v2/session"
|
sessionv2 "github.com/nspcc-dev/neofs-api-go/v2/session"
|
||||||
"github.com/nspcc-dev/neofs-rest-gw/gen/models"
|
"github.com/nspcc-dev/neofs-rest-gw/gen/models"
|
||||||
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/eacl"
|
"github.com/nspcc-dev/neofs-sdk-go/eacl"
|
||||||
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/session"
|
"github.com/nspcc-dev/neofs-sdk-go/session"
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/token"
|
"github.com/nspcc-dev/neofs-sdk-go/token"
|
||||||
)
|
)
|
||||||
|
@ -429,3 +429,18 @@ func ToNativeFilters(fs *models.SearchFilters) (object.SearchFilters, error) {
|
||||||
|
|
||||||
return filters, nil
|
return filters, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewString returns pointer to provided string.
|
||||||
|
func NewString(val string) *string {
|
||||||
|
return &val
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewInteger returns pointer to provided int.
|
||||||
|
func NewInteger(val int64) *int64 {
|
||||||
|
return &val
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewError wraps error into models.Error.
|
||||||
|
func NewError(err error) models.Error {
|
||||||
|
return models.Error(err.Error())
|
||||||
|
}
|
|
@ -3,12 +3,13 @@ package walletconnect
|
||||||
import (
|
import (
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
"testing"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
"github.com/nspcc-dev/neofs-rest-gw/gen/models"
|
"github.com/nspcc-dev/neofs-rest-gw/gen/models"
|
||||||
"github.com/nspcc-dev/neofs-rest-gw/handlers"
|
"github.com/nspcc-dev/neofs-rest-gw/internal/util"
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/owner"
|
"github.com/nspcc-dev/neofs-sdk-go/owner"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const devenvPrivateKey = "1dd37fba80fec4e6a6f13fd708d8dcb3b29def768017052f6c930fa1c5d90bbb"
|
const devenvPrivateKey = "1dd37fba80fec4e6a6f13fd708d8dcb3b29def768017052f6c930fa1c5d90bbb"
|
||||||
|
@ -31,7 +32,7 @@ func TestSign(t *testing.T) {
|
||||||
}},
|
}},
|
||||||
}
|
}
|
||||||
|
|
||||||
btoken, err := handlers.ToNativeObjectToken(b)
|
btoken, err := util.ToNativeObjectToken(b)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
ownerKey, err := keys.NewPublicKeyFromString(pubKeyHex)
|
ownerKey, err := keys.NewPublicKeyFromString(pubKeyHex)
|
Loading…
Reference in a new issue