container: Support new BasicACL field

This commit is contained in:
alexvanin 2020-04-02 15:44:18 +03:00
parent 9f4636618f
commit 2fb36f8588
3 changed files with 9 additions and 37 deletions

View file

@ -31,9 +31,11 @@ func (m *PutRequest) PrepareData() ([]byte, error) {
err error
buf = new(bytes.Buffer)
capBytes = make([]byte, 8)
aclBytes = make([]byte, 4)
)
binary.BigEndian.PutUint64(capBytes, m.Capacity)
binary.BigEndian.PutUint32(capBytes, m.BasicACL)
if _, err = buf.Write(m.MessageID.Bytes()); err != nil {
return nil, errors.Wrap(err, "could not write message id")
@ -45,6 +47,8 @@ func (m *PutRequest) PrepareData() ([]byte, error) {
return nil, errors.Wrap(err, "could not marshal placement")
} else if _, err = buf.Write(data); err != nil {
return nil, errors.Wrap(err, "could not write placement")
} else if _, err = buf.Write(aclBytes); err != nil {
return nil, errors.Wrap(err, "could not write basic acl")
}
return buf.Bytes(), nil

View file

@ -11,19 +11,6 @@ import (
"github.com/pkg/errors"
)
// AccessMode is a container access mode type.
type AccessMode uint32
const (
// AccessModeRead is a read access mode.
AccessModeRead AccessMode = 1 << iota
// AccessModeWrite is a write access mode.
AccessModeWrite
)
// AccessModeReadWrite is a read/write container access mode.
const AccessModeReadWrite = AccessModeRead | AccessModeWrite
var (
_ internal.Custom = (*Container)(nil)
@ -31,8 +18,8 @@ var (
emptyOwner = (OwnerID{}).Bytes()
)
// New creates new user container based on capacity, OwnerID and PlacementRules.
func New(cap uint64, owner OwnerID, rules netmap.PlacementRule) (*Container, error) {
// New creates new user container based on capacity, OwnerID, ACL and PlacementRules.
func New(cap uint64, owner OwnerID, acl uint32, rules netmap.PlacementRule) (*Container, error) {
if bytes.Equal(owner[:], emptyOwner) {
return nil, refs.ErrEmptyOwner
} else if cap == 0 {
@ -49,6 +36,7 @@ func New(cap uint64, owner OwnerID, rules netmap.PlacementRule) (*Container, err
Salt: UUID(salt),
Capacity: cap,
Rules: rules,
BasicACL: acl,
}, nil
}
@ -90,7 +78,7 @@ func NewTestContainer() (*Container, error) {
if err != nil {
return nil, err
}
return New(100, owner, netmap.PlacementRule{
return New(100, owner, 0xFFFFFFFF, netmap.PlacementRule{
ReplFactor: 2,
SFGroups: []netmap.SFGroup{
{

View file

@ -36,7 +36,7 @@ func TestCID(t *testing.T) {
owner, err := refs.NewOwnerID(&key.PublicKey)
require.NoError(t, err)
c1, err := New(10, owner, rules)
c1, err := New(10, owner, 0xDEADBEEF, rules)
require.NoError(t, err)
data, err := proto.Marshal(c1)
@ -55,23 +55,3 @@ func TestCID(t *testing.T) {
require.Equal(t, cid1, cid2)
})
}
func TestAccessMode(t *testing.T) {
t.Run("read access to read/write mode", func(t *testing.T) {
require.Equal(t, AccessModeRead, AccessModeReadWrite&AccessModeRead)
})
t.Run("write access to read/write mode", func(t *testing.T) {
require.Equal(t, AccessModeWrite, AccessModeReadWrite&AccessModeWrite)
})
t.Run("read(write) access to write(read) mode", func(t *testing.T) {
require.Zero(t, AccessModeRead&AccessModeWrite)
})
t.Run("access to same mode", func(t *testing.T) {
require.Equal(t, AccessModeWrite, AccessModeWrite&AccessModeWrite)
require.Equal(t, AccessModeRead, AccessModeRead&AccessModeRead)
require.Equal(t, AccessModeReadWrite, AccessModeReadWrite&AccessModeReadWrite)
})
}