Skip to content

Commit

Permalink
*: Remove pool's deprecated methods
Browse files Browse the repository at this point in the history
Signed-off-by: Evgenii Baidakov <[email protected]>
  • Loading branch information
smallhive committed Aug 3, 2023
1 parent b404452 commit be44240
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 67 deletions.
3 changes: 0 additions & 3 deletions api/layer/layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,12 +318,9 @@ func (n *layer) Owner(ctx context.Context) user.ID {
}

func (n *layer) prepareAuthParameters(ctx context.Context, prm *PrmAuth, bktOwner user.ID) {
prm.PrivateKey = &n.gateKey.PrivateKey

if bd, ok := ctx.Value(api.BoxData).(*accessbox.Box); ok && bd != nil && bd.Gate != nil && bd.Gate.BearerToken != nil {
if bktOwner.Equals(bd.Gate.BearerToken.ResolveIssuer()) {
prm.BearerToken = bd.Gate.BearerToken
return
}
}
}
Expand Down
4 changes: 0 additions & 4 deletions api/layer/neofs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package layer

import (
"context"
"crypto/ecdsa"
"errors"
"io"
"time"
Expand Down Expand Up @@ -47,9 +46,6 @@ type PrmContainerCreate struct {
type PrmAuth struct {
// Bearer token to be used for the operation. Overlaps PrivateKey. Optional.
BearerToken *bearer.Token

// Private key used for the operation if BearerToken is missing (in this case non-nil).
PrivateKey *ecdsa.PrivateKey
}

// PrmObjectRead groups parameters of NeoFS.ReadObject operation.
Expand Down
108 changes: 48 additions & 60 deletions internal/neofs/neofs.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,30 @@ import (
"github.com/nspcc-dev/neofs-sdk-go/eacl"
"github.com/nspcc-dev/neofs-sdk-go/object"
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
"github.com/nspcc-dev/neofs-sdk-go/object/slicer"
"github.com/nspcc-dev/neofs-sdk-go/pool"
"github.com/nspcc-dev/neofs-sdk-go/session"
"github.com/nspcc-dev/neofs-sdk-go/stat"
"github.com/nspcc-dev/neofs-sdk-go/user"
"github.com/nspcc-dev/neofs-sdk-go/waiter"
)

// NeoFS represents virtual connection to the NeoFS network.
// It is used to provide an interface to dependent packages
// which work with NeoFS.
type NeoFS struct {
pool *pool.Pool
await pool.WaitParams
gateSigner user.Signer
}

const (
defaultPollInterval = time.Second // overrides default value from pool
defaultPollTimeout = 120 * time.Second // same as default value from pool
defaultPollInterval = time.Second // overrides default value from pool
)

// NewNeoFS creates new NeoFS using provided pool.Pool.
func NewNeoFS(p *pool.Pool, signer user.Signer) *NeoFS {

Check warning on line 46 in internal/neofs/neofs.go

View check run for this annotation

Codecov / codecov/patch

internal/neofs/neofs.go#L46

Added line #L46 was not covered by tests
var await pool.WaitParams
await.SetPollInterval(defaultPollInterval)
await.SetTimeout(defaultPollTimeout)

return &NeoFS{
pool: p,
await: await,
gateSigner: signer,

Check warning on line 49 in internal/neofs/neofs.go

View check run for this annotation

Codecov / codecov/patch

internal/neofs/neofs.go#L48-L49

Added lines #L48 - L49 were not covered by tests
}
}
Expand Down Expand Up @@ -93,7 +88,8 @@ func (x *NeoFS) TimeToEpoch(ctx context.Context, now, futureTime time.Time) (uin

// Container implements neofs.NeoFS interface method.
func (x *NeoFS) Container(ctx context.Context, idCnr cid.ID) (*container.Container, error) {
res, err := x.pool.GetContainer(ctx, idCnr)
var prm client.PrmContainerGet
res, err := x.pool.ContainerGet(ctx, idCnr, prm)

Check warning on line 92 in internal/neofs/neofs.go

View check run for this annotation

Codecov / codecov/patch

internal/neofs/neofs.go#L91-L92

Added lines #L91 - L92 were not covered by tests
if err != nil {
return nil, fmt.Errorf("read container via connection pool: %w", err)
}
Expand Down Expand Up @@ -140,15 +136,15 @@ func (x *NeoFS) CreateContainer(ctx context.Context, prm layer.PrmContainerCreat
return cid.ID{}, fmt.Errorf("sync container with the network state: %w", err)
}

var prmPut pool.PrmContainerPut
prmPut.SetWaitParams(x.await)

var prmPut client.PrmContainerPut

Check warning on line 139 in internal/neofs/neofs.go

View check run for this annotation

Codecov / codecov/patch

internal/neofs/neofs.go#L139

Added line #L139 was not covered by tests
if prm.SessionToken != nil {
prmPut.WithinSession(*prm.SessionToken)
}

putWaiter := waiter.NewContainerPutWaiter(x.pool, defaultPollInterval)

Check warning on line 145 in internal/neofs/neofs.go

View check run for this annotation

Codecov / codecov/patch

internal/neofs/neofs.go#L144-L145

Added lines #L144 - L145 were not covered by tests
// send request to save the container
idCnr, err := x.pool.PutContainer(ctx, cnr, x.gateSigner, prmPut)
idCnr, err := putWaiter.ContainerPut(ctx, cnr, x.gateSigner, prmPut)

Check warning on line 147 in internal/neofs/neofs.go

View check run for this annotation

Codecov / codecov/patch

internal/neofs/neofs.go#L147

Added line #L147 was not covered by tests
if err != nil {
return cid.ID{}, fmt.Errorf("save container via connection pool: %w", err)
}
Expand All @@ -158,7 +154,8 @@ func (x *NeoFS) CreateContainer(ctx context.Context, prm layer.PrmContainerCreat

// UserContainers implements neofs.NeoFS interface method.
func (x *NeoFS) UserContainers(ctx context.Context, id user.ID) ([]cid.ID, error) {
r, err := x.pool.ListContainers(ctx, id)
var prm client.PrmContainerList
r, err := x.pool.ContainerList(ctx, id, prm)

Check warning on line 158 in internal/neofs/neofs.go

View check run for this annotation

Codecov / codecov/patch

internal/neofs/neofs.go#L157-L158

Added lines #L157 - L158 were not covered by tests
if err != nil {
return nil, fmt.Errorf("list user containers via connection pool: %w", err)
}
Expand All @@ -168,14 +165,13 @@ func (x *NeoFS) UserContainers(ctx context.Context, id user.ID) ([]cid.ID, error

// SetContainerEACL implements neofs.NeoFS interface method.
func (x *NeoFS) SetContainerEACL(ctx context.Context, table eacl.Table, sessionToken *session.Container, signer user.Signer) error {
var prm pool.PrmContainerSetEACL
prm.SetWaitParams(x.await)

var prm client.PrmContainerSetEACL

Check warning on line 168 in internal/neofs/neofs.go

View check run for this annotation

Codecov / codecov/patch

internal/neofs/neofs.go#L167-L168

Added lines #L167 - L168 were not covered by tests
if sessionToken != nil {
prm.WithinSession(*sessionToken)
}

err := x.pool.SetEACL(ctx, table, signer, prm)
eaclWaiter := waiter.NewContainerSetEACLWaiter(x.pool, defaultPollInterval)
err := eaclWaiter.ContainerSetEACL(ctx, table, signer, prm)

Check warning on line 174 in internal/neofs/neofs.go

View check run for this annotation

Codecov / codecov/patch

internal/neofs/neofs.go#L173-L174

Added lines #L173 - L174 were not covered by tests
if err != nil {
return fmt.Errorf("save eACL via connection pool: %w", err)
}
Expand All @@ -185,7 +181,8 @@ func (x *NeoFS) SetContainerEACL(ctx context.Context, table eacl.Table, sessionT

// ContainerEACL implements neofs.NeoFS interface method.
func (x *NeoFS) ContainerEACL(ctx context.Context, id cid.ID) (*eacl.Table, error) {
res, err := x.pool.GetEACL(ctx, id)
var prm client.PrmContainerEACL
res, err := x.pool.ContainerEACL(ctx, id, prm)

Check warning on line 185 in internal/neofs/neofs.go

View check run for this annotation

Codecov / codecov/patch

internal/neofs/neofs.go#L184-L185

Added lines #L184 - L185 were not covered by tests
if err != nil {
return nil, fmt.Errorf("read eACL via connection pool: %w", err)
}
Expand All @@ -195,14 +192,13 @@ func (x *NeoFS) ContainerEACL(ctx context.Context, id cid.ID) (*eacl.Table, erro

// DeleteContainer implements neofs.NeoFS interface method.
func (x *NeoFS) DeleteContainer(ctx context.Context, id cid.ID, token *session.Container, signer user.Signer) error {
var prm pool.PrmContainerDelete
prm.SetWaitParams(x.await)

var prm client.PrmContainerDelete

Check warning on line 195 in internal/neofs/neofs.go

View check run for this annotation

Codecov / codecov/patch

internal/neofs/neofs.go#L194-L195

Added lines #L194 - L195 were not covered by tests
if token != nil {
prm.SetSessionToken(*token)
prm.WithinSession(*token)

Check warning on line 197 in internal/neofs/neofs.go

View check run for this annotation

Codecov / codecov/patch

internal/neofs/neofs.go#L197

Added line #L197 was not covered by tests
}

err := x.pool.DeleteContainer(ctx, id, signer, prm)
deleteWaiter := waiter.NewContainerDeleteWaiter(x.pool, defaultPollInterval)
err := deleteWaiter.ContainerDelete(ctx, id, signer, prm)

Check warning on line 201 in internal/neofs/neofs.go

View check run for this annotation

Codecov / codecov/patch

internal/neofs/neofs.go#L200-L201

Added lines #L200 - L201 were not covered by tests
if err != nil {
return fmt.Errorf("delete container via connection pool: %w", err)
}
Expand Down Expand Up @@ -258,18 +254,14 @@ func (x *NeoFS) CreateObject(ctx context.Context, prm layer.PrmObjectCreate) (oi
objectv2.WriteLock(obj.ToV2(), (objectv2.Lock)(*lock))
}

var prmPut pool.PrmObjectPut
prmPut.SetHeader(*obj)
prmPut.SetPayload(prm.Payload)
prmPut.SetCopiesNumber(prm.CopiesNumber)
var opts slicer.Options
opts.SetCopiesNumber(prm.CopiesNumber)

Check warning on line 258 in internal/neofs/neofs.go

View check run for this annotation

Codecov / codecov/patch

internal/neofs/neofs.go#L257-L258

Added lines #L257 - L258 were not covered by tests

if prm.BearerToken != nil {
prmPut.UseBearer(*prm.BearerToken)
} else if prm.PrivateKey != nil {
prmPut.UseSigner(user.NewSignerRFC6979(*prm.PrivateKey))
opts.SetBearerToken(prm.BearerToken)

Check warning on line 261 in internal/neofs/neofs.go

View check run for this annotation

Codecov / codecov/patch

internal/neofs/neofs.go#L261

Added line #L261 was not covered by tests
}

idObj, err := x.pool.PutObject(ctx, prmPut)
idObj, err := slicer.Put(ctx, x.pool, *obj, x.gateSigner, prm.Payload, opts)

Check warning on line 264 in internal/neofs/neofs.go

View check run for this annotation

Codecov / codecov/patch

internal/neofs/neofs.go#L264

Added line #L264 was not covered by tests
if err != nil {
reason, ok := isErrAccessDenied(err)
if ok {
Expand Down Expand Up @@ -300,17 +292,15 @@ func (x payloadReader) Read(p []byte) (int, error) {

// ReadObject implements neofs.NeoFS interface method.
func (x *NeoFS) ReadObject(ctx context.Context, prm layer.PrmObjectRead) (*layer.ObjectPart, error) {
var prmGet pool.PrmObjectGet
var prmGet client.PrmObjectGet

Check warning on line 295 in internal/neofs/neofs.go

View check run for this annotation

Codecov / codecov/patch

internal/neofs/neofs.go#L295

Added line #L295 was not covered by tests

if prm.BearerToken != nil {
prmGet.UseBearer(*prm.BearerToken)
} else if prm.PrivateKey != nil {
prmGet.UseSigner(user.NewSignerRFC6979(*prm.PrivateKey))
prmGet.WithBearerToken(*prm.BearerToken)

Check warning on line 298 in internal/neofs/neofs.go

View check run for this annotation

Codecov / codecov/patch

internal/neofs/neofs.go#L298

Added line #L298 was not covered by tests
}

if prm.WithHeader {
if prm.WithPayload {
res, err := x.pool.GetObject(ctx, prm.Container, prm.Object, prmGet)
header, res, err := x.pool.ObjectGetInit(ctx, prm.Container, prm.Object, x.gateSigner, prmGet)

Check warning on line 303 in internal/neofs/neofs.go

View check run for this annotation

Codecov / codecov/patch

internal/neofs/neofs.go#L303

Added line #L303 was not covered by tests
if err != nil {
if reason, ok := isErrAccessDenied(err); ok {
return nil, fmt.Errorf("%w: %s", layer.ErrAccessDenied, reason)
Expand All @@ -319,29 +309,27 @@ func (x *NeoFS) ReadObject(ctx context.Context, prm layer.PrmObjectRead) (*layer
return nil, fmt.Errorf("init full object reading via connection pool: %w", err)
}

defer res.Payload.Close()
defer res.Close()

Check warning on line 312 in internal/neofs/neofs.go

View check run for this annotation

Codecov / codecov/patch

internal/neofs/neofs.go#L312

Added line #L312 was not covered by tests

payload, err := io.ReadAll(res.Payload)
payload, err := io.ReadAll(res)

Check warning on line 314 in internal/neofs/neofs.go

View check run for this annotation

Codecov / codecov/patch

internal/neofs/neofs.go#L314

Added line #L314 was not covered by tests
if err != nil {
return nil, fmt.Errorf("read full object payload: %w", err)
}

res.Header.SetPayload(payload)
header.SetPayload(payload)

Check warning on line 319 in internal/neofs/neofs.go

View check run for this annotation

Codecov / codecov/patch

internal/neofs/neofs.go#L319

Added line #L319 was not covered by tests

return &layer.ObjectPart{
Head: &res.Header,
Head: &header,

Check warning on line 322 in internal/neofs/neofs.go

View check run for this annotation

Codecov / codecov/patch

internal/neofs/neofs.go#L322

Added line #L322 was not covered by tests
}, nil
}

var prmHead pool.PrmObjectHead
var prmHead client.PrmObjectHead

Check warning on line 326 in internal/neofs/neofs.go

View check run for this annotation

Codecov / codecov/patch

internal/neofs/neofs.go#L326

Added line #L326 was not covered by tests

if prm.BearerToken != nil {
prmHead.UseBearer(*prm.BearerToken)
} else if prm.PrivateKey != nil {
prmHead.UseSigner(user.NewSignerRFC6979(*prm.PrivateKey))
prmHead.WithBearerToken(*prm.BearerToken)

Check warning on line 329 in internal/neofs/neofs.go

View check run for this annotation

Codecov / codecov/patch

internal/neofs/neofs.go#L329

Added line #L329 was not covered by tests
}

hdr, err := x.pool.HeadObject(ctx, prm.Container, prm.Object, prmHead)
hdrRes, err := x.pool.ObjectHead(ctx, prm.Container, prm.Object, x.gateSigner, prmHead)

Check warning on line 332 in internal/neofs/neofs.go

View check run for this annotation

Codecov / codecov/patch

internal/neofs/neofs.go#L332

Added line #L332 was not covered by tests
if err != nil {
if reason, ok := isErrAccessDenied(err); ok {
return nil, fmt.Errorf("%w: %s", layer.ErrAccessDenied, reason)
Expand All @@ -350,11 +338,16 @@ func (x *NeoFS) ReadObject(ctx context.Context, prm layer.PrmObjectRead) (*layer
return nil, fmt.Errorf("read object header via connection pool: %w", err)
}

var hdr object.Object
if !hdrRes.ReadHeader(&hdr) {
return nil, errors.New("header is empty")
}

Check warning on line 344 in internal/neofs/neofs.go

View check run for this annotation

Codecov / codecov/patch

internal/neofs/neofs.go#L341-L344

Added lines #L341 - L344 were not covered by tests

return &layer.ObjectPart{
Head: &hdr,
}, nil
} else if prm.PayloadRange[0]+prm.PayloadRange[1] == 0 {
res, err := x.pool.GetObject(ctx, prm.Container, prm.Object, prmGet)
_, res, err := x.pool.ObjectGetInit(ctx, prm.Container, prm.Object, x.gateSigner, prmGet)

Check warning on line 350 in internal/neofs/neofs.go

View check run for this annotation

Codecov / codecov/patch

internal/neofs/neofs.go#L350

Added line #L350 was not covered by tests
if err != nil {
if reason, ok := isErrAccessDenied(err); ok {
return nil, fmt.Errorf("%w: %s", layer.ErrAccessDenied, reason)
Expand All @@ -364,19 +357,17 @@ func (x *NeoFS) ReadObject(ctx context.Context, prm layer.PrmObjectRead) (*layer
}

return &layer.ObjectPart{
Payload: res.Payload,
Payload: res,

Check warning on line 360 in internal/neofs/neofs.go

View check run for this annotation

Codecov / codecov/patch

internal/neofs/neofs.go#L360

Added line #L360 was not covered by tests
}, nil
}

var prmRange pool.PrmObjectRange
var prmRange client.PrmObjectRange

Check warning on line 364 in internal/neofs/neofs.go

View check run for this annotation

Codecov / codecov/patch

internal/neofs/neofs.go#L364

Added line #L364 was not covered by tests

if prm.BearerToken != nil {
prmRange.UseBearer(*prm.BearerToken)
} else if prm.PrivateKey != nil {
prmRange.UseSigner(user.NewSignerRFC6979(*prm.PrivateKey))
prmRange.WithBearerToken(*prm.BearerToken)

Check warning on line 367 in internal/neofs/neofs.go

View check run for this annotation

Codecov / codecov/patch

internal/neofs/neofs.go#L367

Added line #L367 was not covered by tests
}

res, err := x.pool.ObjectRange(ctx, prm.Container, prm.Object, prm.PayloadRange[0], prm.PayloadRange[1], prmRange)
res, err := x.pool.ObjectRangeInit(ctx, prm.Container, prm.Object, prm.PayloadRange[0], prm.PayloadRange[1], x.gateSigner, prmRange)

Check warning on line 370 in internal/neofs/neofs.go

View check run for this annotation

Codecov / codecov/patch

internal/neofs/neofs.go#L370

Added line #L370 was not covered by tests
if err != nil {
if reason, ok := isErrAccessDenied(err); ok {
return nil, fmt.Errorf("%w: %s", layer.ErrAccessDenied, reason)
Expand All @@ -386,22 +377,19 @@ func (x *NeoFS) ReadObject(ctx context.Context, prm layer.PrmObjectRead) (*layer
}

return &layer.ObjectPart{
Payload: payloadReader{&res},
Payload: payloadReader{res},

Check warning on line 380 in internal/neofs/neofs.go

View check run for this annotation

Codecov / codecov/patch

internal/neofs/neofs.go#L380

Added line #L380 was not covered by tests
}, nil
}

// DeleteObject implements neofs.NeoFS interface method.
func (x *NeoFS) DeleteObject(ctx context.Context, prm layer.PrmObjectDelete) error {
var prmDelete pool.PrmObjectDelete
var prmDelete client.PrmObjectDelete

Check warning on line 386 in internal/neofs/neofs.go

View check run for this annotation

Codecov / codecov/patch

internal/neofs/neofs.go#L386

Added line #L386 was not covered by tests

if prm.BearerToken != nil {
prmDelete.UseBearer(*prm.BearerToken)
}
if prm.PrivateKey != nil {
prmDelete.UseSigner(user.NewSignerRFC6979(*prm.PrivateKey))
prmDelete.WithBearerToken(*prm.BearerToken)

Check warning on line 389 in internal/neofs/neofs.go

View check run for this annotation

Codecov / codecov/patch

internal/neofs/neofs.go#L389

Added line #L389 was not covered by tests
}

err := x.pool.DeleteObject(ctx, prm.Container, prm.Object, prmDelete)
_, err := x.pool.ObjectDelete(ctx, prm.Container, prm.Object, x.gateSigner, prmDelete)

Check warning on line 392 in internal/neofs/neofs.go

View check run for this annotation

Codecov / codecov/patch

internal/neofs/neofs.go#L392

Added line #L392 was not covered by tests
if err != nil {
if reason, ok := isErrAccessDenied(err); ok {
return fmt.Errorf("%w: %s", layer.ErrAccessDenied, reason)
Expand Down

0 comments on commit be44240

Please sign in to comment.