From 79765fb7cc50d6a780af4021a56633e498ac238f Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Mon, 15 Nov 2021 14:12:15 +0300 Subject: [PATCH] [#106] Update neofs-sdk-go to the latest version Includes: - fix for unavailable endpoints of client pool, - session token cache with request retry in case of missing session token, - migrated neofs client. Signed-off-by: Alex Vanin --- app.go | 4 ++-- downloader/download.go | 20 ++++++++++---------- downloader/head.go | 7 ++++--- go.mod | 3 +-- go.sum | 5 ++--- integration_test.go | 12 ++++++------ main.go | 2 +- tokens/bearer-token.go | 2 +- tokens/bearer-token_test.go | 4 ++-- uploader/filter_test.go | 2 +- uploader/upload.go | 14 +++++++------- 11 files changed, 37 insertions(+), 38 deletions(-) diff --git a/app.go b/app.go index 7dacb18..9b6849d 100644 --- a/app.go +++ b/app.go @@ -15,8 +15,8 @@ import ( "github.com/nspcc-dev/neofs-http-gw/downloader" "github.com/nspcc-dev/neofs-http-gw/response" "github.com/nspcc-dev/neofs-http-gw/uploader" - "github.com/nspcc-dev/neofs-sdk-go/pkg/logger" - "github.com/nspcc-dev/neofs-sdk-go/pkg/pool" + "github.com/nspcc-dev/neofs-sdk-go/logger" + "github.com/nspcc-dev/neofs-sdk-go/pool" "github.com/spf13/viper" "github.com/valyala/fasthttp" "go.uber.org/zap" diff --git a/downloader/download.go b/downloader/download.go index 5d50fe9..13027a3 100644 --- a/downloader/download.go +++ b/downloader/download.go @@ -12,12 +12,12 @@ import ( "strings" "time" - "github.com/nspcc-dev/neofs-api-go/pkg/client" - cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id" - "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-http-gw/response" "github.com/nspcc-dev/neofs-http-gw/tokens" - "github.com/nspcc-dev/neofs-sdk-go/pkg/pool" + "github.com/nspcc-dev/neofs-sdk-go/client" + cid "github.com/nspcc-dev/neofs-sdk-go/container/id" + "github.com/nspcc-dev/neofs-sdk-go/object" + "github.com/nspcc-dev/neofs-sdk-go/pool" "github.com/valyala/fasthttp" "go.uber.org/zap" ) @@ -114,7 +114,7 @@ func isValidValue(s string) bool { return true } -func (r request) receiveFile(clnt client.Object, objectAddress *object.Address) { +func (r request) receiveFile(clnt pool.Object, objectAddress *object.Address) { var ( err error dis = "inline" @@ -189,11 +189,11 @@ func (r request) receiveFile(clnt client.Object, objectAddress *object.Address) r.Response.Header.Set("Content-Disposition", dis+"; filename="+path.Base(filename)) } -func bearerOpts(ctx context.Context) client.CallOption { +func bearerOpts(ctx context.Context) pool.CallOption { if tkn, err := tokens.LoadBearerToken(ctx); err == nil { - return client.WithBearer(tkn) + return pool.WithBearer(tkn) } - return client.WithBearer(nil) + return pool.WithBearer(nil) } func (r *request) handleNeoFSErr(err error, start time.Time) { @@ -263,7 +263,7 @@ func (d *Downloader) DownloadByAddress(c *fasthttp.RequestCtx) { // byAddress is wrapper for function (e.g. request.headObject, request.receiveFile) that // prepares request and object address to it. -func (d *Downloader) byAddress(c *fasthttp.RequestCtx, f func(request, client.Object, *object.Address)) { +func (d *Downloader) byAddress(c *fasthttp.RequestCtx, f func(request, pool.Object, *object.Address)) { var ( address = object.NewAddress() cid, _ = c.UserValue("cid").(string) @@ -286,7 +286,7 @@ func (d *Downloader) DownloadByAttribute(c *fasthttp.RequestCtx) { } // byAttribute is wrapper similar to byAddress. -func (d *Downloader) byAttribute(c *fasthttp.RequestCtx, f func(request, client.Object, *object.Address)) { +func (d *Downloader) byAttribute(c *fasthttp.RequestCtx, f func(request, pool.Object, *object.Address)) { var ( httpStatus = fasthttp.StatusBadRequest scid, _ = c.UserValue("cid").(string) diff --git a/downloader/head.go b/downloader/head.go index 2a80129..67cc04e 100644 --- a/downloader/head.go +++ b/downloader/head.go @@ -5,17 +5,18 @@ import ( "strconv" "time" - "github.com/nspcc-dev/neofs-api-go/pkg/client" - "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-http-gw/response" "github.com/nspcc-dev/neofs-http-gw/tokens" + "github.com/nspcc-dev/neofs-sdk-go/client" + "github.com/nspcc-dev/neofs-sdk-go/object" + "github.com/nspcc-dev/neofs-sdk-go/pool" "github.com/valyala/fasthttp" "go.uber.org/zap" ) const sizeToDetectType = 512 -func (r request) headObject(clnt client.Object, objectAddress *object.Address) { +func (r request) headObject(clnt pool.Object, objectAddress *object.Address) { var start = time.Now() if err := tokens.StoreBearerToken(r.RequestCtx); err != nil { r.log.Error("could not fetch and store bearer token", zap.Error(err)) diff --git a/go.mod b/go.mod index 094d8fd..1c5a056 100644 --- a/go.mod +++ b/go.mod @@ -15,8 +15,7 @@ require ( github.com/google/uuid v1.3.0 // indirect github.com/klauspost/compress v1.13.1 // indirect github.com/nspcc-dev/neo-go v0.96.1 - github.com/nspcc-dev/neofs-api-go v1.30.0 - github.com/nspcc-dev/neofs-sdk-go v0.0.0-20210728093755-d95d722d6156 + github.com/nspcc-dev/neofs-sdk-go v0.0.0-20211115110427-df6a622c20e8 github.com/prometheus/client_golang v1.11.0 github.com/prometheus/common v0.29.0 github.com/prometheus/procfs v0.7.1 // indirect diff --git a/go.sum b/go.sum index 669c380..a825e4f 100644 --- a/go.sum +++ b/go.sum @@ -612,15 +612,14 @@ github.com/nspcc-dev/neo-go v0.96.1 h1:JaKWvM/vvQ48bq2ADNj7zH/6Ek38Iqxo22hdu2lhx github.com/nspcc-dev/neo-go v0.96.1/go.mod h1:yguwQBpWMTHx07INKoElJT8Gga1LUdTSi0gT75ywJ68= github.com/nspcc-dev/neofs-api-go v1.24.0/go.mod h1:G7dqincfdjBrAbL5nxVp82emF05fSVEqe59ICsoRDI8= github.com/nspcc-dev/neofs-api-go v1.27.1/go.mod h1:i0Cwgvcu9A4M4e58pydbXFisUhSxpfljmuWFPIp2btE= -github.com/nspcc-dev/neofs-api-go v1.28.3/go.mod h1:YRIzUqBj/lGbmFm8mmCh54ZOzcJKkEIhv2s7ZvSLv3M= github.com/nspcc-dev/neofs-api-go v1.30.0 h1:Nns7QjmQGk9I5lWMCtmeD9D3de46uyH3H07WBeXTEI0= github.com/nspcc-dev/neofs-api-go v1.30.0/go.mod h1:KC8T91skIg8juvUh7lQabswQ9J6KmnXErpH8qwDitXA= github.com/nspcc-dev/neofs-crypto v0.2.0/go.mod h1:F/96fUzPM3wR+UGsPi3faVNmFlA9KAEAUQR7dMxZmNA= github.com/nspcc-dev/neofs-crypto v0.2.3/go.mod h1:8w16GEJbH6791ktVqHN9YRNH3s9BEEKYxGhlFnp0cDw= github.com/nspcc-dev/neofs-crypto v0.3.0 h1:zlr3pgoxuzrmGCxc5W8dGVfA9Rro8diFvVnBg0L4ifM= github.com/nspcc-dev/neofs-crypto v0.3.0/go.mod h1:8w16GEJbH6791ktVqHN9YRNH3s9BEEKYxGhlFnp0cDw= -github.com/nspcc-dev/neofs-sdk-go v0.0.0-20210728093755-d95d722d6156 h1:HiCIiXmv9HEbJh6okyW/8OCLNn8r3AbvgmBUtKh+8wE= -github.com/nspcc-dev/neofs-sdk-go v0.0.0-20210728093755-d95d722d6156/go.mod h1:NOjwgDKeU8ZoXO0k2cwMi5HV3BRJVJLLaXrYpVjF1LU= +github.com/nspcc-dev/neofs-sdk-go v0.0.0-20211115110427-df6a622c20e8 h1:nhJSZwE2qbrCrVq4TsHlqYlwXePpqD7BsoEsu4TY5vs= +github.com/nspcc-dev/neofs-sdk-go v0.0.0-20211115110427-df6a622c20e8/go.mod h1:kISVlyRa5l6UIDFigT2AZSW7yUK0QOEmd5mw9WPeYVI= github.com/nspcc-dev/rfc6979 v0.1.0/go.mod h1:exhIh1PdpDC5vQmyEsGvc4YDM/lyQp/452QxGq/UEso= github.com/nspcc-dev/rfc6979 v0.2.0 h1:3e1WNxrN60/6N0DW7+UYisLeZJyfqZTNOjeV/toYvOE= github.com/nspcc-dev/rfc6979 v0.2.0/go.mod h1:exhIh1PdpDC5vQmyEsGvc4YDM/lyQp/452QxGq/UEso= diff --git a/integration_test.go b/integration_test.go index cb9ebd1..5bb0733 100644 --- a/integration_test.go +++ b/integration_test.go @@ -16,12 +16,12 @@ import ( "time" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" - "github.com/nspcc-dev/neofs-api-go/pkg/client" - "github.com/nspcc-dev/neofs-api-go/pkg/container" - cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id" - "github.com/nspcc-dev/neofs-api-go/pkg/object" - "github.com/nspcc-dev/neofs-sdk-go/pkg/policy" - "github.com/nspcc-dev/neofs-sdk-go/pkg/pool" + "github.com/nspcc-dev/neofs-sdk-go/client" + "github.com/nspcc-dev/neofs-sdk-go/container" + cid "github.com/nspcc-dev/neofs-sdk-go/container/id" + "github.com/nspcc-dev/neofs-sdk-go/object" + "github.com/nspcc-dev/neofs-sdk-go/policy" + "github.com/nspcc-dev/neofs-sdk-go/pool" "github.com/spf13/viper" "github.com/stretchr/testify/require" "github.com/testcontainers/testcontainers-go" diff --git a/main.go b/main.go index 830a26f..966904c 100644 --- a/main.go +++ b/main.go @@ -5,7 +5,7 @@ import ( "os/signal" "syscall" - "github.com/nspcc-dev/neofs-sdk-go/pkg/logger" + "github.com/nspcc-dev/neofs-sdk-go/logger" "github.com/spf13/viper" "go.uber.org/zap" ) diff --git a/tokens/bearer-token.go b/tokens/bearer-token.go index c7d16bc..48b109e 100644 --- a/tokens/bearer-token.go +++ b/tokens/bearer-token.go @@ -7,7 +7,7 @@ import ( "errors" "fmt" - "github.com/nspcc-dev/neofs-api-go/pkg/token" + "github.com/nspcc-dev/neofs-sdk-go/token" "github.com/valyala/fasthttp" ) diff --git a/tokens/bearer-token_test.go b/tokens/bearer-token_test.go index f038014..54258c2 100644 --- a/tokens/bearer-token_test.go +++ b/tokens/bearer-token_test.go @@ -4,8 +4,8 @@ import ( "encoding/base64" "testing" - "github.com/nspcc-dev/neofs-api-go/pkg/owner" - "github.com/nspcc-dev/neofs-api-go/pkg/token" + "github.com/nspcc-dev/neofs-sdk-go/owner" + "github.com/nspcc-dev/neofs-sdk-go/token" "github.com/stretchr/testify/require" "github.com/valyala/fasthttp" ) diff --git a/uploader/filter_test.go b/uploader/filter_test.go index 6e04270..9cfb435 100644 --- a/uploader/filter_test.go +++ b/uploader/filter_test.go @@ -3,7 +3,7 @@ package uploader import ( "testing" - "github.com/nspcc-dev/neofs-sdk-go/pkg/logger" + "github.com/nspcc-dev/neofs-sdk-go/logger" "github.com/stretchr/testify/require" "github.com/valyala/fasthttp" ) diff --git a/uploader/upload.go b/uploader/upload.go index 1833fa9..35ef30c 100644 --- a/uploader/upload.go +++ b/uploader/upload.go @@ -7,14 +7,14 @@ import ( "strconv" "time" - "github.com/nspcc-dev/neofs-api-go/pkg/client" - cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id" - "github.com/nspcc-dev/neofs-api-go/pkg/object" - "github.com/nspcc-dev/neofs-api-go/pkg/owner" - "github.com/nspcc-dev/neofs-api-go/pkg/token" "github.com/nspcc-dev/neofs-http-gw/response" "github.com/nspcc-dev/neofs-http-gw/tokens" - "github.com/nspcc-dev/neofs-sdk-go/pkg/pool" + "github.com/nspcc-dev/neofs-sdk-go/client" + cid "github.com/nspcc-dev/neofs-sdk-go/container/id" + "github.com/nspcc-dev/neofs-sdk-go/object" + "github.com/nspcc-dev/neofs-sdk-go/owner" + "github.com/nspcc-dev/neofs-sdk-go/pool" + "github.com/nspcc-dev/neofs-sdk-go/token" "github.com/valyala/fasthttp" "go.uber.org/zap" ) @@ -111,7 +111,7 @@ func (u *Uploader) Upload(c *fasthttp.RequestCtx) { ops := new(client.PutObjectParams).WithObject(rawObject.Object()).WithPayloadReader(file) - if obj, err = u.pool.PutObject(c, ops, client.WithBearer(bt)); err != nil { + if obj, err = u.pool.PutObject(c, ops, pool.WithBearer(bt)); err != nil { log.Error("could not store file in neofs", zap.Error(err)) response.Error(c, "could not store file in neofs", fasthttp.StatusBadRequest) return