From fba29a9a66920b2d8dd8b9ef3e0077d027e76af0 Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Tue, 15 Jun 2021 11:51:42 +0300 Subject: [PATCH] [#78] Using client.Object from sdk Signed-off-by: Denis Kirillov --- api/layer/layer.go | 6 +----- api/layer/object.go | 31 +++++-------------------------- creds/tokens/credentials.go | 14 ++------------ go.mod | 2 +- go.sum | 2 ++ 5 files changed, 11 insertions(+), 44 deletions(-) diff --git a/api/layer/layer.go b/api/layer/layer.go index ee4ff481..59ac8934 100644 --- a/api/layer/layer.go +++ b/api/layer/layer.go @@ -115,12 +115,8 @@ func (n *layer) Owner(ctx context.Context) *owner.ID { // Get NeoFS Object by refs.Address (should be used by auth.Center). func (n *layer) Get(ctx context.Context, address *object.Address) (*object.Object, error) { - conn, tok, err := n.pool.Connection() - if err != nil { - return nil, err - } ops := new(client.GetObjectParams).WithAddress(address) - return conn.GetObject(ctx, ops, client.WithSession(tok)) + return n.pool.GetObject(ctx, ops) } // GetBucketInfo returns bucket info by name. diff --git a/api/layer/object.go b/api/layer/object.go index b13fb43b..0716f2ea 100644 --- a/api/layer/object.go +++ b/api/layer/object.go @@ -42,11 +42,7 @@ func (n *layer) objectSearch(ctx context.Context, p *findParams) ([]*object.ID, } else if filename != "" { opts.AddFilter(object.AttributeFileName, filename, object.MatchStringEqual) } - conn, _, err := n.pool.Connection() - if err != nil { - return nil, err - } - return conn.SearchObject(ctx, new(client.SearchObjectParams).WithContainerID(p.cid).WithSearchFilters(opts)) + return n.pool.SearchObject(ctx, new(client.SearchObjectParams).WithContainerID(p.cid).WithSearchFilters(opts)) } // objectFindID returns object id (uuid) based on it's nice name in s3. If @@ -65,24 +61,16 @@ func (n *layer) objectFindID(ctx context.Context, p *findParams) (*object.ID, er // objectHead returns all object's headers. func (n *layer) objectHead(ctx context.Context, address *object.Address) (*object.Object, error) { - conn, _, err := n.pool.Connection() - if err != nil { - return nil, err - } ops := new(client.ObjectHeaderParams).WithAddress(address).WithAllFields() - return conn.GetObjectHeader(ctx, ops) + return n.pool.GetObjectHeader(ctx, ops) } // objectGet and write it into provided io.Reader. func (n *layer) objectGet(ctx context.Context, p *getParams) (*object.Object, error) { - conn, tok, err := n.pool.Connection() - if err != nil { - return nil, err - } // prepare length/offset writer w := newWriter(p.Writer, p.offset, p.length) ops := new(client.GetObjectParams).WithAddress(p.address).WithPayloadWriter(w) - return conn.GetObject(ctx, ops, client.WithSession(tok)) + return n.pool.GetObject(ctx, ops) } // objectPut into NeoFS, took payload from io.Reader. @@ -135,16 +123,11 @@ func (n *layer) objectPut(ctx context.Context, p *PutObjectParams) (*ObjectInfo, raw.SetAttributes(attributes...) r := newDetector(p.Reader) - conn, tok, err := n.pool.Connection() - if err != nil { - return nil, err - } ops := new(client.PutObjectParams).WithObject(raw.Object()).WithPayloadReader(r) - oid, err := conn.PutObject( + oid, err := n.pool.PutObject( ctx, ops, - client.WithSession(tok), ) if err != nil { return nil, err @@ -165,11 +148,7 @@ func (n *layer) objectPut(ctx context.Context, p *PutObjectParams) (*ObjectInfo, // objectDelete puts tombstone object into neofs. func (n *layer) objectDelete(ctx context.Context, address *object.Address) error { - conn, _, err := n.pool.Connection() - if err != nil { - return err - } dop := new(client.DeleteObjectParams) dop.WithAddress(address) - return conn.DeleteObject(ctx, dop) + return n.pool.DeleteObject(ctx, dop) } diff --git a/creds/tokens/credentials.go b/creds/tokens/credentials.go index 2d39667c..a1aa2a86 100644 --- a/creds/tokens/credentials.go +++ b/creds/tokens/credentials.go @@ -96,16 +96,11 @@ func (c *cred) getAccessBox(ctx context.Context, address *object.Address) (*acce ) defer c.releaseBuffer(buf) - conn, tok, err := c.pool.Connection() - if err != nil { - return nil, err - } ops := new(client.GetObjectParams).WithAddress(address).WithPayloadWriter(buf) - _, err = conn.GetObject( + _, err := c.pool.GetObject( ctx, ops, - client.WithSession(tok), ) if err != nil { return nil, err @@ -133,10 +128,6 @@ func (c *cred) Put(ctx context.Context, cid *cid.ID, issuer *owner.ID, box *acce return nil, err } - conn, tok, err := c.pool.Connection() - if err != nil { - return nil, err - } timestamp := object.NewAttribute() timestamp.SetKey(object.AttributeTimestamp) timestamp.SetValue(created) @@ -151,10 +142,9 @@ func (c *cred) Put(ctx context.Context, cid *cid.ID, issuer *owner.ID, box *acce raw.SetAttributes(filename, timestamp) ops := new(client.PutObjectParams).WithObject(raw.Object()).WithPayloadReader(bytes.NewBuffer(data)) - oid, err := conn.PutObject( + oid, err := c.pool.PutObject( ctx, ops, - client.WithSession(tok), ) if err != nil { return nil, err diff --git a/go.mod b/go.mod index 66a8040b..cf764df1 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/nspcc-dev/neofs-api-go v1.27.0 github.com/nspcc-dev/neofs-crypto v0.3.0 github.com/nspcc-dev/neofs-node v1.22.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/spf13/pflag v1.0.5 github.com/spf13/viper v1.7.1 diff --git a/go.sum b/go.sum index d797c816..62e15ddf 100644 --- a/go.sum +++ b/go.sum @@ -346,6 +346,8 @@ github.com/nspcc-dev/neofs-sdk-go v0.0.0-20210604112451-f16d38c7b92a h1:bVvyR+Y+ github.com/nspcc-dev/neofs-sdk-go v0.0.0-20210604112451-f16d38c7b92a/go.mod h1:1djNrOkpTTbNUlJM/MvTmohJUaWKUMy9JHSCCA8rJEc= 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=