From 1cd636a24bde4e8c4e873d5c15864b92b98406b9 Mon Sep 17 00:00:00 2001 From: Evgeniy Kulikov Date: Tue, 24 Nov 2020 19:31:57 +0300 Subject: [PATCH] Refactoring api/auth package Migrate to cred/bearer instead of CredentialsClient Signed-off-by: Evgeniy Kulikov --- api/auth/center.go | 11 +++++------ cmd/gate/app.go | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/api/auth/center.go b/api/auth/center.go index bd851df1..1a7a82ea 100644 --- a/api/auth/center.go +++ b/api/auth/center.go @@ -15,6 +15,7 @@ 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/bearer" "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" @@ -30,9 +31,8 @@ type ( } center struct { - cli sdk.Client - key hcs.PrivateKey reg *regexpSubmatcher + cli bearer.Credentials } Params struct { @@ -43,10 +43,9 @@ type ( ) // 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 ¢er{ - cli: cli, - key: key, + cli: bearer.New(obj, key), reg: ®expSubmatcher{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) } - tkn, err := c.cli.Credentials().BearerToken(r.Context(), address, c.key) + tkn, err := c.cli.Get(r.Context(), address) if err != nil { return nil, err } diff --git a/cmd/gate/app.go b/cmd/gate/app.go index 4dcc4485..bc183bfc 100644 --- a/cmd/gate/app.go +++ b/cmd/gate/app.go @@ -157,7 +157,7 @@ func newApp(ctx context.Context, l *zap.Logger, v *viper.Viper) *App { obj = layer.NewLayer(l, cli) // 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 { l.Fatal("could not initialize API handler", zap.Error(err))