From fffb0b2f12d09974f26773b523191416173d13e8 Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Tue, 15 Jun 2021 11:28:30 +0300 Subject: [PATCH] [#63] Using client.Object from sdk Signed-off-by: Denis Kirillov --- downloader/download.go | 35 ++++------------------------------- go.mod | 2 +- go.sum | 2 ++ uploader/upload.go | 13 +------------ 4 files changed, 8 insertions(+), 44 deletions(-) diff --git a/downloader/download.go b/downloader/download.go index ab0b762..75c5f8a 100644 --- a/downloader/download.go +++ b/downloader/download.go @@ -15,7 +15,6 @@ import ( "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/session" "github.com/nspcc-dev/neofs-http-gw/tokens" "github.com/nspcc-dev/neofs-sdk-go/pkg/pool" "github.com/valyala/fasthttp" @@ -72,9 +71,7 @@ func isValidValue(s string) bool { return true } -func (r *request) receiveFile(clnt client.Object, - sessionToken *session.Token, - objectAddress *object.Address) { +func (r *request) receiveFile(clnt client.Object, objectAddress *object.Address) { var ( err error dis = "inline" @@ -95,7 +92,6 @@ func (r *request) receiveFile(clnt client.Object, obj, err = clnt.GetObject( r.RequestCtx, options, - client.WithSession(sessionToken), ) if err != nil { r.log.Error( @@ -194,8 +190,6 @@ func (d *Downloader) DownloadByAddress(c *fasthttp.RequestCtx) { oid, _ = c.UserValue("oid").(string) val = strings.Join([]string{cid, oid}, "/") log = d.log.With(zap.String("cid", cid), zap.String("oid", oid)) - conn client.Object - tkn *session.Token ) if err = address.Parse(val); err != nil { log.Error("wrong object address", zap.Error(err)) @@ -203,13 +197,7 @@ func (d *Downloader) DownloadByAddress(c *fasthttp.RequestCtx) { return } - conn, tkn, err = d.pool.Connection() - if err != nil { - log.Error("failed to get neofs connection artifacts", zap.Error(err)) - c.Error("failed to get neofs connection artifacts", fasthttp.StatusInternalServerError) - return - } - d.newRequest(c, log).receiveFile(conn, tkn, address) + d.newRequest(c, log).receiveFile(d.pool, address) } // DownloadByAttribute handles attribute-based download requests. @@ -221,8 +209,6 @@ func (d *Downloader) DownloadByAttribute(c *fasthttp.RequestCtx) { val, _ = c.UserValue("attr_val").(string) log = d.log.With(zap.String("cid", scid), zap.String("attr_key", key), zap.String("attr_val", val)) ids []*object.ID - conn client.Object - tkn *session.Token ) cid := cid.New() if err = cid.Parse(scid); err != nil { @@ -231,19 +217,12 @@ func (d *Downloader) DownloadByAttribute(c *fasthttp.RequestCtx) { return } - conn, tkn, err = d.pool.Connection() - if err != nil { - log.Error("failed to get neofs connection artifacts", zap.Error(err)) - c.Error("failed to get neofs connection artifacts", fasthttp.StatusInternalServerError) - return - } - options := object.NewSearchFilters() options.AddRootFilter() options.AddFilter(key, val, object.MatchStringEqual) sops := new(client.SearchObjectParams).WithContainerID(cid).WithSearchFilters(options) - if ids, err = conn.SearchObject(c, sops, client.WithSession(tkn)); err != nil { + if ids, err = d.pool.SearchObject(c, sops); err != nil { log.Error("something went wrong", zap.Error(err)) c.Error("something went wrong", fasthttp.StatusBadRequest) return @@ -261,11 +240,5 @@ func (d *Downloader) DownloadByAttribute(c *fasthttp.RequestCtx) { address.SetContainerID(cid) address.SetObjectID(ids[0]) - conn, tkn, err = d.pool.Connection() - if err != nil { - log.Error("failed to get neofs connection artifacts", zap.Error(err)) - c.Error("failed to get neofs connection artifacts", fasthttp.StatusInternalServerError) - return - } - d.newRequest(c, log).receiveFile(conn, tkn, address) + d.newRequest(c, log).receiveFile(d.pool, address) } diff --git a/go.mod b/go.mod index 2aaa8e3..2ad26ef 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/mr-tron/base58 v1.1.3 // indirect github.com/nspcc-dev/neofs-api-go v1.27.0 github.com/nspcc-dev/neofs-crypto v0.3.0 - github.com/nspcc-dev/neofs-sdk-go v0.0.0-20210609143631-0d3c078a0d9b + github.com/nspcc-dev/neofs-sdk-go v0.0.0-20210615074944-86a9aa92599b github.com/prometheus/client_golang v1.9.0 github.com/prometheus/common v0.15.0 github.com/spf13/pflag v1.0.5 diff --git a/go.sum b/go.sum index 90c40de..03868e3 100644 --- a/go.sum +++ b/go.sum @@ -321,6 +321,8 @@ github.com/nspcc-dev/neofs-crypto v0.3.0 h1:zlr3pgoxuzrmGCxc5W8dGVfA9Rro8diFvVnB github.com/nspcc-dev/neofs-crypto v0.3.0/go.mod h1:8w16GEJbH6791ktVqHN9YRNH3s9BEEKYxGhlFnp0cDw= github.com/nspcc-dev/neofs-sdk-go v0.0.0-20210609143631-0d3c078a0d9b h1:2alc6tGPHScEATOxlrYuHCTl+DbhVaqigT5Bo1QXY90= github.com/nspcc-dev/neofs-sdk-go v0.0.0-20210609143631-0d3c078a0d9b/go.mod h1:1djNrOkpTTbNUlJM/MvTmohJUaWKUMy9JHSCCA8rJEc= +github.com/nspcc-dev/neofs-sdk-go v0.0.0-20210615074944-86a9aa92599b h1:l99sCKR/mt+iFb4p1836qtoXUQEGYlEzqWAeAliEaE8= +github.com/nspcc-dev/neofs-sdk-go v0.0.0-20210615074944-86a9aa92599b/go.mod h1:1djNrOkpTTbNUlJM/MvTmohJUaWKUMy9JHSCCA8rJEc= 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/uploader/upload.go b/uploader/upload.go index e8f9735..f43dfb2 100644 --- a/uploader/upload.go +++ b/uploader/upload.go @@ -11,7 +11,6 @@ import ( 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/session" "github.com/nspcc-dev/neofs-api-go/pkg/token" "github.com/nspcc-dev/neofs-http-gw/tokens" "github.com/nspcc-dev/neofs-sdk-go/pkg/pool" @@ -43,8 +42,6 @@ func (u *Uploader) Upload(c *fasthttp.RequestCtx) { err error file MultipartFile obj *object.ID - conn client.Object - tkn *session.Token addr = object.NewAddress() cid = cid.New() scid, _ = c.UserValue("cid").(string) @@ -106,14 +103,6 @@ func (u *Uploader) Upload(c *fasthttp.RequestCtx) { } oid, bt := u.fetchOwnerAndBearerToken(c) - // Try to put file into NeoFS or throw an error. - conn, tkn, err = u.pool.Connection() - if err != nil { - log.Error("failed to get neofs connection artifacts", zap.Error(err)) - c.Error("failed to get neofs connection artifacts", fasthttp.StatusInternalServerError) - return - } - rawObject := object.NewRaw() rawObject.SetContainerID(cid) rawObject.SetOwnerID(oid) @@ -121,7 +110,7 @@ func (u *Uploader) Upload(c *fasthttp.RequestCtx) { ops := new(client.PutObjectParams).WithObject(rawObject.Object()).WithPayloadReader(file) - if obj, err = conn.PutObject(c, ops, client.WithSession(tkn), client.WithBearer(bt)); err != nil { + if obj, err = u.pool.PutObject(c, ops, client.WithBearer(bt)); err != nil { log.Error("could not store file in neofs", zap.Error(err)) c.Error("could not store file in neofs", fasthttp.StatusBadRequest) return