[#78] Using client.Object from sdk

Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
Denis Kirillov 2021-06-15 11:51:42 +03:00
parent ee078eabcc
commit fba29a9a66
5 changed files with 11 additions and 44 deletions

View file

@ -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.

View file

@ -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)
}

View file

@ -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

2
go.mod
View file

@ -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

2
go.sum
View file

@ -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=