[#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:
parent
89be8d3f5a
commit
65080c8b69
22 changed files with 97 additions and 209 deletions
|
@ -6,26 +6,25 @@ 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"
|
||||
cidtest "github.com/nspcc-dev/neofs-api-go/pkg/container/id/test"
|
||||
sessiontest "github.com/nspcc-dev/neofs-api-go/pkg/session/test"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestTable(t *testing.T) {
|
||||
var (
|
||||
v pkg.Version
|
||||
cid container.ID
|
||||
v pkg.Version
|
||||
)
|
||||
|
||||
sha := sha256.Sum256([]byte("container id"))
|
||||
cid.SetSHA256(sha)
|
||||
id := cidtest.GenerateWithChecksum(sha)
|
||||
|
||||
v.SetMajor(3)
|
||||
v.SetMinor(2)
|
||||
|
||||
table := eacl.NewTable()
|
||||
table.SetVersion(v)
|
||||
table.SetCID(&cid)
|
||||
table.SetCID(id)
|
||||
table.AddRecord(eacl.CreateRecord(eacl.ActionAllow, eacl.OperationPut))
|
||||
|
||||
v2 := table.ToV2()
|
||||
|
@ -43,11 +42,10 @@ func TestTable(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("create table", func(t *testing.T) {
|
||||
var cid = new(container.ID)
|
||||
cid.SetSHA256(sha256.Sum256([]byte("container id")))
|
||||
id := cidtest.Generate()
|
||||
|
||||
table := eacl.CreateTable(*cid)
|
||||
require.Equal(t, cid, table.CID())
|
||||
table := eacl.CreateTable(*id)
|
||||
require.Equal(t, id, table.CID())
|
||||
require.Equal(t, *pkg.SDKVersion(), table.Version())
|
||||
})
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package audit
|
|||
|
||||
import (
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg"
|
||||
"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/v2/audit"
|
||||
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
||||
|
@ -87,15 +87,15 @@ func (r *Result) SetAuditEpoch(epoch uint64) {
|
|||
}
|
||||
|
||||
// ContainerID returns container under audit.
|
||||
func (r *Result) ContainerID() *container.ID {
|
||||
return container.NewIDFromV2(
|
||||
func (r *Result) ContainerID() *cid.ID {
|
||||
return cid.NewFromV2(
|
||||
(*audit.DataAuditResult)(r).
|
||||
GetContainerID(),
|
||||
)
|
||||
}
|
||||
|
||||
// SetContainerID sets container under audit.
|
||||
func (r *Result) SetContainerID(id *container.ID) {
|
||||
func (r *Result) SetContainerID(id *cid.ID) {
|
||||
(*audit.DataAuditResult)(r).
|
||||
SetContainerID(id.ToV2())
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/audit"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/container"
|
||||
cidtest "github.com/nspcc-dev/neofs-api-go/pkg/container/id/test"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/object"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
@ -17,13 +17,6 @@ func testSHA256() (cs [sha256.Size]byte) {
|
|||
return
|
||||
}
|
||||
|
||||
func testCID() *container.ID {
|
||||
cid := container.NewID()
|
||||
cid.SetSHA256(testSHA256())
|
||||
|
||||
return cid
|
||||
}
|
||||
|
||||
func testOID() *object.ID {
|
||||
id := object.NewID()
|
||||
id.SetSHA256(testSHA256())
|
||||
|
@ -39,7 +32,7 @@ func TestResult(t *testing.T) {
|
|||
r.SetAuditEpoch(epoch)
|
||||
require.Equal(t, epoch, r.AuditEpoch())
|
||||
|
||||
cid := testCID()
|
||||
cid := cidtest.Generate()
|
||||
r.SetContainerID(cid)
|
||||
require.Equal(t, cid, r.ContainerID())
|
||||
|
||||
|
@ -90,7 +83,7 @@ func TestResult(t *testing.T) {
|
|||
func TestStorageGroupEncoding(t *testing.T) {
|
||||
r := audit.NewResult()
|
||||
r.SetAuditEpoch(13)
|
||||
r.SetContainerID(testCID())
|
||||
r.SetContainerID(cidtest.Generate())
|
||||
r.SetPublicKey([]byte{1, 2, 3})
|
||||
r.SetPassSG([]*object.ID{testOID(), testOID()})
|
||||
r.SetFailSG([]*object.ID{testOID(), testOID()})
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package container
|
||||
|
||||
import (
|
||||
cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id"
|
||||
"github.com/nspcc-dev/neofs-api-go/v2/container"
|
||||
)
|
||||
|
||||
|
@ -30,14 +31,14 @@ func (a *UsedSpaceAnnouncement) SetEpoch(epoch uint64) {
|
|||
}
|
||||
|
||||
// ContainerID of the announcement.
|
||||
func (a *UsedSpaceAnnouncement) ContainerID() *ID {
|
||||
return NewIDFromV2(
|
||||
func (a *UsedSpaceAnnouncement) ContainerID() *cid.ID {
|
||||
return cid.NewFromV2(
|
||||
(*container.UsedSpaceAnnouncement)(a).GetContainerID(),
|
||||
)
|
||||
}
|
||||
|
||||
// SetContainerID sets announcement container value.
|
||||
func (a *UsedSpaceAnnouncement) SetContainerID(cid *ID) {
|
||||
func (a *UsedSpaceAnnouncement) SetContainerID(cid *cid.ID) {
|
||||
(*container.UsedSpaceAnnouncement)(a).SetContainerID(cid.ToV2())
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,8 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/container"
|
||||
cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id"
|
||||
cidtest "github.com/nspcc-dev/neofs-api-go/pkg/container/id/test"
|
||||
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
@ -12,18 +14,17 @@ import (
|
|||
func TestAnnouncement(t *testing.T) {
|
||||
const epoch, usedSpace uint64 = 10, 100
|
||||
|
||||
cidValue := [32]byte{1, 2, 3}
|
||||
cid := container.NewID()
|
||||
cid.SetSHA256(cidValue)
|
||||
cidValue := [sha256.Size]byte{1, 2, 3}
|
||||
id := cidtest.GenerateWithChecksum(cidValue)
|
||||
|
||||
a := container.NewAnnouncement()
|
||||
a.SetEpoch(epoch)
|
||||
a.SetContainerID(cid)
|
||||
a.SetContainerID(id)
|
||||
a.SetUsedSpace(usedSpace)
|
||||
|
||||
require.Equal(t, epoch, a.Epoch())
|
||||
require.Equal(t, usedSpace, a.UsedSpace())
|
||||
require.Equal(t, cid, a.ContainerID())
|
||||
require.Equal(t, id, a.ContainerID())
|
||||
|
||||
t.Run("test v2", func(t *testing.T) {
|
||||
const newEpoch, newUsedSpace uint64 = 20, 200
|
||||
|
@ -45,7 +46,7 @@ func TestAnnouncement(t *testing.T) {
|
|||
|
||||
require.Equal(t, newEpoch, newA.Epoch())
|
||||
require.Equal(t, newUsedSpace, newA.UsedSpace())
|
||||
require.Equal(t, container.NewIDFromV2(newCID), newA.ContainerID())
|
||||
require.Equal(t, cid.NewFromV2(newCID), newA.ContainerID())
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -54,8 +55,7 @@ func TestUsedSpaceEncoding(t *testing.T) {
|
|||
a.SetUsedSpace(13)
|
||||
a.SetEpoch(666)
|
||||
|
||||
id := container.NewID()
|
||||
id.SetSHA256([sha256.Size]byte{1, 2, 3})
|
||||
id := cidtest.Generate()
|
||||
|
||||
a.SetContainerID(id)
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
|
||||
"github.com/google/uuid"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg"
|
||||
cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/netmap"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/owner"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/session"
|
||||
|
@ -63,13 +64,13 @@ func NewContainerFromV2(c *container.Container) *Container {
|
|||
|
||||
// CalculateID calculates container identifier
|
||||
// based on its structure.
|
||||
func CalculateID(c *Container) *ID {
|
||||
func CalculateID(c *Container) *cid.ID {
|
||||
data, err := c.ToV2().StableMarshal(nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
id := NewID()
|
||||
id := cid.New()
|
||||
id.SetSHA256(sha256.Sum256(data))
|
||||
|
||||
return id
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
"github.com/nspcc-dev/neofs-api-go/pkg/container"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/netmap"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/owner"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/token"
|
||||
sessiontest "github.com/nspcc-dev/neofs-api-go/pkg/session/test"
|
||||
"github.com/nspcc-dev/neofs-crypto/test"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
@ -98,8 +98,7 @@ func TestContainerEncoding(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestContainer_SessionToken(t *testing.T) {
|
||||
tok := token.NewSessionToken()
|
||||
tok.SetID([]byte{1, 2, 3})
|
||||
tok := sessiontest.Generate()
|
||||
|
||||
cnr := container.New()
|
||||
|
||||
|
|
|
@ -16,11 +16,9 @@ func randSHA256Checksum() (cs [sha256.Size]byte) {
|
|||
}
|
||||
|
||||
func TestID_ToV2(t *testing.T) {
|
||||
id := cid.New()
|
||||
|
||||
checksum := randSHA256Checksum()
|
||||
|
||||
id.SetSHA256(checksum)
|
||||
id := cidtest.GenerateWithChecksum(checksum)
|
||||
|
||||
idV2 := id.ToV2()
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"errors"
|
||||
"strings"
|
||||
|
||||
"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/v2/refs"
|
||||
)
|
||||
|
||||
|
@ -36,14 +36,14 @@ func (a *Address) ToV2() *refs.Address {
|
|||
}
|
||||
|
||||
// ContainerID returns container identifier.
|
||||
func (a *Address) ContainerID() *container.ID {
|
||||
return container.NewIDFromV2(
|
||||
func (a *Address) ContainerID() *cid.ID {
|
||||
return cid.NewFromV2(
|
||||
(*refs.Address)(a).GetContainerID(),
|
||||
)
|
||||
}
|
||||
|
||||
// SetContainerID sets container identifier.
|
||||
func (a *Address) SetContainerID(id *container.ID) {
|
||||
func (a *Address) SetContainerID(id *cid.ID) {
|
||||
(*refs.Address)(a).SetContainerID(id.ToV2())
|
||||
}
|
||||
|
||||
|
@ -64,20 +64,20 @@ func (a *Address) Parse(s string) error {
|
|||
var (
|
||||
err error
|
||||
oid = NewID()
|
||||
cid = container.NewID()
|
||||
id = cid.New()
|
||||
parts = strings.Split(s, addressSeparator)
|
||||
)
|
||||
|
||||
if len(parts) != addressParts {
|
||||
return errInvalidAddressString
|
||||
} else if err = cid.Parse(parts[0]); err != nil {
|
||||
} else if err = id.Parse(parts[0]); err != nil {
|
||||
return err
|
||||
} else if err = oid.Parse(parts[1]); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
a.SetObjectID(oid)
|
||||
a.SetContainerID(cid)
|
||||
a.SetContainerID(id)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -4,19 +4,18 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/container"
|
||||
cidtest "github.com/nspcc-dev/neofs-api-go/pkg/container/id/test"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestAddress_SetContainerID(t *testing.T) {
|
||||
a := NewAddress()
|
||||
|
||||
cid := container.NewID()
|
||||
cid.SetSHA256(randSHA256Checksum(t))
|
||||
id := cidtest.Generate()
|
||||
|
||||
a.SetContainerID(cid)
|
||||
a.SetContainerID(id)
|
||||
|
||||
require.Equal(t, cid, a.ContainerID())
|
||||
require.Equal(t, id, a.ContainerID())
|
||||
}
|
||||
|
||||
func TestAddress_SetObjectID(t *testing.T) {
|
||||
|
@ -30,8 +29,7 @@ func TestAddress_SetObjectID(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestAddress_Parse(t *testing.T) {
|
||||
cid := container.NewID()
|
||||
cid.SetSHA256(randSHA256Checksum(t))
|
||||
cid := cidtest.Generate()
|
||||
|
||||
oid := NewID()
|
||||
oid.SetSHA256(randSHA256Checksum(t))
|
||||
|
@ -64,7 +62,7 @@ func TestAddress_Parse(t *testing.T) {
|
|||
func TestAddressEncoding(t *testing.T) {
|
||||
a := NewAddress()
|
||||
a.SetObjectID(randID(t))
|
||||
a.SetContainerID(randCID(t))
|
||||
a.SetContainerID(cidtest.Generate())
|
||||
|
||||
t.Run("binary", func(t *testing.T) {
|
||||
data, err := a.Marshal()
|
||||
|
|
|
@ -2,9 +2,9 @@ package object
|
|||
|
||||
import (
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg"
|
||||
"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/token"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/session"
|
||||
"github.com/nspcc-dev/neofs-api-go/v2/object"
|
||||
)
|
||||
|
||||
|
@ -71,7 +71,7 @@ func (o *RawObject) SetPayloadSize(v uint64) {
|
|||
}
|
||||
|
||||
// SetContainerID sets identifier of the related container.
|
||||
func (o *RawObject) SetContainerID(v *container.ID) {
|
||||
func (o *RawObject) SetContainerID(v *cid.ID) {
|
||||
o.setContainerID(v)
|
||||
}
|
||||
|
||||
|
@ -127,7 +127,7 @@ func (o *RawObject) SetParent(v *Object) {
|
|||
|
||||
// SetSessionToken sets token of the session
|
||||
// within which object was created.
|
||||
func (o *RawObject) SetSessionToken(v *token.SessionToken) {
|
||||
func (o *RawObject) SetSessionToken(v *session.Token) {
|
||||
o.setSessionToken(v)
|
||||
}
|
||||
|
||||
|
|
|
@ -6,9 +6,9 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/container"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/owner"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/token"
|
||||
cidtest "github.com/nspcc-dev/neofs-api-go/pkg/container/id/test"
|
||||
ownertest "github.com/nspcc-dev/neofs-api-go/pkg/owner/test"
|
||||
sessiontest "github.com/nspcc-dev/neofs-api-go/pkg/session/test"
|
||||
"github.com/nspcc-dev/neofs-api-go/v2/object"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
@ -20,13 +20,6 @@ func randID(t *testing.T) *ID {
|
|||
return id
|
||||
}
|
||||
|
||||
func randCID(t *testing.T) *container.ID {
|
||||
id := container.NewID()
|
||||
id.SetSHA256(randSHA256Checksum(t))
|
||||
|
||||
return id
|
||||
}
|
||||
|
||||
func randSHA256Checksum(t *testing.T) (cs [sha256.Size]byte) {
|
||||
_, err := rand.Read(cs[:])
|
||||
require.NoError(t, err)
|
||||
|
@ -98,10 +91,7 @@ func TestRawObject_SetPayloadSize(t *testing.T) {
|
|||
func TestRawObject_SetContainerID(t *testing.T) {
|
||||
obj := NewRaw()
|
||||
|
||||
checksum := randSHA256Checksum(t)
|
||||
|
||||
cid := container.NewID()
|
||||
cid.SetSHA256(checksum)
|
||||
cid := cidtest.Generate()
|
||||
|
||||
obj.SetContainerID(cid)
|
||||
|
||||
|
@ -111,11 +101,7 @@ func TestRawObject_SetContainerID(t *testing.T) {
|
|||
func TestRawObject_SetOwnerID(t *testing.T) {
|
||||
obj := NewRaw()
|
||||
|
||||
w := new(owner.NEO3Wallet)
|
||||
_, _ = rand.Read(w.Bytes())
|
||||
|
||||
ownerID := owner.NewID()
|
||||
ownerID.SetNeo3Wallet(w)
|
||||
ownerID := ownertest.Generate()
|
||||
|
||||
obj.SetOwnerID(ownerID)
|
||||
|
||||
|
@ -208,7 +194,7 @@ func TestRawObject_SetParent(t *testing.T) {
|
|||
|
||||
par := NewRaw()
|
||||
par.SetID(randID(t))
|
||||
par.SetContainerID(container.NewID())
|
||||
par.SetContainerID(cidtest.Generate())
|
||||
par.SetSignature(pkg.NewSignature())
|
||||
|
||||
parObj := par.Object()
|
||||
|
@ -230,8 +216,7 @@ func TestRawObject_ToV2(t *testing.T) {
|
|||
func TestRawObject_SetSessionToken(t *testing.T) {
|
||||
obj := NewRaw()
|
||||
|
||||
tok := token.NewSessionToken()
|
||||
tok.SetID([]byte{1, 2, 3})
|
||||
tok := sessiontest.Generate()
|
||||
|
||||
obj.SetSessionToken(tok)
|
||||
|
||||
|
|
|
@ -2,9 +2,9 @@ package object
|
|||
|
||||
import (
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg"
|
||||
"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/token"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/session"
|
||||
"github.com/nspcc-dev/neofs-api-go/v2/object"
|
||||
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
||||
)
|
||||
|
@ -108,15 +108,15 @@ func (o *rwObject) setPayloadSize(v uint64) {
|
|||
}
|
||||
|
||||
// ContainerID returns identifier of the related container.
|
||||
func (o *rwObject) ContainerID() *container.ID {
|
||||
return container.NewIDFromV2(
|
||||
func (o *rwObject) ContainerID() *cid.ID {
|
||||
return cid.NewFromV2(
|
||||
(*object.Object)(o).
|
||||
GetHeader().
|
||||
GetContainerID(),
|
||||
)
|
||||
}
|
||||
|
||||
func (o *rwObject) setContainerID(v *container.ID) {
|
||||
func (o *rwObject) setContainerID(v *cid.ID) {
|
||||
o.setHeaderField(func(h *object.Header) {
|
||||
h.SetContainerID(v.ToV2())
|
||||
})
|
||||
|
@ -327,15 +327,15 @@ func (o *rwObject) resetRelations() {
|
|||
|
||||
// SessionToken returns token of the session
|
||||
// within which object was created.
|
||||
func (o *rwObject) SessionToken() *token.SessionToken {
|
||||
return token.NewSessionTokenFromV2(
|
||||
func (o *rwObject) SessionToken() *session.Token {
|
||||
return session.NewTokenFromV2(
|
||||
(*object.Object)(o).
|
||||
GetHeader().
|
||||
GetSessionToken(),
|
||||
)
|
||||
}
|
||||
|
||||
func (o *rwObject) setSessionToken(v *token.SessionToken) {
|
||||
func (o *rwObject) setSessionToken(v *session.Token) {
|
||||
o.setHeaderField(func(h *object.Header) {
|
||||
h.SetSessionToken(v.ToV2())
|
||||
})
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"fmt"
|
||||
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg"
|
||||
"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"
|
||||
v2object "github.com/nspcc-dev/neofs-api-go/v2/object"
|
||||
)
|
||||
|
@ -199,7 +199,7 @@ func (f *SearchFilters) AddObjectVersionFilter(op SearchMatchType, v *pkg.Versio
|
|||
f.addReservedFilter(op, fKeyVersion, v)
|
||||
}
|
||||
|
||||
func (f *SearchFilters) AddObjectContainerIDFilter(m SearchMatchType, id *container.ID) {
|
||||
func (f *SearchFilters) AddObjectContainerIDFilter(m SearchMatchType, id *cid.ID) {
|
||||
f.addReservedFilter(m, fKeyContainerID, id)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package owner_test
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
|
@ -12,21 +11,8 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func randID(t *testing.T) *ID {
|
||||
id := NewID()
|
||||
|
||||
wallet := new(NEO3Wallet)
|
||||
|
||||
_, err := rand.Read(wallet.Bytes())
|
||||
require.NoError(t, err)
|
||||
|
||||
id.SetNeo3Wallet(wallet)
|
||||
|
||||
return id
|
||||
}
|
||||
|
||||
func TestIDV2(t *testing.T) {
|
||||
id := randID(t)
|
||||
id := ownertest.Generate()
|
||||
|
||||
idV2 := id.ToV2()
|
||||
|
||||
|
@ -73,7 +59,7 @@ func TestID_Parse(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestIDEncoding(t *testing.T) {
|
||||
id := randID(t)
|
||||
id := ownertest.Generate()
|
||||
|
||||
t.Run("binary", func(t *testing.T) {
|
||||
data, err := id.Marshal()
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
package session_test
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"testing"
|
||||
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/owner"
|
||||
ownertest "github.com/nspcc-dev/neofs-api-go/pkg/owner/test"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/session"
|
||||
sessiontest "github.com/nspcc-dev/neofs-api-go/pkg/session/test"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
@ -22,12 +21,7 @@ func TestSessionToken_SetID(t *testing.T) {
|
|||
func TestSessionToken_SetOwnerID(t *testing.T) {
|
||||
token := session.NewToken()
|
||||
|
||||
w := new(owner.NEO3Wallet)
|
||||
_, err := rand.Read(w.Bytes())
|
||||
require.NoError(t, err)
|
||||
|
||||
ownerID := owner.NewID()
|
||||
ownerID.SetNeo3Wallet(w)
|
||||
ownerID := ownertest.Generate()
|
||||
|
||||
token.SetOwnerID(ownerID)
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ func TestBearerToken_Issuer(t *testing.T) {
|
|||
|
||||
bearerToken.SetEACLTable(eacl.NewTable())
|
||||
require.NoError(t, bearerToken.SignToken(key))
|
||||
require.Equal(t, bearerToken.Issuer().String(), ownerID.String())
|
||||
require.True(t, ownerID.Equal(bearerToken.Issuer()))
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -1,67 +0,0 @@
|
|||
package token
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"testing"
|
||||
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/owner"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestSessionToken_SetID(t *testing.T) {
|
||||
token := NewSessionToken()
|
||||
|
||||
id := []byte{1, 2, 3}
|
||||
token.SetID(id)
|
||||
|
||||
require.Equal(t, id, token.ID())
|
||||
}
|
||||
|
||||
func TestSessionToken_SetOwnerID(t *testing.T) {
|
||||
token := NewSessionToken()
|
||||
|
||||
w := new(owner.NEO3Wallet)
|
||||
_, err := rand.Read(w.Bytes())
|
||||
require.NoError(t, err)
|
||||
|
||||
ownerID := owner.NewID()
|
||||
ownerID.SetNeo3Wallet(w)
|
||||
|
||||
token.SetOwnerID(ownerID)
|
||||
|
||||
require.Equal(t, ownerID, token.OwnerID())
|
||||
}
|
||||
|
||||
func TestSessionToken_SetSessionKey(t *testing.T) {
|
||||
token := NewSessionToken()
|
||||
|
||||
key := []byte{1, 2, 3}
|
||||
token.SetSessionKey(key)
|
||||
|
||||
require.Equal(t, key, token.SessionKey())
|
||||
}
|
||||
|
||||
func TestSessionTokenEncoding(t *testing.T) {
|
||||
tok := NewSessionToken()
|
||||
tok.SetID([]byte("id"))
|
||||
|
||||
t.Run("binary", func(t *testing.T) {
|
||||
data, err := tok.Marshal()
|
||||
require.NoError(t, err)
|
||||
|
||||
tok2 := NewSessionToken()
|
||||
require.NoError(t, tok2.Unmarshal(data))
|
||||
|
||||
require.Equal(t, tok, tok2)
|
||||
})
|
||||
|
||||
t.Run("json", func(t *testing.T) {
|
||||
data, err := tok.MarshalJSON()
|
||||
require.NoError(t, err)
|
||||
|
||||
tok2 := NewSessionToken()
|
||||
require.NoError(t, tok2.UnmarshalJSON(data))
|
||||
|
||||
require.Equal(t, tok, tok2)
|
||||
})
|
||||
}
|
Loading…
Reference in a new issue