[#295] pkg: Remove usage of deprecated elements

Remove usage of deprecated of `container.ID` and `token.SessionToken` code
elements. Replace using of custom message generators with the ones provided
by packages. Replace string comparison with `Equal` method call.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-05-31 15:09:04 +03:00 committed by Leonard Lyubich
parent 89be8d3f5a
commit 65080c8b69
22 changed files with 97 additions and 209 deletions

View file

@ -8,6 +8,7 @@ import (
"github.com/nspcc-dev/neofs-api-go/pkg"
"github.com/nspcc-dev/neofs-api-go/pkg/acl/eacl"
"github.com/nspcc-dev/neofs-api-go/pkg/container"
cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id"
"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/rpc/client"
@ -21,19 +22,19 @@ import (
// Container contains methods related to container and ACL.
type Container interface {
// PutContainer creates new container in the NeoFS network.
PutContainer(context.Context, *container.Container, ...CallOption) (*container.ID, error)
PutContainer(context.Context, *container.Container, ...CallOption) (*cid.ID, error)
// GetContainer returns container by ID.
GetContainer(context.Context, *container.ID, ...CallOption) (*container.Container, error)
GetContainer(context.Context, *cid.ID, ...CallOption) (*container.Container, error)
// ListContainers return container list with the provided owner.
ListContainers(context.Context, *owner.ID, ...CallOption) ([]*container.ID, error)
ListContainers(context.Context, *owner.ID, ...CallOption) ([]*cid.ID, error)
// DeleteContainer removes container from NeoFS network.
DeleteContainer(context.Context, *container.ID, ...CallOption) error
DeleteContainer(context.Context, *cid.ID, ...CallOption) error
// GetEACL returns extended ACL for a given container.
GetEACL(context.Context, *container.ID, ...CallOption) (*EACLWithSignature, error)
GetEACL(context.Context, *cid.ID, ...CallOption) (*EACLWithSignature, error)
// SetEACL sets extended ACL.
SetEACL(context.Context, *eacl.Table, ...CallOption) error
@ -71,7 +72,7 @@ func (e EACLWithSignature) Signature() *pkg.Signature {
return e.table.Signature()
}
func (c *clientImpl) PutContainer(ctx context.Context, cnr *container.Container, opts ...CallOption) (*container.ID, error) {
func (c *clientImpl) PutContainer(ctx context.Context, cnr *container.Container, opts ...CallOption) (*cid.ID, error) {
// apply all available options
callOptions := c.defaultCallOptions()
@ -134,13 +135,13 @@ func (c *clientImpl) PutContainer(ctx context.Context, cnr *container.Container,
return nil, fmt.Errorf("can't verify response message: %w", err)
}
return container.NewIDFromV2(resp.GetBody().GetContainerID()), nil
return cid.NewFromV2(resp.GetBody().GetContainerID()), nil
}
// GetContainer receives container structure through NeoFS API call.
//
// Returns error if container structure is received but does not meet NeoFS API specification.
func (c *clientImpl) GetContainer(ctx context.Context, id *container.ID, opts ...CallOption) (*container.Container, error) {
func (c *clientImpl) GetContainer(ctx context.Context, id *cid.ID, opts ...CallOption) (*container.Container, error) {
// apply all available options
callOptions := c.defaultCallOptions()
@ -192,7 +193,7 @@ func (c *clientImpl) GetContainer(ctx context.Context, id *container.ID, opts ..
// which checks if the structure of the resulting container matches its identifier.
//
// Returns an error if container does not match the identifier.
func GetVerifiedContainerStructure(ctx context.Context, c Client, id *container.ID, opts ...CallOption) (*container.Container, error) {
func GetVerifiedContainerStructure(ctx context.Context, c Client, id *cid.ID, opts ...CallOption) (*container.Container, error) {
cnr, err := c.GetContainer(ctx, id, opts...)
if err != nil {
return nil, err
@ -205,7 +206,7 @@ func GetVerifiedContainerStructure(ctx context.Context, c Client, id *container.
return cnr, nil
}
func (c *clientImpl) ListContainers(ctx context.Context, ownerID *owner.ID, opts ...CallOption) ([]*container.ID, error) {
func (c *clientImpl) ListContainers(ctx context.Context, ownerID *owner.ID, opts ...CallOption) ([]*cid.ID, error) {
// apply all available options
callOptions := c.defaultCallOptions()
@ -245,15 +246,15 @@ func (c *clientImpl) ListContainers(ctx context.Context, ownerID *owner.ID, opts
return nil, fmt.Errorf("can't verify response message: %w", err)
}
result := make([]*container.ID, 0, len(resp.GetBody().GetContainerIDs()))
result := make([]*cid.ID, 0, len(resp.GetBody().GetContainerIDs()))
for _, cidV2 := range resp.GetBody().GetContainerIDs() {
result = append(result, container.NewIDFromV2(cidV2))
result = append(result, cid.NewFromV2(cidV2))
}
return result, nil
}
func (c *clientImpl) DeleteContainer(ctx context.Context, id *container.ID, opts ...CallOption) error {
func (c *clientImpl) DeleteContainer(ctx context.Context, id *cid.ID, opts ...CallOption) error {
// apply all available options
callOptions := c.defaultCallOptions()
@ -301,7 +302,7 @@ func (c *clientImpl) DeleteContainer(ctx context.Context, id *container.ID, opts
return nil
}
func (c *clientImpl) GetEACL(ctx context.Context, id *container.ID, opts ...CallOption) (*EACLWithSignature, error) {
func (c *clientImpl) GetEACL(ctx context.Context, id *cid.ID, opts ...CallOption) (*EACLWithSignature, error) {
// apply all available options
callOptions := c.defaultCallOptions()

View file

@ -9,7 +9,7 @@ import (
"fmt"
"io"
"github.com/nspcc-dev/neofs-api-go/pkg/container"
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/rpc/client"
signer "github.com/nspcc-dev/neofs-api-go/util/signature"
@ -106,7 +106,7 @@ type RangeChecksumParams struct {
}
type SearchObjectParams struct {
cid *container.ID
cid *cid.ID
filters object.SearchFilters
}
@ -1092,7 +1092,7 @@ func (c *clientImpl) objectPayloadRangeHash(ctx context.Context, p *RangeChecksu
return res, nil
}
func (p *SearchObjectParams) WithContainerID(v *container.ID) *SearchObjectParams {
func (p *SearchObjectParams) WithContainerID(v *cid.ID) *SearchObjectParams {
if p != nil {
p.cid = v
}
@ -1100,7 +1100,7 @@ func (p *SearchObjectParams) WithContainerID(v *container.ID) *SearchObjectParam
return p
}
func (p *SearchObjectParams) ContainerID() *container.ID {
func (p *SearchObjectParams) ContainerID() *cid.ID {
if p != nil {
return p.cid
}

View file

@ -6,6 +6,7 @@ import (
"time"
"github.com/nspcc-dev/neofs-api-go/pkg"
"github.com/nspcc-dev/neofs-api-go/pkg/session"
"github.com/nspcc-dev/neofs-api-go/pkg/token"
"github.com/nspcc-dev/neofs-api-go/rpc/client"
"github.com/nspcc-dev/neofs-api-go/v2/refs"
@ -24,7 +25,7 @@ type (
ttl uint32
epoch uint64
key *ecdsa.PrivateKey
session *token.SessionToken
session *session.Token
bearer *token.BearerToken
}
@ -75,7 +76,7 @@ func WithEpoch(epoch uint64) CallOption {
}
}
func WithSession(token *token.SessionToken) CallOption {
func WithSession(token *session.Token) CallOption {
return func(opts *callOptions) {
opts.session = token
}

View file

@ -6,7 +6,7 @@ import (
"fmt"
"github.com/nspcc-dev/neofs-api-go/pkg/owner"
"github.com/nspcc-dev/neofs-api-go/pkg/token"
"github.com/nspcc-dev/neofs-api-go/pkg/session"
"github.com/nspcc-dev/neofs-api-go/rpc/client"
rpcapi "github.com/nspcc-dev/neofs-api-go/v2/rpc"
v2session "github.com/nspcc-dev/neofs-api-go/v2/session"
@ -16,12 +16,12 @@ import (
// Session contains session-related methods.
type Session interface {
// CreateSession creates session using provided expiration time.
CreateSession(context.Context, uint64, ...CallOption) (*token.SessionToken, error)
CreateSession(context.Context, uint64, ...CallOption) (*session.Token, error)
}
var errMalformedResponseBody = errors.New("malformed response body")
func (c *clientImpl) CreateSession(ctx context.Context, expiration uint64, opts ...CallOption) (*token.SessionToken, error) {
func (c *clientImpl) CreateSession(ctx context.Context, expiration uint64, opts ...CallOption) (*session.Token, error) {
// apply all available options
callOptions := c.defaultCallOptions()
@ -65,7 +65,7 @@ func (c *clientImpl) CreateSession(ctx context.Context, expiration uint64, opts
return nil, errMalformedResponseBody
}
sessionToken := token.NewSessionToken()
sessionToken := session.NewToken()
sessionToken.SetID(body.GetID())
sessionToken.SetSessionKey(body.GetSessionKey())
sessionToken.SetOwnerID(ownerID)