From 0284bf136b466667a32b20c3f6bad4e93afe1dda Mon Sep 17 00:00:00 2001 From: Evgeniy Kulikov Date: Tue, 24 Nov 2020 12:17:36 +0300 Subject: [PATCH] Migrate to Credentials client Signed-off-by: Evgeniy Kulikov --- api/auth/center.go | 17 ++++------------- api/layer/object.go | 4 +--- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/api/auth/center.go b/api/auth/center.go index b67524150..bd851df1f 100644 --- a/api/auth/center.go +++ b/api/auth/center.go @@ -15,7 +15,6 @@ import ( "github.com/aws/aws-sdk-go/aws/credentials" v4 "github.com/aws/aws-sdk-go/aws/signer/v4" sdk "github.com/nspcc-dev/cdn-neofs-sdk" - "github.com/nspcc-dev/cdn-neofs-sdk/creds/accessbox" "github.com/nspcc-dev/cdn-neofs-sdk/creds/hcs" "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-api-go/pkg/token" @@ -85,20 +84,12 @@ func (c *center) Authenticate(r *http.Request) (*token.BearerToken, error) { return nil, errors.Wrapf(err, "could not parse AccessBox address: %s", accessKeyID) } - buf := new(bytes.Buffer) - if _, err = c.cli.Object().Get(r.Context(), address, sdk.WithGetWriter(buf)); err != nil { - return nil, errors.Wrapf(err, "could not fetch AccessBox: %s (%s / %s)", - accessKeyID, - address.ContainerID(), - address.ObjectID()) - } - - box := accessbox.NewBearerBox(nil) - if err = accessbox.NewDecoder(buf, c.key).Decode(box); err != nil { + tkn, err := c.cli.Credentials().BearerToken(r.Context(), address, c.key) + if err != nil { return nil, err } - data, err := box.Token().Marshal() + data, err := tkn.Marshal() if err != nil { return nil, err } @@ -135,7 +126,7 @@ func (c *center) Authenticate(r *http.Request) (*token.BearerToken, error) { return nil, errors.Wrap(err, "failed to pass authentication procedure") } - return box.Token(), nil + return tkn, nil } // TODO: Make this write into a smart buffer backed by a file on a fast drive. diff --git a/api/layer/object.go b/api/layer/object.go index 5797959bf..e79793ab3 100644 --- a/api/layer/object.go +++ b/api/layer/object.go @@ -10,12 +10,10 @@ import ( "strconv" "time" - "github.com/nspcc-dev/neofs-api-go/pkg/token" - 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/object" + "github.com/nspcc-dev/neofs-api-go/pkg/token" "github.com/nspcc-dev/neofs-s3-gate/api" "github.com/pkg/errors" "google.golang.org/grpc/codes"