Refactoring api/auth package

Migrate to cred/bearer instead of CredentialsClient

Signed-off-by: Evgeniy Kulikov <kim@nspcc.ru>
This commit is contained in:
Evgeniy Kulikov 2020-11-24 19:31:57 +03:00
parent 0284bf136b
commit 1cd636a24b
2 changed files with 6 additions and 7 deletions

View file

@ -15,6 +15,7 @@ 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/bearer"
"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"
@ -30,9 +31,8 @@ type (
} }
center struct { center struct {
cli sdk.Client
key hcs.PrivateKey
reg *regexpSubmatcher reg *regexpSubmatcher
cli bearer.Credentials
} }
Params struct { Params struct {
@ -43,10 +43,9 @@ type (
) )
// New creates an instance of AuthCenter. // New creates an instance of AuthCenter.
func New(cli sdk.Client, key hcs.PrivateKey) Center { func New(obj sdk.ObjectClient, key hcs.PrivateKey) Center {
return &center{ return &center{
cli: cli, cli: bearer.New(obj, key),
key: key,
reg: &regexpSubmatcher{re: authorizationFieldRegexp}, reg: &regexpSubmatcher{re: authorizationFieldRegexp},
} }
} }
@ -84,7 +83,7 @@ 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)
} }
tkn, err := c.cli.Credentials().BearerToken(r.Context(), address, c.key) tkn, err := c.cli.Get(r.Context(), address)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

@ -157,7 +157,7 @@ func newApp(ctx context.Context, l *zap.Logger, v *viper.Viper) *App {
obj = layer.NewLayer(l, cli) obj = layer.NewLayer(l, cli)
// prepare auth center // prepare auth center
ctr = auth.New(cli, hcsCred.PrivateKey()) ctr = auth.New(cli.Object(), hcsCred.PrivateKey())
if caller, err = handler.New(l, obj); err != nil { if caller, err = handler.New(l, obj); err != nil {
l.Fatal("could not initialize API handler", zap.Error(err)) l.Fatal("could not initialize API handler", zap.Error(err))