Migrate to Credentials client

Signed-off-by: Evgeniy Kulikov <kim@nspcc.ru>
This commit is contained in:
Evgeniy Kulikov 2020-11-24 12:17:36 +03:00
parent c1c8d56de5
commit 0284bf136b
2 changed files with 5 additions and 16 deletions

View file

@ -15,7 +15,6 @@ import (
"github.com/aws/aws-sdk-go/aws/credentials" "github.com/aws/aws-sdk-go/aws/credentials"
v4 "github.com/aws/aws-sdk-go/aws/signer/v4" v4 "github.com/aws/aws-sdk-go/aws/signer/v4"
sdk "github.com/nspcc-dev/cdn-neofs-sdk" 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/cdn-neofs-sdk/creds/hcs"
"github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-api-go/pkg/object"
"github.com/nspcc-dev/neofs-api-go/pkg/token" "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) return nil, errors.Wrapf(err, "could not parse AccessBox address: %s", accessKeyID)
} }
buf := new(bytes.Buffer) tkn, err := c.cli.Credentials().BearerToken(r.Context(), address, c.key)
if _, err = c.cli.Object().Get(r.Context(), address, sdk.WithGetWriter(buf)); err != nil { if 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 {
return nil, err return nil, err
} }
data, err := box.Token().Marshal() data, err := tkn.Marshal()
if err != nil { if err != nil {
return nil, err 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 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. // TODO: Make this write into a smart buffer backed by a file on a fast drive.

View file

@ -10,12 +10,10 @@ import (
"strconv" "strconv"
"time" "time"
"github.com/nspcc-dev/neofs-api-go/pkg/token"
sdk "github.com/nspcc-dev/cdn-neofs-sdk" 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/container"
"github.com/nspcc-dev/neofs-api-go/pkg/object" "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/nspcc-dev/neofs-s3-gate/api"
"github.com/pkg/errors" "github.com/pkg/errors"
"google.golang.org/grpc/codes" "google.golang.org/grpc/codes"