Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#78] Using client.Object from sdk #81

Merged
merged 1 commit into from
Jun 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions api/layer/layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
31 changes: 5 additions & 26 deletions api/layer/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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)
}
14 changes: 2 additions & 12 deletions creds/tokens/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down