Migrate api/layer to SDK

Signed-off-by: Evgeniy Kulikov <kim@nspcc.ru>
This commit is contained in:
Evgeniy Kulikov 2020-11-24 10:01:38 +03:00
parent e3b1e8f369
commit 0ee3a5f9ba
4 changed files with 72 additions and 215 deletions

View file

@ -5,11 +5,11 @@ import (
"strconv"
"time"
"github.com/nspcc-dev/neofs-api-go/pkg/client"
sdk "github.com/nspcc-dev/cdn-neofs-sdk"
"github.com/nspcc-dev/neofs-api-go/pkg/container"
"github.com/nspcc-dev/neofs-api-go/pkg/owner"
"github.com/nspcc-dev/neofs-api-go/pkg/token"
"github.com/nspcc-dev/neofs-s3-gate/api"
"github.com/nspcc-dev/neofs-s3-gate/auth"
"go.uber.org/zap"
)
@ -32,6 +32,8 @@ type (
func (n *layer) containerInfo(ctx context.Context, cid *container.ID) (*BucketInfo, error) {
var (
err error
res *container.Container
rid = api.GetRequestID(ctx)
info = &BucketInfo{
@ -40,29 +42,7 @@ func (n *layer) containerInfo(ctx context.Context, cid *container.ID) (*BucketIn
}
)
bearer, err := auth.GetBearerToken(ctx)
if err != nil {
n.log.Error("could not receive bearer token",
zap.Stringer("cid", cid),
zap.String("request_id", rid),
zap.Error(err))
return nil, err
}
_ = bearer
cli, tkn, err := n.prepareClient(ctx)
if err != nil {
n.log.Error("could not prepare client",
zap.Stringer("cid", cid),
zap.String("request_id", rid),
zap.Error(err))
return nil, err
}
res, err := cli.GetContainer(ctx, cid, client.WithSession(tkn))
if err != nil {
if res, err = n.cli.Container().Get(ctx, cid); err != nil {
n.log.Error("could not fetch container",
zap.Stringer("cid", cid),
zap.String("request_id", rid),
@ -71,14 +51,14 @@ func (n *layer) containerInfo(ctx context.Context, cid *container.ID) (*BucketIn
return nil, err
}
info.Owner = owner.NewIDFromV2(res.GetOwnerID())
info.Owner = res.OwnerID()
for _, attr := range res.GetAttributes() {
switch key, val := attr.GetKey(), attr.GetValue(); key {
for _, attr := range res.Attributes() {
switch key, val := attr.Key(), attr.Value(); key {
case container.AttributeName:
info.Name = val
case container.AttributeTimestamp:
unix, err := strconv.ParseInt(attr.GetValue(), 10, 64)
unix, err := strconv.ParseInt(attr.Value(), 10, 64)
if err != nil {
n.log.Error("could not parse container creation time",
zap.Stringer("cid", cid),
@ -97,34 +77,20 @@ func (n *layer) containerInfo(ctx context.Context, cid *container.ID) (*BucketIn
}
func (n *layer) containerList(ctx context.Context) ([]*BucketInfo, error) {
rid := api.GetRequestID(ctx)
bearer, err := auth.GetBearerToken(ctx)
if err != nil {
var (
err error
tkn *token.BearerToken
rid = api.GetRequestID(ctx)
)
if tkn, err = sdk.BearerToken(ctx); err != nil {
n.log.Error("could not receive bearer token",
zap.String("request_id", rid),
zap.Error(err))
return nil, err
}
_ = bearer
cli, tkn, err := n.prepareClient(ctx)
if err != nil {
n.log.Error("could not prepare client",
zap.String("request_id", rid),
zap.Error(err))
return nil, err
}
// own, err := GetOwnerID(bearer)
// if err != nil {
// n.log.Error("could not fetch owner id",
// zap.String("request_id", rid),
// zap.Error(err))
// return nil, err
// }
res, err := cli.ListContainers(ctx, tkn.OwnerID(), client.WithSession(tkn))
res, err := n.cli.Container().List(ctx, tkn.Issuer())
if err != nil {
n.log.Error("could not fetch container",
zap.String("request_id", rid),