Change ACL to Acl
This commit is contained in:
parent
a32a3674b1
commit
27e0cbf1ea
@ -10,7 +10,7 @@ type rpcHandler struct {
|
|||||||
s *service
|
s *service
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *rpcHandler) PullSpace(ctx context.Context, request *spacesyncproto.SpacePullRequest) (resp *spacesyncproto.SpacePullResponse, err error) {
|
func (r *rpcHandler) SpacePull(ctx context.Context, request *spacesyncproto.SpacePullRequest) (resp *spacesyncproto.SpacePullResponse, err error) {
|
||||||
sp, err := r.s.GetSpace(ctx, request.Id)
|
sp, err := r.s.GetSpace(ctx, request.Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err != spacesyncproto.ErrSpaceMissing {
|
if err != spacesyncproto.ErrSpaceMissing {
|
||||||
@ -37,7 +37,7 @@ func (r *rpcHandler) PullSpace(ctx context.Context, request *spacesyncproto.Spac
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *rpcHandler) PushSpace(ctx context.Context, req *spacesyncproto.SpacePushRequest) (resp *spacesyncproto.SpacePushResponse, err error) {
|
func (r *rpcHandler) SpacePush(ctx context.Context, req *spacesyncproto.SpacePushRequest) (resp *spacesyncproto.SpacePushResponse, err error) {
|
||||||
description := commonspace.SpaceDescription{
|
description := commonspace.SpaceDescription{
|
||||||
SpaceHeader: req.Payload.SpaceHeader,
|
SpaceHeader: req.Payload.SpaceHeader,
|
||||||
AclId: req.Payload.AclPayloadId,
|
AclId: req.Payload.AclPayloadId,
|
||||||
@ -62,7 +62,7 @@ func (r *rpcHandler) HeadSync(ctx context.Context, req *spacesyncproto.HeadSyncR
|
|||||||
return sp.SpaceSyncRpc().HeadSync(ctx, req)
|
return sp.SpaceSyncRpc().HeadSync(ctx, req)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *rpcHandler) Stream(stream spacesyncproto.DRPCSpaceSync_ObjectSyncStreamStream) error {
|
func (r *rpcHandler) ObjectSyncStream(stream spacesyncproto.DRPCSpaceSync_ObjectSyncStreamStream) error {
|
||||||
msg, err := stream.Recv()
|
msg, err := stream.Recv()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@ -46,7 +46,7 @@ func (s *service) Init(a *app.App) (err error) {
|
|||||||
ocache.WithGCPeriod(time.Minute),
|
ocache.WithGCPeriod(time.Minute),
|
||||||
ocache.WithTTL(time.Duration(s.conf.GCTTL)*time.Second),
|
ocache.WithTTL(time.Duration(s.conf.GCTTL)*time.Second),
|
||||||
)
|
)
|
||||||
return spacesyncproto.DRPCRegisterSpace(a.MustComponent(server.CName).(server.DRPCServer), &rpcHandler{s})
|
return spacesyncproto.DRPCRegisterSpaceSync(a.MustComponent(server.CName).(server.DRPCServer), &rpcHandler{s})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) Name() (name string) {
|
func (s *service) Name() (name string) {
|
||||||
|
|||||||
@ -10,7 +10,7 @@ type aclKeys struct {
|
|||||||
headKey []byte
|
headKey []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func newACLKeys(spaceId string) aclKeys {
|
func newAclKeys(spaceId string) aclKeys {
|
||||||
return aclKeys{
|
return aclKeys{
|
||||||
spaceId: spaceId,
|
spaceId: spaceId,
|
||||||
rootKey: treestorage.JoinStringsToBytes("space", spaceId, "a", "rootId"),
|
rootKey: treestorage.JoinStringsToBytes("space", spaceId, "a", "rootId"),
|
||||||
|
|||||||
@ -14,11 +14,11 @@ type listStorage struct {
|
|||||||
db *badger.DB
|
db *badger.DB
|
||||||
keys aclKeys
|
keys aclKeys
|
||||||
id string
|
id string
|
||||||
root *aclrecordproto.RawACLRecordWithId
|
root *aclrecordproto.RawAclRecordWithId
|
||||||
}
|
}
|
||||||
|
|
||||||
func newListStorage(spaceId string, db *badger.DB, txn *badger.Txn) (ls liststorage.ListStorage, err error) {
|
func newListStorage(spaceId string, db *badger.DB, txn *badger.Txn) (ls liststorage.ListStorage, err error) {
|
||||||
keys := newACLKeys(spaceId)
|
keys := newAclKeys(spaceId)
|
||||||
rootId, err := getTxn(txn, keys.RootIdKey())
|
rootId, err := getTxn(txn, keys.RootIdKey())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@ -30,7 +30,7 @@ func newListStorage(spaceId string, db *badger.DB, txn *badger.Txn) (ls liststor
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
rootWithId := &aclrecordproto.RawACLRecordWithId{
|
rootWithId := &aclrecordproto.RawAclRecordWithId{
|
||||||
Payload: value,
|
Payload: value,
|
||||||
Id: stringId,
|
Id: stringId,
|
||||||
}
|
}
|
||||||
@ -44,8 +44,8 @@ func newListStorage(spaceId string, db *badger.DB, txn *badger.Txn) (ls liststor
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func createListStorage(spaceId string, db *badger.DB, txn *badger.Txn, root *aclrecordproto.RawACLRecordWithId) (ls liststorage.ListStorage, err error) {
|
func createListStorage(spaceId string, db *badger.DB, txn *badger.Txn, root *aclrecordproto.RawAclRecordWithId) (ls liststorage.ListStorage, err error) {
|
||||||
keys := newACLKeys(spaceId)
|
keys := newAclKeys(spaceId)
|
||||||
_, err = getTxn(txn, keys.RootIdKey())
|
_, err = getTxn(txn, keys.RootIdKey())
|
||||||
if err != badger.ErrKeyNotFound {
|
if err != badger.ErrKeyNotFound {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@ -81,7 +81,7 @@ func (l *listStorage) Id() string {
|
|||||||
return l.id
|
return l.id
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *listStorage) Root() (*aclrecordproto.RawACLRecordWithId, error) {
|
func (l *listStorage) Root() (*aclrecordproto.RawAclRecordWithId, error) {
|
||||||
return l.root, nil
|
return l.root, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,7 +94,7 @@ func (l *listStorage) Head() (head string, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *listStorage) GetRawRecord(ctx context.Context, id string) (raw *aclrecordproto.RawACLRecordWithId, err error) {
|
func (l *listStorage) GetRawRecord(ctx context.Context, id string) (raw *aclrecordproto.RawAclRecordWithId, err error) {
|
||||||
res, err := getDB(l.db, l.keys.RawRecordKey(id))
|
res, err := getDB(l.db, l.keys.RawRecordKey(id))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == badger.ErrKeyNotFound {
|
if err == badger.ErrKeyNotFound {
|
||||||
@ -103,7 +103,7 @@ func (l *listStorage) GetRawRecord(ctx context.Context, id string) (raw *aclreco
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
raw = &aclrecordproto.RawACLRecordWithId{
|
raw = &aclrecordproto.RawAclRecordWithId{
|
||||||
Payload: res,
|
Payload: res,
|
||||||
Id: id,
|
Id: id,
|
||||||
}
|
}
|
||||||
@ -114,6 +114,6 @@ func (l *listStorage) SetHead(headId string) (err error) {
|
|||||||
return putDB(l.db, l.keys.HeadIdKey(), []byte(headId))
|
return putDB(l.db, l.keys.HeadIdKey(), []byte(headId))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *listStorage) AddRawRecord(ctx context.Context, rec *aclrecordproto.RawACLRecordWithId) error {
|
func (l *listStorage) AddRawRecord(ctx context.Context, rec *aclrecordproto.RawAclRecordWithId) error {
|
||||||
return putDB(l.db, l.keys.RawRecordKey(rec.Id), rec.Payload)
|
return putDB(l.db, l.keys.RawRecordKey(rec.Id), rec.Payload)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,7 +9,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func testList(t *testing.T, store liststorage.ListStorage, root *aclrecordproto.RawACLRecordWithId, head string) {
|
func testList(t *testing.T, store liststorage.ListStorage, root *aclrecordproto.RawAclRecordWithId, head string) {
|
||||||
require.Equal(t, store.Id(), root.Id)
|
require.Equal(t, store.Id(), root.Id)
|
||||||
|
|
||||||
aclRoot, err := store.Root()
|
aclRoot, err := store.Root()
|
||||||
@ -26,7 +26,7 @@ func TestListStorage(t *testing.T) {
|
|||||||
fx.open(t)
|
fx.open(t)
|
||||||
defer fx.stop(t)
|
defer fx.stop(t)
|
||||||
spaceId := "spaceId"
|
spaceId := "spaceId"
|
||||||
aclRoot := &aclrecordproto.RawACLRecordWithId{Payload: []byte("root"), Id: "someRootId"}
|
aclRoot := &aclrecordproto.RawAclRecordWithId{Payload: []byte("root"), Id: "someRootId"}
|
||||||
|
|
||||||
fx.db.Update(func(txn *badger.Txn) error {
|
fx.db.Update(func(txn *badger.Txn) error {
|
||||||
_, err := createListStorage(spaceId, fx.db, txn, aclRoot)
|
_, err := createListStorage(spaceId, fx.db, txn, aclRoot)
|
||||||
@ -63,7 +63,7 @@ func TestListStorage(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("add raw record and get raw record", func(t *testing.T) {
|
t.Run("add raw record and get raw record", func(t *testing.T) {
|
||||||
newRec := &aclrecordproto.RawACLRecordWithId{Payload: []byte("rec"), Id: "someRecId"}
|
newRec := &aclrecordproto.RawAclRecordWithId{Payload: []byte("rec"), Id: "someRecId"}
|
||||||
require.NoError(t, listStore.AddRawRecord(context.Background(), newRec))
|
require.NoError(t, listStore.AddRawRecord(context.Background(), newRec))
|
||||||
aclRec, err := listStore.GetRawRecord(context.Background(), newRec.Id)
|
aclRec, err := listStore.GetRawRecord(context.Background(), newRec.Id)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|||||||
@ -120,7 +120,7 @@ func (s *spaceStorage) CreateTreeStorage(payload storage.TreeStorageCreatePayloa
|
|||||||
return createTreeStorage(s.objDb, s.spaceId, payload)
|
return createTreeStorage(s.objDb, s.spaceId, payload)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *spaceStorage) ACLStorage() (liststorage.ListStorage, error) {
|
func (s *spaceStorage) AclStorage() (liststorage.ListStorage, error) {
|
||||||
return s.aclStorage, nil
|
return s.aclStorage, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -16,7 +16,7 @@ func spaceTestPayload() spacestorage.SpaceStorageCreatePayload {
|
|||||||
RawHeader: []byte("header"),
|
RawHeader: []byte("header"),
|
||||||
Id: "headerId",
|
Id: "headerId",
|
||||||
}
|
}
|
||||||
aclRoot := &aclrecordproto.RawACLRecordWithId{
|
aclRoot := &aclrecordproto.RawAclRecordWithId{
|
||||||
Payload: []byte("aclRoot"),
|
Payload: []byte("aclRoot"),
|
||||||
Id: "aclRootId",
|
Id: "aclRootId",
|
||||||
}
|
}
|
||||||
@ -36,7 +36,7 @@ func testSpace(t *testing.T, store spacestorage.SpaceStorage, payload spacestora
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, payload.SpaceHeaderWithId, header)
|
require.Equal(t, payload.SpaceHeaderWithId, header)
|
||||||
|
|
||||||
aclStorage, err := store.ACLStorage()
|
aclStorage, err := store.AclStorage()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
testList(t, aclStorage, payload.AclWithId, payload.AclWithId.Id)
|
testList(t, aclStorage, payload.AclWithId, payload.AclWithId.Id)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,12 +10,12 @@ import (
|
|||||||
|
|
||||||
type commonSpaceGetter struct {
|
type commonSpaceGetter struct {
|
||||||
spaceId string
|
spaceId string
|
||||||
aclList *syncacl.SyncACL
|
aclList *syncacl.SyncAcl
|
||||||
treeGetter treegetter.TreeGetter
|
treeGetter treegetter.TreeGetter
|
||||||
settings settings.SettingsObject
|
settings settings.SettingsObject
|
||||||
}
|
}
|
||||||
|
|
||||||
func newCommonSpaceGetter(spaceId string, aclList *syncacl.SyncACL, treeGetter treegetter.TreeGetter, settings settings.SettingsObject) syncobjectgetter.SyncObjectGetter {
|
func newCommonSpaceGetter(spaceId string, aclList *syncacl.SyncAcl, treeGetter treegetter.TreeGetter, settings settings.SettingsObject) syncobjectgetter.SyncObjectGetter {
|
||||||
return &commonSpaceGetter{
|
return &commonSpaceGetter{
|
||||||
spaceId: spaceId,
|
spaceId: spaceId,
|
||||||
aclList: aclList,
|
aclList: aclList,
|
||||||
|
|||||||
@ -147,7 +147,7 @@ func (d *diffSyncer) pingTreesInCache(ctx context.Context, trees []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *diffSyncer) sendPushSpaceRequest(ctx context.Context, cl spacesyncproto.DRPCSpaceSyncClient) (err error) {
|
func (d *diffSyncer) sendPushSpaceRequest(ctx context.Context, cl spacesyncproto.DRPCSpaceSyncClient) (err error) {
|
||||||
aclStorage, err := d.storage.ACLStorage()
|
aclStorage, err := d.storage.AclStorage()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@ -160,7 +160,7 @@ func TestDiffSyncer_Sync(t *testing.T) {
|
|||||||
aclStorageMock := mock_treestorage.NewMockListStorage(ctrl)
|
aclStorageMock := mock_treestorage.NewMockListStorage(ctrl)
|
||||||
settingsStorage := mock_treestorage.NewMockTreeStorage(ctrl)
|
settingsStorage := mock_treestorage.NewMockTreeStorage(ctrl)
|
||||||
settingsId := "settingsId"
|
settingsId := "settingsId"
|
||||||
aclRoot := &aclrecordproto.RawACLRecordWithId{
|
aclRoot := &aclrecordproto.RawAclRecordWithId{
|
||||||
Id: aclRootId,
|
Id: aclRootId,
|
||||||
}
|
}
|
||||||
settingsRoot := &treechangeproto.RawTreeChangeWithId{
|
settingsRoot := &treechangeproto.RawTreeChangeWithId{
|
||||||
@ -176,7 +176,7 @@ func TestDiffSyncer_Sync(t *testing.T) {
|
|||||||
Diff(gomock.Any(), gomock.Eq(NewRemoteDiff(spaceId, clientMock))).
|
Diff(gomock.Any(), gomock.Eq(NewRemoteDiff(spaceId, clientMock))).
|
||||||
Return(nil, nil, nil, spacesyncproto.ErrSpaceMissing)
|
Return(nil, nil, nil, spacesyncproto.ErrSpaceMissing)
|
||||||
|
|
||||||
stMock.EXPECT().ACLStorage().Return(aclStorageMock, nil)
|
stMock.EXPECT().AclStorage().Return(aclStorageMock, nil)
|
||||||
stMock.EXPECT().SpaceHeader().Return(spaceHeader, nil)
|
stMock.EXPECT().SpaceHeader().Return(spaceHeader, nil)
|
||||||
stMock.EXPECT().SpaceSettingsId().Return(spaceSettingsId)
|
stMock.EXPECT().SpaceSettingsId().Return(spaceSettingsId)
|
||||||
stMock.EXPECT().TreeStorage(spaceSettingsId).Return(settingsStorage, nil)
|
stMock.EXPECT().TreeStorage(spaceSettingsId).Return(settingsStorage, nil)
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import (
|
|||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/util/keys/symmetric"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/util/keys/symmetric"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ACLReadKeyDerive(signKey []byte, encKey []byte) (*symmetric.Key, error) {
|
func AclReadKeyDerive(signKey []byte, encKey []byte) (*symmetric.Key, error) {
|
||||||
concBuf := make([]byte, 0, len(signKey)+len(encKey))
|
concBuf := make([]byte, 0, len(signKey)+len(encKey))
|
||||||
concBuf = append(concBuf, signKey...)
|
concBuf = append(concBuf, signKey...)
|
||||||
concBuf = append(concBuf, encKey...)
|
concBuf = append(concBuf, encKey...)
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@ -2,19 +2,19 @@ syntax = "proto3";
|
|||||||
package aclrecord;
|
package aclrecord;
|
||||||
option go_package = "commonspace/object/acl/aclrecordproto";
|
option go_package = "commonspace/object/acl/aclrecordproto";
|
||||||
|
|
||||||
message RawACLRecord {
|
message RawAclRecord {
|
||||||
bytes payload = 1;
|
bytes payload = 1;
|
||||||
bytes signature = 2;
|
bytes signature = 2;
|
||||||
bytes acceptorIdentity = 3;
|
bytes acceptorIdentity = 3;
|
||||||
bytes acceptorSignature = 4;
|
bytes acceptorSignature = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
message RawACLRecordWithId {
|
message RawAclRecordWithId {
|
||||||
bytes payload = 1;
|
bytes payload = 1;
|
||||||
string id = 2;
|
string id = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ACLRecord {
|
message AclRecord {
|
||||||
string prevId = 1;
|
string prevId = 1;
|
||||||
bytes identity = 2;
|
bytes identity = 2;
|
||||||
bytes data = 3;
|
bytes data = 3;
|
||||||
@ -22,7 +22,7 @@ message ACLRecord {
|
|||||||
int64 timestamp = 5;
|
int64 timestamp = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ACLRoot {
|
message AclRoot {
|
||||||
bytes identity = 1;
|
bytes identity = 1;
|
||||||
bytes encryptionKey = 2;
|
bytes encryptionKey = 2;
|
||||||
string spaceId = 3;
|
string spaceId = 3;
|
||||||
@ -32,47 +32,47 @@ message ACLRoot {
|
|||||||
int64 timestamp = 7;
|
int64 timestamp = 7;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ACLContentValue {
|
message AclContentValue {
|
||||||
oneof value {
|
oneof value {
|
||||||
ACLUserAdd userAdd = 1;
|
AclUserAdd userAdd = 1;
|
||||||
ACLUserRemove userRemove = 2;
|
AclUserRemove userRemove = 2;
|
||||||
ACLUserPermissionChange userPermissionChange = 3;
|
AclUserPermissionChange userPermissionChange = 3;
|
||||||
ACLUserInvite userInvite = 4;
|
AclUserInvite userInvite = 4;
|
||||||
ACLUserJoin userJoin = 5;
|
AclUserJoin userJoin = 5;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
message ACLData {
|
message AclData {
|
||||||
repeated ACLContentValue aclContent = 1;
|
repeated AclContentValue aclContent = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ACLState {
|
message AclState {
|
||||||
repeated uint64 readKeyHashes = 1;
|
repeated uint64 readKeyHashes = 1;
|
||||||
repeated ACLUserState userStates = 2;
|
repeated AclUserState userStates = 2;
|
||||||
map<string, ACLUserInvite> invites = 3;
|
map<string, AclUserInvite> invites = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ACLUserState {
|
message AclUserState {
|
||||||
bytes identity = 1;
|
bytes identity = 1;
|
||||||
bytes encryptionKey = 2;
|
bytes encryptionKey = 2;
|
||||||
ACLUserPermissions permissions = 3;
|
AclUserPermissions permissions = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ACLUserAdd {
|
message AclUserAdd {
|
||||||
bytes identity = 1;
|
bytes identity = 1;
|
||||||
bytes encryptionKey = 2;
|
bytes encryptionKey = 2;
|
||||||
repeated bytes encryptedReadKeys = 3;
|
repeated bytes encryptedReadKeys = 3;
|
||||||
ACLUserPermissions permissions = 4;
|
AclUserPermissions permissions = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ACLUserInvite {
|
message AclUserInvite {
|
||||||
bytes acceptPublicKey = 1;
|
bytes acceptPublicKey = 1;
|
||||||
uint64 encryptSymKeyHash = 2;
|
uint64 encryptSymKeyHash = 2;
|
||||||
repeated bytes encryptedReadKeys = 3;
|
repeated bytes encryptedReadKeys = 3;
|
||||||
ACLUserPermissions permissions = 4;
|
AclUserPermissions permissions = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ACLUserJoin {
|
message AclUserJoin {
|
||||||
bytes identity = 1;
|
bytes identity = 1;
|
||||||
bytes encryptionKey = 2;
|
bytes encryptionKey = 2;
|
||||||
bytes acceptSignature = 3;
|
bytes acceptSignature = 3;
|
||||||
@ -80,39 +80,39 @@ message ACLUserJoin {
|
|||||||
repeated bytes encryptedReadKeys = 5;
|
repeated bytes encryptedReadKeys = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ACLUserRemove {
|
message AclUserRemove {
|
||||||
bytes identity = 1;
|
bytes identity = 1;
|
||||||
repeated ACLReadKeyReplace readKeyReplaces = 2;
|
repeated AclReadKeyReplace readKeyReplaces = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ACLReadKeyReplace {
|
message AclReadKeyReplace {
|
||||||
bytes identity = 1;
|
bytes identity = 1;
|
||||||
bytes encryptionKey = 2;
|
bytes encryptionKey = 2;
|
||||||
bytes encryptedReadKey = 3;
|
bytes encryptedReadKey = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ACLUserPermissionChange {
|
message AclUserPermissionChange {
|
||||||
bytes identity = 1;
|
bytes identity = 1;
|
||||||
ACLUserPermissions permissions = 2;
|
AclUserPermissions permissions = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum ACLUserPermissions {
|
enum AclUserPermissions {
|
||||||
Admin = 0;
|
Admin = 0;
|
||||||
Writer = 1;
|
Writer = 1;
|
||||||
Reader = 2;
|
Reader = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ACLSyncMessage {
|
message AclSyncMessage {
|
||||||
ACLSyncContentValue content = 2;
|
AclSyncContentValue content = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ACLSyncContentValue provides different types for acl sync
|
// AclSyncContentValue provides different types for acl sync
|
||||||
message ACLSyncContentValue {
|
message AclSyncContentValue {
|
||||||
oneof value {
|
oneof value {
|
||||||
ACLAddRecords addRecords = 1;
|
AclAddRecords addRecords = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
message ACLAddRecords {
|
message AclAddRecords {
|
||||||
repeated RawACLRecordWithId records = 1;
|
repeated RawAclRecordWithId records = 1;
|
||||||
}
|
}
|
||||||
@ -10,9 +10,10 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ACLRecordBuilder interface {
|
// remove interface
|
||||||
ConvertFromRaw(rawIdRecord *aclrecordproto.RawACLRecordWithId) (rec *ACLRecord, err error)
|
type AclRecordBuilder interface {
|
||||||
BuildUserJoin(acceptPrivKeyBytes []byte, encSymKeyBytes []byte, state *ACLState) (rec *aclrecordproto.RawACLRecord, err error)
|
ConvertFromRaw(rawIdRecord *aclrecordproto.RawAclRecordWithId) (rec *AclRecord, err error)
|
||||||
|
BuildUserJoin(acceptPrivKeyBytes []byte, encSymKeyBytes []byte, state *AclState) (rec *aclrecordproto.RawAclRecord, err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type aclRecordBuilder struct {
|
type aclRecordBuilder struct {
|
||||||
@ -20,14 +21,14 @@ type aclRecordBuilder struct {
|
|||||||
keychain *keychain.Keychain
|
keychain *keychain.Keychain
|
||||||
}
|
}
|
||||||
|
|
||||||
func newACLRecordBuilder(id string, keychain *keychain.Keychain) ACLRecordBuilder {
|
func newAclRecordBuilder(id string, keychain *keychain.Keychain) AclRecordBuilder {
|
||||||
return &aclRecordBuilder{
|
return &aclRecordBuilder{
|
||||||
id: id,
|
id: id,
|
||||||
keychain: keychain,
|
keychain: keychain,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *aclRecordBuilder) BuildUserJoin(acceptPrivKeyBytes []byte, encSymKeyBytes []byte, state *ACLState) (rec *aclrecordproto.RawACLRecord, err error) {
|
func (a *aclRecordBuilder) BuildUserJoin(acceptPrivKeyBytes []byte, encSymKeyBytes []byte, state *AclState) (rec *aclrecordproto.RawAclRecord, err error) {
|
||||||
acceptPrivKey, err := signingkey.NewSigningEd25519PrivKeyFromBytes(acceptPrivKeyBytes)
|
acceptPrivKey, err := signingkey.NewSigningEd25519PrivKeyFromBytes(acceptPrivKeyBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@ -68,21 +69,21 @@ func (a *aclRecordBuilder) BuildUserJoin(acceptPrivKeyBytes []byte, encSymKeyByt
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
userJoin := &aclrecordproto.ACLUserJoin{
|
userJoin := &aclrecordproto.AclUserJoin{
|
||||||
Identity: state.Identity(),
|
Identity: state.Identity(),
|
||||||
EncryptionKey: encPubKeyBytes,
|
EncryptionKey: encPubKeyBytes,
|
||||||
AcceptSignature: idSignature,
|
AcceptSignature: idSignature,
|
||||||
AcceptPubKey: acceptPubKeyBytes,
|
AcceptPubKey: acceptPubKeyBytes,
|
||||||
EncryptedReadKeys: symKeys,
|
EncryptedReadKeys: symKeys,
|
||||||
}
|
}
|
||||||
aclData := &aclrecordproto.ACLData{AclContent: []*aclrecordproto.ACLContentValue{
|
aclData := &aclrecordproto.AclData{AclContent: []*aclrecordproto.AclContentValue{
|
||||||
{Value: &aclrecordproto.ACLContentValue_UserJoin{UserJoin: userJoin}},
|
{Value: &aclrecordproto.AclContentValue_UserJoin{UserJoin: userJoin}},
|
||||||
}}
|
}}
|
||||||
marshalledJoin, err := aclData.Marshal()
|
marshalledJoin, err := aclData.Marshal()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
aclRecord := &aclrecordproto.ACLRecord{
|
aclRecord := &aclrecordproto.AclRecord{
|
||||||
PrevId: state.LastRecordId(),
|
PrevId: state.LastRecordId(),
|
||||||
Identity: state.Identity(),
|
Identity: state.Identity(),
|
||||||
Data: marshalledJoin,
|
Data: marshalledJoin,
|
||||||
@ -97,28 +98,28 @@ func (a *aclRecordBuilder) BuildUserJoin(acceptPrivKeyBytes []byte, encSymKeyByt
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
rec = &aclrecordproto.RawACLRecord{
|
rec = &aclrecordproto.RawAclRecord{
|
||||||
Payload: marshalledRecord,
|
Payload: marshalledRecord,
|
||||||
Signature: recSignature,
|
Signature: recSignature,
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *aclRecordBuilder) ConvertFromRaw(rawIdRecord *aclrecordproto.RawACLRecordWithId) (rec *ACLRecord, err error) {
|
func (a *aclRecordBuilder) ConvertFromRaw(rawIdRecord *aclrecordproto.RawAclRecordWithId) (rec *AclRecord, err error) {
|
||||||
rawRec := &aclrecordproto.RawACLRecord{}
|
rawRec := &aclrecordproto.RawAclRecord{}
|
||||||
err = proto.Unmarshal(rawIdRecord.Payload, rawRec)
|
err = proto.Unmarshal(rawIdRecord.Payload, rawRec)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if rawIdRecord.Id == a.id {
|
if rawIdRecord.Id == a.id {
|
||||||
aclRoot := &aclrecordproto.ACLRoot{}
|
aclRoot := &aclrecordproto.AclRoot{}
|
||||||
err = proto.Unmarshal(rawRec.Payload, aclRoot)
|
err = proto.Unmarshal(rawRec.Payload, aclRoot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
rec = &ACLRecord{
|
rec = &AclRecord{
|
||||||
Id: rawIdRecord.Id,
|
Id: rawIdRecord.Id,
|
||||||
CurrentReadKeyHash: aclRoot.CurrentReadKeyHash,
|
CurrentReadKeyHash: aclRoot.CurrentReadKeyHash,
|
||||||
Timestamp: aclRoot.Timestamp,
|
Timestamp: aclRoot.Timestamp,
|
||||||
@ -127,13 +128,13 @@ func (a *aclRecordBuilder) ConvertFromRaw(rawIdRecord *aclrecordproto.RawACLReco
|
|||||||
Model: aclRoot,
|
Model: aclRoot,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
aclRecord := &aclrecordproto.ACLRecord{}
|
aclRecord := &aclrecordproto.AclRecord{}
|
||||||
err = proto.Unmarshal(rawRec.Payload, aclRecord)
|
err = proto.Unmarshal(rawRec.Payload, aclRecord)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
rec = &ACLRecord{
|
rec = &AclRecord{
|
||||||
Id: rawIdRecord.Id,
|
Id: rawIdRecord.Id,
|
||||||
PrevId: aclRecord.PrevId,
|
PrevId: aclRecord.PrevId,
|
||||||
CurrentReadKeyHash: aclRecord.CurrentReadKeyHash,
|
CurrentReadKeyHash: aclRecord.CurrentReadKeyHash,
|
||||||
@ -150,8 +151,8 @@ func (a *aclRecordBuilder) ConvertFromRaw(rawIdRecord *aclrecordproto.RawACLReco
|
|||||||
|
|
||||||
func verifyRaw(
|
func verifyRaw(
|
||||||
keychain *keychain.Keychain,
|
keychain *keychain.Keychain,
|
||||||
rawRec *aclrecordproto.RawACLRecord,
|
rawRec *aclrecordproto.RawAclRecord,
|
||||||
recWithId *aclrecordproto.RawACLRecordWithId,
|
recWithId *aclrecordproto.RawAclRecordWithId,
|
||||||
identity []byte) (err error) {
|
identity []byte) (err error) {
|
||||||
identityKey, err := keychain.GetOrAdd(string(identity))
|
identityKey, err := keychain.GetOrAdd(string(identity))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -15,7 +15,7 @@ func TestAclRecordBuilder_BuildUserJoin(t *testing.T) {
|
|||||||
st, err := acllistbuilder2.NewListStorageWithTestName("userjoinexample.yml")
|
st, err := acllistbuilder2.NewListStorageWithTestName("userjoinexample.yml")
|
||||||
require.NoError(t, err, "building storage should not result in error")
|
require.NoError(t, err, "building storage should not result in error")
|
||||||
|
|
||||||
testKeychain := st.(*acllistbuilder2.ACLListStorageBuilder).GetKeychain()
|
testKeychain := st.(*acllistbuilder2.AclListStorageBuilder).GetKeychain()
|
||||||
identity := testKeychain.GeneratedIdentities["D"]
|
identity := testKeychain.GeneratedIdentities["D"]
|
||||||
signPrivKey := testKeychain.SigningKeysByYAMLName["D"]
|
signPrivKey := testKeychain.SigningKeysByYAMLName["D"]
|
||||||
encPrivKey := testKeychain.EncryptionKeysByYAMLName["D"]
|
encPrivKey := testKeychain.EncryptionKeysByYAMLName["D"]
|
||||||
@ -25,26 +25,26 @@ func TestAclRecordBuilder_BuildUserJoin(t *testing.T) {
|
|||||||
EncKey: encPrivKey,
|
EncKey: encPrivKey,
|
||||||
}
|
}
|
||||||
|
|
||||||
aclList, err := BuildACLListWithIdentity(acc, st)
|
aclList, err := BuildAclListWithIdentity(acc, st)
|
||||||
require.NoError(t, err, "building acl list should be without error")
|
require.NoError(t, err, "building acl list should be without error")
|
||||||
recordBuilder := newACLRecordBuilder(aclList.ID(), keychain.NewKeychain())
|
recordBuilder := newAclRecordBuilder(aclList.ID(), keychain.NewKeychain())
|
||||||
rk, err := testKeychain.GetKey("key.Read.EncKey").(*acllistbuilder2.SymKey).Key.Raw()
|
rk, err := testKeychain.GetKey("key.Read.EncKey").(*acllistbuilder2.SymKey).Key.Raw()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
privKey, err := testKeychain.GetKey("key.Sign.Onetime1").(signingkey.PrivKey).Raw()
|
privKey, err := testKeychain.GetKey("key.Sign.Onetime1").(signingkey.PrivKey).Raw()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
userJoin, err := recordBuilder.BuildUserJoin(privKey, rk, aclList.ACLState())
|
userJoin, err := recordBuilder.BuildUserJoin(privKey, rk, aclList.AclState())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
marshalledJoin, err := userJoin.Marshal()
|
marshalledJoin, err := userJoin.Marshal()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
id, err := cidutil.NewCIDFromBytes(marshalledJoin)
|
id, err := cidutil.NewCIDFromBytes(marshalledJoin)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
rawRec := &aclrecordproto.RawACLRecordWithId{
|
rawRec := &aclrecordproto.RawAclRecordWithId{
|
||||||
Payload: marshalledJoin,
|
Payload: marshalledJoin,
|
||||||
Id: id,
|
Id: id,
|
||||||
}
|
}
|
||||||
res, err := aclList.AddRawRecord(rawRec)
|
res, err := aclList.AddRawRecord(rawRec)
|
||||||
require.True(t, res)
|
require.True(t, res)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, aclrecordproto.ACLUserPermissions_Writer, aclList.ACLState().UserStates()[identity].Permissions)
|
require.Equal(t, aclrecordproto.AclUserPermissions_Writer, aclList.AclState().UserStates()[identity].Permissions)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -36,15 +36,15 @@ var (
|
|||||||
|
|
||||||
type UserPermissionPair struct {
|
type UserPermissionPair struct {
|
||||||
Identity string
|
Identity string
|
||||||
Permission aclrecordproto2.ACLUserPermissions
|
Permission aclrecordproto2.AclUserPermissions
|
||||||
}
|
}
|
||||||
|
|
||||||
type ACLState struct {
|
type AclState struct {
|
||||||
id string
|
id string
|
||||||
currentReadKeyHash uint64
|
currentReadKeyHash uint64
|
||||||
userReadKeys map[uint64]*symmetric.Key
|
userReadKeys map[uint64]*symmetric.Key
|
||||||
userStates map[string]*aclrecordproto2.ACLUserState
|
userStates map[string]*aclrecordproto2.AclUserState
|
||||||
userInvites map[string]*aclrecordproto2.ACLUserInvite
|
userInvites map[string]*aclrecordproto2.AclUserInvite
|
||||||
encryptionKey encryptionkey.PrivKey
|
encryptionKey encryptionkey.PrivKey
|
||||||
signingKey signingkey.PrivKey
|
signingKey signingkey.PrivKey
|
||||||
totalReadKeys int
|
totalReadKeys int
|
||||||
@ -56,41 +56,41 @@ type ACLState struct {
|
|||||||
keychain *keychain.Keychain
|
keychain *keychain.Keychain
|
||||||
}
|
}
|
||||||
|
|
||||||
func newACLStateWithKeys(
|
func newAclStateWithKeys(
|
||||||
id string,
|
id string,
|
||||||
signingKey signingkey.PrivKey,
|
signingKey signingkey.PrivKey,
|
||||||
encryptionKey encryptionkey.PrivKey) (*ACLState, error) {
|
encryptionKey encryptionkey.PrivKey) (*AclState, error) {
|
||||||
identity, err := signingKey.GetPublic().Raw()
|
identity, err := signingKey.GetPublic().Raw()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &ACLState{
|
return &AclState{
|
||||||
id: id,
|
id: id,
|
||||||
identity: string(identity),
|
identity: string(identity),
|
||||||
signingKey: signingKey,
|
signingKey: signingKey,
|
||||||
encryptionKey: encryptionKey,
|
encryptionKey: encryptionKey,
|
||||||
userReadKeys: make(map[uint64]*symmetric.Key),
|
userReadKeys: make(map[uint64]*symmetric.Key),
|
||||||
userStates: make(map[string]*aclrecordproto2.ACLUserState),
|
userStates: make(map[string]*aclrecordproto2.AclUserState),
|
||||||
userInvites: make(map[string]*aclrecordproto2.ACLUserInvite),
|
userInvites: make(map[string]*aclrecordproto2.AclUserInvite),
|
||||||
permissionsAtRecord: make(map[string][]UserPermissionPair),
|
permissionsAtRecord: make(map[string][]UserPermissionPair),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func newACLState(id string) *ACLState {
|
func newAclState(id string) *AclState {
|
||||||
return &ACLState{
|
return &AclState{
|
||||||
id: id,
|
id: id,
|
||||||
userReadKeys: make(map[uint64]*symmetric.Key),
|
userReadKeys: make(map[uint64]*symmetric.Key),
|
||||||
userStates: make(map[string]*aclrecordproto2.ACLUserState),
|
userStates: make(map[string]*aclrecordproto2.AclUserState),
|
||||||
userInvites: make(map[string]*aclrecordproto2.ACLUserInvite),
|
userInvites: make(map[string]*aclrecordproto2.AclUserInvite),
|
||||||
permissionsAtRecord: make(map[string][]UserPermissionPair),
|
permissionsAtRecord: make(map[string][]UserPermissionPair),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *ACLState) CurrentReadKeyHash() uint64 {
|
func (st *AclState) CurrentReadKeyHash() uint64 {
|
||||||
return st.currentReadKeyHash
|
return st.currentReadKeyHash
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *ACLState) CurrentReadKey() (*symmetric.Key, error) {
|
func (st *AclState) CurrentReadKey() (*symmetric.Key, error) {
|
||||||
key, exists := st.userReadKeys[st.currentReadKeyHash]
|
key, exists := st.userReadKeys[st.currentReadKeyHash]
|
||||||
if !exists {
|
if !exists {
|
||||||
return nil, ErrNoReadKey
|
return nil, ErrNoReadKey
|
||||||
@ -98,11 +98,11 @@ func (st *ACLState) CurrentReadKey() (*symmetric.Key, error) {
|
|||||||
return key, nil
|
return key, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *ACLState) UserReadKeys() map[uint64]*symmetric.Key {
|
func (st *AclState) UserReadKeys() map[uint64]*symmetric.Key {
|
||||||
return st.userReadKeys
|
return st.userReadKeys
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *ACLState) PermissionsAtRecord(id string, identity string) (UserPermissionPair, error) {
|
func (st *AclState) PermissionsAtRecord(id string, identity string) (UserPermissionPair, error) {
|
||||||
permissions, ok := st.permissionsAtRecord[id]
|
permissions, ok := st.permissionsAtRecord[id]
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Errorf("missing record at id %s", id)
|
log.Errorf("missing record at id %s", id)
|
||||||
@ -117,7 +117,7 @@ func (st *ACLState) PermissionsAtRecord(id string, identity string) (UserPermiss
|
|||||||
return UserPermissionPair{}, ErrNoSuchUser
|
return UserPermissionPair{}, ErrNoSuchUser
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *ACLState) applyRecord(record *ACLRecord) (err error) {
|
func (st *AclState) applyRecord(record *AclRecord) (err error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
st.lastRecordId = record.Id
|
st.lastRecordId = record.Id
|
||||||
@ -128,7 +128,7 @@ func (st *ACLState) applyRecord(record *ACLRecord) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if record.Id == st.id {
|
if record.Id == st.id {
|
||||||
root, ok := record.Model.(*aclrecordproto2.ACLRoot)
|
root, ok := record.Model.(*aclrecordproto2.AclRoot)
|
||||||
if !ok {
|
if !ok {
|
||||||
return ErrIncorrectRoot
|
return ErrIncorrectRoot
|
||||||
}
|
}
|
||||||
@ -137,14 +137,14 @@ func (st *ACLState) applyRecord(record *ACLRecord) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
st.permissionsAtRecord[record.Id] = []UserPermissionPair{
|
st.permissionsAtRecord[record.Id] = []UserPermissionPair{
|
||||||
{Identity: string(root.Identity), Permission: aclrecordproto2.ACLUserPermissions_Admin},
|
{Identity: string(root.Identity), Permission: aclrecordproto2.AclUserPermissions_Admin},
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
aclData := &aclrecordproto2.ACLData{}
|
aclData := &aclrecordproto2.AclData{}
|
||||||
|
|
||||||
if record.Model != nil {
|
if record.Model != nil {
|
||||||
aclData = record.Model.(*aclrecordproto2.ACLData)
|
aclData = record.Model.(*aclrecordproto2.AclData)
|
||||||
} else {
|
} else {
|
||||||
err = proto.Unmarshal(record.Data, aclData)
|
err = proto.Unmarshal(record.Data, aclData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -172,7 +172,7 @@ func (st *ACLState) applyRecord(record *ACLRecord) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *ACLState) applyRoot(root *aclrecordproto2.ACLRoot) (err error) {
|
func (st *AclState) applyRoot(root *aclrecordproto2.AclRoot) (err error) {
|
||||||
if st.signingKey != nil && st.encryptionKey != nil && st.identity == string(root.Identity) {
|
if st.signingKey != nil && st.encryptionKey != nil && st.identity == string(root.Identity) {
|
||||||
err = st.saveReadKeyFromRoot(root)
|
err = st.saveReadKeyFromRoot(root)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -181,10 +181,10 @@ func (st *ACLState) applyRoot(root *aclrecordproto2.ACLRoot) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// adding user to the list
|
// adding user to the list
|
||||||
userState := &aclrecordproto2.ACLUserState{
|
userState := &aclrecordproto2.AclUserState{
|
||||||
Identity: root.Identity,
|
Identity: root.Identity,
|
||||||
EncryptionKey: root.EncryptionKey,
|
EncryptionKey: root.EncryptionKey,
|
||||||
Permissions: aclrecordproto2.ACLUserPermissions_Admin,
|
Permissions: aclrecordproto2.AclUserPermissions_Admin,
|
||||||
}
|
}
|
||||||
st.currentReadKeyHash = root.CurrentReadKeyHash
|
st.currentReadKeyHash = root.CurrentReadKeyHash
|
||||||
st.userStates[string(root.Identity)] = userState
|
st.userStates[string(root.Identity)] = userState
|
||||||
@ -192,7 +192,7 @@ func (st *ACLState) applyRoot(root *aclrecordproto2.ACLRoot) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *ACLState) saveReadKeyFromRoot(root *aclrecordproto2.ACLRoot) (err error) {
|
func (st *AclState) saveReadKeyFromRoot(root *aclrecordproto2.AclRoot) (err error) {
|
||||||
var readKey *symmetric.Key
|
var readKey *symmetric.Key
|
||||||
if len(root.GetDerivationScheme()) != 0 {
|
if len(root.GetDerivationScheme()) != 0 {
|
||||||
var encPrivKey []byte
|
var encPrivKey []byte
|
||||||
@ -206,7 +206,7 @@ func (st *ACLState) saveReadKeyFromRoot(root *aclrecordproto2.ACLRoot) (err erro
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
readKey, err = aclrecordproto2.ACLReadKeyDerive(signPrivKey, encPrivKey)
|
readKey, err = aclrecordproto2.AclReadKeyDerive(signPrivKey, encPrivKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -230,7 +230,7 @@ func (st *ACLState) saveReadKeyFromRoot(root *aclrecordproto2.ACLRoot) (err erro
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *ACLState) applyChangeData(changeData *aclrecordproto2.ACLData, hash uint64, identity []byte) (err error) {
|
func (st *AclState) applyChangeData(changeData *aclrecordproto2.AclData, hash uint64, identity []byte) (err error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@ -248,7 +248,7 @@ func (st *ACLState) applyChangeData(changeData *aclrecordproto2.ACLData, hash ui
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !st.HasPermission(identity, aclrecordproto2.ACLUserPermissions_Admin) {
|
if !st.HasPermission(identity, aclrecordproto2.AclUserPermissions_Admin) {
|
||||||
err = fmt.Errorf("user %s must have admin permissions", identity)
|
err = fmt.Errorf("user %s must have admin permissions", identity)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -264,7 +264,7 @@ func (st *ACLState) applyChangeData(changeData *aclrecordproto2.ACLData, hash ui
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *ACLState) applyChangeContent(ch *aclrecordproto2.ACLContentValue) error {
|
func (st *AclState) applyChangeContent(ch *aclrecordproto2.AclContentValue) error {
|
||||||
switch {
|
switch {
|
||||||
case ch.GetUserPermissionChange() != nil:
|
case ch.GetUserPermissionChange() != nil:
|
||||||
return st.applyUserPermissionChange(ch.GetUserPermissionChange())
|
return st.applyUserPermissionChange(ch.GetUserPermissionChange())
|
||||||
@ -281,7 +281,7 @@ func (st *ACLState) applyChangeContent(ch *aclrecordproto2.ACLContentValue) erro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *ACLState) applyUserPermissionChange(ch *aclrecordproto2.ACLUserPermissionChange) error {
|
func (st *AclState) applyUserPermissionChange(ch *aclrecordproto2.AclUserPermissionChange) error {
|
||||||
chIdentity := string(ch.Identity)
|
chIdentity := string(ch.Identity)
|
||||||
state, exists := st.userStates[chIdentity]
|
state, exists := st.userStates[chIdentity]
|
||||||
if !exists {
|
if !exists {
|
||||||
@ -292,12 +292,12 @@ func (st *ACLState) applyUserPermissionChange(ch *aclrecordproto2.ACLUserPermiss
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *ACLState) applyUserInvite(ch *aclrecordproto2.ACLUserInvite) error {
|
func (st *AclState) applyUserInvite(ch *aclrecordproto2.AclUserInvite) error {
|
||||||
st.userInvites[string(ch.AcceptPublicKey)] = ch
|
st.userInvites[string(ch.AcceptPublicKey)] = ch
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *ACLState) applyUserJoin(ch *aclrecordproto2.ACLUserJoin) error {
|
func (st *AclState) applyUserJoin(ch *aclrecordproto2.AclUserJoin) error {
|
||||||
invite, exists := st.userInvites[string(ch.AcceptPubKey)]
|
invite, exists := st.userInvites[string(ch.AcceptPubKey)]
|
||||||
if !exists {
|
if !exists {
|
||||||
return fmt.Errorf("no such invite with such public key %s", keys.EncodeBytesToString(ch.AcceptPubKey))
|
return fmt.Errorf("no such invite with such public key %s", keys.EncodeBytesToString(ch.AcceptPubKey))
|
||||||
@ -336,7 +336,7 @@ func (st *ACLState) applyUserJoin(ch *aclrecordproto2.ACLUserJoin) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// adding user to the list
|
// adding user to the list
|
||||||
userState := &aclrecordproto2.ACLUserState{
|
userState := &aclrecordproto2.AclUserState{
|
||||||
Identity: ch.Identity,
|
Identity: ch.Identity,
|
||||||
EncryptionKey: ch.EncryptionKey,
|
EncryptionKey: ch.EncryptionKey,
|
||||||
Permissions: invite.Permissions,
|
Permissions: invite.Permissions,
|
||||||
@ -345,13 +345,13 @@ func (st *ACLState) applyUserJoin(ch *aclrecordproto2.ACLUserJoin) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *ACLState) applyUserAdd(ch *aclrecordproto2.ACLUserAdd) error {
|
func (st *AclState) applyUserAdd(ch *aclrecordproto2.AclUserAdd) error {
|
||||||
chIdentity := string(ch.Identity)
|
chIdentity := string(ch.Identity)
|
||||||
if _, exists := st.userStates[chIdentity]; exists {
|
if _, exists := st.userStates[chIdentity]; exists {
|
||||||
return ErrUserAlreadyExists
|
return ErrUserAlreadyExists
|
||||||
}
|
}
|
||||||
|
|
||||||
st.userStates[chIdentity] = &aclrecordproto2.ACLUserState{
|
st.userStates[chIdentity] = &aclrecordproto2.AclUserState{
|
||||||
Identity: ch.Identity,
|
Identity: ch.Identity,
|
||||||
EncryptionKey: ch.EncryptionKey,
|
EncryptionKey: ch.EncryptionKey,
|
||||||
Permissions: ch.Permissions,
|
Permissions: ch.Permissions,
|
||||||
@ -371,7 +371,7 @@ func (st *ACLState) applyUserAdd(ch *aclrecordproto2.ACLUserAdd) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *ACLState) applyUserRemove(ch *aclrecordproto2.ACLUserRemove) error {
|
func (st *AclState) applyUserRemove(ch *aclrecordproto2.AclUserRemove) error {
|
||||||
chIdentity := string(ch.Identity)
|
chIdentity := string(ch.Identity)
|
||||||
if chIdentity == st.identity {
|
if chIdentity == st.identity {
|
||||||
return ErrDocumentForbidden
|
return ErrDocumentForbidden
|
||||||
@ -399,7 +399,7 @@ func (st *ACLState) applyUserRemove(ch *aclrecordproto2.ACLUserRemove) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *ACLState) decryptReadKeyAndHash(msg []byte) (*symmetric.Key, uint64, error) {
|
func (st *AclState) decryptReadKeyAndHash(msg []byte) (*symmetric.Key, uint64, error) {
|
||||||
decrypted, err := st.encryptionKey.Decrypt(msg)
|
decrypted, err := st.encryptionKey.Decrypt(msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, ErrFailedToDecrypt
|
return nil, 0, ErrFailedToDecrypt
|
||||||
@ -415,7 +415,7 @@ func (st *ACLState) decryptReadKeyAndHash(msg []byte) (*symmetric.Key, uint64, e
|
|||||||
return key, hasher.Sum64(), nil
|
return key, hasher.Sum64(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *ACLState) HasPermission(identity []byte, permission aclrecordproto2.ACLUserPermissions) bool {
|
func (st *AclState) HasPermission(identity []byte, permission aclrecordproto2.AclUserPermissions) bool {
|
||||||
state, exists := st.userStates[string(identity)]
|
state, exists := st.userStates[string(identity)]
|
||||||
if !exists {
|
if !exists {
|
||||||
return false
|
return false
|
||||||
@ -424,22 +424,22 @@ func (st *ACLState) HasPermission(identity []byte, permission aclrecordproto2.AC
|
|||||||
return state.Permissions == permission
|
return state.Permissions == permission
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *ACLState) isUserJoin(data *aclrecordproto2.ACLData) bool {
|
func (st *AclState) isUserJoin(data *aclrecordproto2.AclData) bool {
|
||||||
// if we have a UserJoin, then it should always be the first one applied
|
// if we have a UserJoin, then it should always be the first one applied
|
||||||
return data.GetAclContent() != nil && data.GetAclContent()[0].GetUserJoin() != nil
|
return data.GetAclContent() != nil && data.GetAclContent()[0].GetUserJoin() != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *ACLState) isUserAdd(data *aclrecordproto2.ACLData, identity []byte) bool {
|
func (st *AclState) isUserAdd(data *aclrecordproto2.AclData, identity []byte) bool {
|
||||||
// if we have a UserAdd, then it should always be the first one applied
|
// if we have a UserAdd, then it should always be the first one applied
|
||||||
userAdd := data.GetAclContent()[0].GetUserAdd()
|
userAdd := data.GetAclContent()[0].GetUserAdd()
|
||||||
return data.GetAclContent() != nil && userAdd != nil && bytes.Compare(userAdd.GetIdentity(), identity) == 0
|
return data.GetAclContent() != nil && userAdd != nil && bytes.Compare(userAdd.GetIdentity(), identity) == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *ACLState) UserStates() map[string]*aclrecordproto2.ACLUserState {
|
func (st *AclState) UserStates() map[string]*aclrecordproto2.AclUserState {
|
||||||
return st.userStates
|
return st.userStates
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *ACLState) Invite(acceptPubKey []byte) (invite *aclrecordproto2.ACLUserInvite, err error) {
|
func (st *AclState) Invite(acceptPubKey []byte) (invite *aclrecordproto2.AclUserInvite, err error) {
|
||||||
invite, exists := st.userInvites[string(acceptPubKey)]
|
invite, exists := st.userInvites[string(acceptPubKey)]
|
||||||
if !exists {
|
if !exists {
|
||||||
err = ErrNoSuchInvite
|
err = ErrNoSuchInvite
|
||||||
@ -451,14 +451,14 @@ func (st *ACLState) Invite(acceptPubKey []byte) (invite *aclrecordproto2.ACLUser
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *ACLState) UserKeys() (encKey encryptionkey.PrivKey, signKey signingkey.PrivKey) {
|
func (st *AclState) UserKeys() (encKey encryptionkey.PrivKey, signKey signingkey.PrivKey) {
|
||||||
return st.encryptionKey, st.signingKey
|
return st.encryptionKey, st.signingKey
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *ACLState) Identity() []byte {
|
func (st *AclState) Identity() []byte {
|
||||||
return []byte(st.identity)
|
return []byte(st.identity)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *ACLState) LastRecordId() string {
|
func (st *AclState) LastRecordId() string {
|
||||||
return st.lastRecordId
|
return st.lastRecordId
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,14 +12,14 @@ type aclStateBuilder struct {
|
|||||||
id string
|
id string
|
||||||
}
|
}
|
||||||
|
|
||||||
func newACLStateBuilderWithIdentity(accountData *accountdata.AccountData) *aclStateBuilder {
|
func newAclStateBuilderWithIdentity(accountData *accountdata.AccountData) *aclStateBuilder {
|
||||||
return &aclStateBuilder{
|
return &aclStateBuilder{
|
||||||
signPrivKey: accountData.SignKey,
|
signPrivKey: accountData.SignKey,
|
||||||
encPrivKey: accountData.EncKey,
|
encPrivKey: accountData.EncKey,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newACLStateBuilder() *aclStateBuilder {
|
func newAclStateBuilder() *aclStateBuilder {
|
||||||
return &aclStateBuilder{}
|
return &aclStateBuilder{}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,14 +27,14 @@ func (sb *aclStateBuilder) Init(id string) {
|
|||||||
sb.id = id
|
sb.id = id
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sb *aclStateBuilder) Build(records []*ACLRecord) (state *ACLState, err error) {
|
func (sb *aclStateBuilder) Build(records []*AclRecord) (state *AclState, err error) {
|
||||||
if sb.encPrivKey != nil && sb.signPrivKey != nil {
|
if sb.encPrivKey != nil && sb.signPrivKey != nil {
|
||||||
state, err = newACLStateWithKeys(sb.id, sb.signPrivKey, sb.encPrivKey)
|
state, err = newAclStateWithKeys(sb.id, sb.signPrivKey, sb.encPrivKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
state = newACLState(sb.id)
|
state = newAclState(sb.id)
|
||||||
}
|
}
|
||||||
for _, rec := range records {
|
for _, rec := range records {
|
||||||
err = state.applyRecord(rec)
|
err = state.applyRecord(rec)
|
||||||
@ -46,7 +46,7 @@ func (sb *aclStateBuilder) Build(records []*ACLRecord) (state *ACLState, err err
|
|||||||
return state, err
|
return state, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sb *aclStateBuilder) Append(state *ACLState, records []*ACLRecord) (err error) {
|
func (sb *aclStateBuilder) Append(state *AclState, records []*AclRecord) (err error) {
|
||||||
for _, rec := range records {
|
for _, rec := range records {
|
||||||
err = state.applyRecord(rec)
|
err = state.applyRecord(rec)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
//go:generate mockgen -destination mock_list/mock_list.go github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/object/acl/list ACLList
|
//go:generate mockgen -destination mock_list/mock_list.go github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/object/acl/list AclList
|
||||||
package list
|
package list
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -12,7 +12,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
type IterFunc = func(record *ACLRecord) (IsContinue bool)
|
type IterFunc = func(record *AclRecord) (IsContinue bool)
|
||||||
|
|
||||||
var ErrIncorrectCID = errors.New("incorrect CID")
|
var ErrIncorrectCID = errors.New("incorrect CID")
|
||||||
|
|
||||||
@ -22,48 +22,48 @@ type RWLocker interface {
|
|||||||
RUnlock()
|
RUnlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
type ACLList interface {
|
type AclList interface {
|
||||||
RWLocker
|
RWLocker
|
||||||
ID() string
|
ID() string
|
||||||
Root() *aclrecordproto.RawACLRecordWithId
|
Root() *aclrecordproto.RawAclRecordWithId
|
||||||
Records() []*ACLRecord
|
Records() []*AclRecord
|
||||||
ACLState() *ACLState
|
AclState() *AclState
|
||||||
IsAfter(first string, second string) (bool, error)
|
IsAfter(first string, second string) (bool, error)
|
||||||
Head() *ACLRecord
|
Head() *AclRecord
|
||||||
Get(id string) (*ACLRecord, error)
|
Get(id string) (*AclRecord, error)
|
||||||
Iterate(iterFunc IterFunc)
|
Iterate(iterFunc IterFunc)
|
||||||
IterateFrom(startId string, iterFunc IterFunc)
|
IterateFrom(startId string, iterFunc IterFunc)
|
||||||
|
|
||||||
AddRawRecord(rawRec *aclrecordproto.RawACLRecordWithId) (added bool, err error)
|
AddRawRecord(rawRec *aclrecordproto.RawAclRecordWithId) (added bool, err error)
|
||||||
|
|
||||||
Close() (err error)
|
Close() (err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type aclList struct {
|
type aclList struct {
|
||||||
root *aclrecordproto.RawACLRecordWithId
|
root *aclrecordproto.RawAclRecordWithId
|
||||||
records []*ACLRecord
|
records []*AclRecord
|
||||||
indexes map[string]int
|
indexes map[string]int
|
||||||
id string
|
id string
|
||||||
|
|
||||||
stateBuilder *aclStateBuilder
|
stateBuilder *aclStateBuilder
|
||||||
recordBuilder ACLRecordBuilder
|
recordBuilder AclRecordBuilder
|
||||||
aclState *ACLState
|
aclState *AclState
|
||||||
keychain *keychain.Keychain
|
keychain *keychain.Keychain
|
||||||
storage liststorage.ListStorage
|
storage liststorage.ListStorage
|
||||||
|
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func BuildACLListWithIdentity(acc *accountdata.AccountData, storage liststorage.ListStorage) (ACLList, error) {
|
func BuildAclListWithIdentity(acc *accountdata.AccountData, storage liststorage.ListStorage) (AclList, error) {
|
||||||
builder := newACLStateBuilderWithIdentity(acc)
|
builder := newAclStateBuilderWithIdentity(acc)
|
||||||
return build(storage.Id(), builder, newACLRecordBuilder(storage.Id(), keychain.NewKeychain()), storage)
|
return build(storage.Id(), builder, newAclRecordBuilder(storage.Id(), keychain.NewKeychain()), storage)
|
||||||
}
|
}
|
||||||
|
|
||||||
func BuildACLList(storage liststorage.ListStorage) (ACLList, error) {
|
func BuildAclList(storage liststorage.ListStorage) (AclList, error) {
|
||||||
return build(storage.Id(), newACLStateBuilder(), newACLRecordBuilder(storage.Id(), keychain.NewKeychain()), storage)
|
return build(storage.Id(), newAclStateBuilder(), newAclRecordBuilder(storage.Id(), keychain.NewKeychain()), storage)
|
||||||
}
|
}
|
||||||
|
|
||||||
func build(id string, stateBuilder *aclStateBuilder, recBuilder ACLRecordBuilder, storage liststorage.ListStorage) (list ACLList, err error) {
|
func build(id string, stateBuilder *aclStateBuilder, recBuilder AclRecordBuilder, storage liststorage.ListStorage) (list AclList, err error) {
|
||||||
head, err := storage.Head()
|
head, err := storage.Head()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@ -78,7 +78,7 @@ func build(id string, stateBuilder *aclStateBuilder, recBuilder ACLRecordBuilder
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
records := []*ACLRecord{record}
|
records := []*AclRecord{record}
|
||||||
|
|
||||||
for record.PrevId != "" {
|
for record.PrevId != "" {
|
||||||
rawRecordWithId, err = storage.GetRawRecord(context.Background(), record.PrevId)
|
rawRecordWithId, err = storage.GetRawRecord(context.Background(), record.PrevId)
|
||||||
@ -129,11 +129,11 @@ func build(id string, stateBuilder *aclStateBuilder, recBuilder ACLRecordBuilder
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *aclList) Records() []*ACLRecord {
|
func (a *aclList) Records() []*AclRecord {
|
||||||
return a.records
|
return a.records
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *aclList) AddRawRecord(rawRec *aclrecordproto.RawACLRecordWithId) (added bool, err error) {
|
func (a *aclList) AddRawRecord(rawRec *aclrecordproto.RawAclRecordWithId) (added bool, err error) {
|
||||||
if _, ok := a.indexes[rawRec.Id]; ok {
|
if _, ok := a.indexes[rawRec.Id]; ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -155,7 +155,7 @@ func (a *aclList) AddRawRecord(rawRec *aclrecordproto.RawACLRecordWithId) (added
|
|||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *aclList) IsValidNext(rawRec *aclrecordproto.RawACLRecordWithId) (err error) {
|
func (a *aclList) IsValidNext(rawRec *aclrecordproto.RawAclRecordWithId) (err error) {
|
||||||
_, err = a.recordBuilder.ConvertFromRaw(rawRec)
|
_, err = a.recordBuilder.ConvertFromRaw(rawRec)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@ -168,11 +168,11 @@ func (a *aclList) ID() string {
|
|||||||
return a.id
|
return a.id
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *aclList) Root() *aclrecordproto.RawACLRecordWithId {
|
func (a *aclList) Root() *aclrecordproto.RawAclRecordWithId {
|
||||||
return a.root
|
return a.root
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *aclList) ACLState() *ACLState {
|
func (a *aclList) AclState() *AclState {
|
||||||
return a.aclState
|
return a.aclState
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,11 +185,11 @@ func (a *aclList) IsAfter(first string, second string) (bool, error) {
|
|||||||
return firstRec >= secondRec, nil
|
return firstRec >= secondRec, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *aclList) Head() *ACLRecord {
|
func (a *aclList) Head() *AclRecord {
|
||||||
return a.records[len(a.records)-1]
|
return a.records[len(a.records)-1]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *aclList) Get(id string) (*ACLRecord, error) {
|
func (a *aclList) Get(id string) (*AclRecord, error) {
|
||||||
recIdx, ok := a.indexes[id]
|
recIdx, ok := a.indexes[id]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("no such record")
|
return nil, fmt.Errorf("no such record")
|
||||||
|
|||||||
@ -8,13 +8,13 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAclList_ACLState_UserInviteAndJoin(t *testing.T) {
|
func TestAclList_AclState_UserInviteAndJoin(t *testing.T) {
|
||||||
st, err := acllistbuilder.NewListStorageWithTestName("userjoinexample.yml")
|
st, err := acllistbuilder.NewListStorageWithTestName("userjoinexample.yml")
|
||||||
require.NoError(t, err, "building storage should not result in error")
|
require.NoError(t, err, "building storage should not result in error")
|
||||||
|
|
||||||
keychain := st.(*acllistbuilder.ACLListStorageBuilder).GetKeychain()
|
keychain := st.(*acllistbuilder.AclListStorageBuilder).GetKeychain()
|
||||||
|
|
||||||
aclList, err := BuildACLList(st)
|
aclList, err := BuildAclList(st)
|
||||||
require.NoError(t, err, "building acl list should be without error")
|
require.NoError(t, err, "building acl list should be without error")
|
||||||
|
|
||||||
idA := keychain.GetIdentity("A")
|
idA := keychain.GetIdentity("A")
|
||||||
@ -22,13 +22,13 @@ func TestAclList_ACLState_UserInviteAndJoin(t *testing.T) {
|
|||||||
idC := keychain.GetIdentity("C")
|
idC := keychain.GetIdentity("C")
|
||||||
|
|
||||||
// checking final state
|
// checking final state
|
||||||
assert.Equal(t, aclrecordproto.ACLUserPermissions_Admin, aclList.ACLState().UserStates()[idA].Permissions)
|
assert.Equal(t, aclrecordproto.AclUserPermissions_Admin, aclList.AclState().UserStates()[idA].Permissions)
|
||||||
assert.Equal(t, aclrecordproto.ACLUserPermissions_Writer, aclList.ACLState().UserStates()[idB].Permissions)
|
assert.Equal(t, aclrecordproto.AclUserPermissions_Writer, aclList.AclState().UserStates()[idB].Permissions)
|
||||||
assert.Equal(t, aclrecordproto.ACLUserPermissions_Reader, aclList.ACLState().UserStates()[idC].Permissions)
|
assert.Equal(t, aclrecordproto.AclUserPermissions_Reader, aclList.AclState().UserStates()[idC].Permissions)
|
||||||
assert.Equal(t, aclList.Head().CurrentReadKeyHash, aclList.ACLState().CurrentReadKeyHash())
|
assert.Equal(t, aclList.Head().CurrentReadKeyHash, aclList.AclState().CurrentReadKeyHash())
|
||||||
|
|
||||||
var records []*ACLRecord
|
var records []*AclRecord
|
||||||
aclList.Iterate(func(record *ACLRecord) (IsContinue bool) {
|
aclList.Iterate(func(record *AclRecord) (IsContinue bool) {
|
||||||
records = append(records, record)
|
records = append(records, record)
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
@ -36,24 +36,24 @@ func TestAclList_ACLState_UserInviteAndJoin(t *testing.T) {
|
|||||||
// checking permissions at specific records
|
// checking permissions at specific records
|
||||||
assert.Equal(t, 3, len(records))
|
assert.Equal(t, 3, len(records))
|
||||||
|
|
||||||
_, err = aclList.ACLState().PermissionsAtRecord(records[1].Id, idB)
|
_, err = aclList.AclState().PermissionsAtRecord(records[1].Id, idB)
|
||||||
assert.Error(t, err, "B should have no permissions at record 1")
|
assert.Error(t, err, "B should have no permissions at record 1")
|
||||||
|
|
||||||
perm, err := aclList.ACLState().PermissionsAtRecord(records[2].Id, idB)
|
perm, err := aclList.AclState().PermissionsAtRecord(records[2].Id, idB)
|
||||||
assert.NoError(t, err, "should have no error with permissions of B in the record 2")
|
assert.NoError(t, err, "should have no error with permissions of B in the record 2")
|
||||||
assert.Equal(t, UserPermissionPair{
|
assert.Equal(t, UserPermissionPair{
|
||||||
Identity: idB,
|
Identity: idB,
|
||||||
Permission: aclrecordproto.ACLUserPermissions_Writer,
|
Permission: aclrecordproto.AclUserPermissions_Writer,
|
||||||
}, perm)
|
}, perm)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAclList_ACLState_UserJoinAndRemove(t *testing.T) {
|
func TestAclList_AclState_UserJoinAndRemove(t *testing.T) {
|
||||||
st, err := acllistbuilder.NewListStorageWithTestName("userremoveexample.yml")
|
st, err := acllistbuilder.NewListStorageWithTestName("userremoveexample.yml")
|
||||||
require.NoError(t, err, "building storage should not result in error")
|
require.NoError(t, err, "building storage should not result in error")
|
||||||
|
|
||||||
keychain := st.(*acllistbuilder.ACLListStorageBuilder).GetKeychain()
|
keychain := st.(*acllistbuilder.AclListStorageBuilder).GetKeychain()
|
||||||
|
|
||||||
aclList, err := BuildACLList(st)
|
aclList, err := BuildAclList(st)
|
||||||
require.NoError(t, err, "building acl list should be without error")
|
require.NoError(t, err, "building acl list should be without error")
|
||||||
|
|
||||||
idA := keychain.GetIdentity("A")
|
idA := keychain.GetIdentity("A")
|
||||||
@ -61,15 +61,15 @@ func TestAclList_ACLState_UserJoinAndRemove(t *testing.T) {
|
|||||||
idC := keychain.GetIdentity("C")
|
idC := keychain.GetIdentity("C")
|
||||||
|
|
||||||
// checking final state
|
// checking final state
|
||||||
assert.Equal(t, aclrecordproto.ACLUserPermissions_Admin, aclList.ACLState().UserStates()[idA].Permissions)
|
assert.Equal(t, aclrecordproto.AclUserPermissions_Admin, aclList.AclState().UserStates()[idA].Permissions)
|
||||||
assert.Equal(t, aclrecordproto.ACLUserPermissions_Reader, aclList.ACLState().UserStates()[idC].Permissions)
|
assert.Equal(t, aclrecordproto.AclUserPermissions_Reader, aclList.AclState().UserStates()[idC].Permissions)
|
||||||
assert.Equal(t, aclList.Head().CurrentReadKeyHash, aclList.ACLState().CurrentReadKeyHash())
|
assert.Equal(t, aclList.Head().CurrentReadKeyHash, aclList.AclState().CurrentReadKeyHash())
|
||||||
|
|
||||||
_, exists := aclList.ACLState().UserStates()[idB]
|
_, exists := aclList.AclState().UserStates()[idB]
|
||||||
assert.Equal(t, false, exists)
|
assert.Equal(t, false, exists)
|
||||||
|
|
||||||
var records []*ACLRecord
|
var records []*AclRecord
|
||||||
aclList.Iterate(func(record *ACLRecord) (IsContinue bool) {
|
aclList.Iterate(func(record *AclRecord) (IsContinue bool) {
|
||||||
records = append(records, record)
|
records = append(records, record)
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
@ -77,15 +77,15 @@ func TestAclList_ACLState_UserJoinAndRemove(t *testing.T) {
|
|||||||
// checking permissions at specific records
|
// checking permissions at specific records
|
||||||
assert.Equal(t, 4, len(records))
|
assert.Equal(t, 4, len(records))
|
||||||
|
|
||||||
assert.NotEqual(t, records[2].CurrentReadKeyHash, aclList.ACLState().CurrentReadKeyHash())
|
assert.NotEqual(t, records[2].CurrentReadKeyHash, aclList.AclState().CurrentReadKeyHash())
|
||||||
|
|
||||||
perm, err := aclList.ACLState().PermissionsAtRecord(records[2].Id, idB)
|
perm, err := aclList.AclState().PermissionsAtRecord(records[2].Id, idB)
|
||||||
assert.NoError(t, err, "should have no error with permissions of B in the record 2")
|
assert.NoError(t, err, "should have no error with permissions of B in the record 2")
|
||||||
assert.Equal(t, UserPermissionPair{
|
assert.Equal(t, UserPermissionPair{
|
||||||
Identity: idB,
|
Identity: idB,
|
||||||
Permission: aclrecordproto.ACLUserPermissions_Writer,
|
Permission: aclrecordproto.AclUserPermissions_Writer,
|
||||||
}, perm)
|
}, perm)
|
||||||
|
|
||||||
_, err = aclList.ACLState().PermissionsAtRecord(records[3].Id, idB)
|
_, err = aclList.AclState().PermissionsAtRecord(records[3].Id, idB)
|
||||||
assert.Error(t, err, "B should have no permissions at record 3, because user should be removed")
|
assert.Error(t, err, "B should have no permissions at record 3, because user should be removed")
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
// Code generated by MockGen. DO NOT EDIT.
|
// Code generated by MockGen. DO NOT EDIT.
|
||||||
// Source: github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/object/acl/list (interfaces: ACLList)
|
// Source: github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/object/acl/list (interfaces: AclList)
|
||||||
|
|
||||||
// Package mock_list is a generated GoMock package.
|
// Package mock_list is a generated GoMock package.
|
||||||
package mock_list
|
package mock_list
|
||||||
@ -12,45 +12,45 @@ import (
|
|||||||
gomock "github.com/golang/mock/gomock"
|
gomock "github.com/golang/mock/gomock"
|
||||||
)
|
)
|
||||||
|
|
||||||
// MockACLList is a mock of ACLList interface.
|
// MockAclList is a mock of AclList interface.
|
||||||
type MockACLList struct {
|
type MockAclList struct {
|
||||||
ctrl *gomock.Controller
|
ctrl *gomock.Controller
|
||||||
recorder *MockACLListMockRecorder
|
recorder *MockAclListMockRecorder
|
||||||
}
|
}
|
||||||
|
|
||||||
// MockACLListMockRecorder is the mock recorder for MockACLList.
|
// MockAclListMockRecorder is the mock recorder for MockAclList.
|
||||||
type MockACLListMockRecorder struct {
|
type MockAclListMockRecorder struct {
|
||||||
mock *MockACLList
|
mock *MockAclList
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewMockACLList creates a new mock instance.
|
// NewMockAclList creates a new mock instance.
|
||||||
func NewMockACLList(ctrl *gomock.Controller) *MockACLList {
|
func NewMockAclList(ctrl *gomock.Controller) *MockAclList {
|
||||||
mock := &MockACLList{ctrl: ctrl}
|
mock := &MockAclList{ctrl: ctrl}
|
||||||
mock.recorder = &MockACLListMockRecorder{mock}
|
mock.recorder = &MockAclListMockRecorder{mock}
|
||||||
return mock
|
return mock
|
||||||
}
|
}
|
||||||
|
|
||||||
// EXPECT returns an object that allows the caller to indicate expected use.
|
// EXPECT returns an object that allows the caller to indicate expected use.
|
||||||
func (m *MockACLList) EXPECT() *MockACLListMockRecorder {
|
func (m *MockAclList) EXPECT() *MockAclListMockRecorder {
|
||||||
return m.recorder
|
return m.recorder
|
||||||
}
|
}
|
||||||
|
|
||||||
// ACLState mocks base method.
|
// AclState mocks base method.
|
||||||
func (m *MockACLList) ACLState() *list.ACLState {
|
func (m *MockAclList) AclState() *list.AclState {
|
||||||
m.ctrl.T.Helper()
|
m.ctrl.T.Helper()
|
||||||
ret := m.ctrl.Call(m, "ACLState")
|
ret := m.ctrl.Call(m, "AclState")
|
||||||
ret0, _ := ret[0].(*list.ACLState)
|
ret0, _ := ret[0].(*list.AclState)
|
||||||
return ret0
|
return ret0
|
||||||
}
|
}
|
||||||
|
|
||||||
// ACLState indicates an expected call of ACLState.
|
// AclState indicates an expected call of AclState.
|
||||||
func (mr *MockACLListMockRecorder) ACLState() *gomock.Call {
|
func (mr *MockAclListMockRecorder) AclState() *gomock.Call {
|
||||||
mr.mock.ctrl.T.Helper()
|
mr.mock.ctrl.T.Helper()
|
||||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ACLState", reflect.TypeOf((*MockACLList)(nil).ACLState))
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AclState", reflect.TypeOf((*MockAclList)(nil).AclState))
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddRawRecord mocks base method.
|
// AddRawRecord mocks base method.
|
||||||
func (m *MockACLList) AddRawRecord(arg0 *aclrecordproto.RawACLRecordWithId) (bool, error) {
|
func (m *MockAclList) AddRawRecord(arg0 *aclrecordproto.RawAclRecordWithId) (bool, error) {
|
||||||
m.ctrl.T.Helper()
|
m.ctrl.T.Helper()
|
||||||
ret := m.ctrl.Call(m, "AddRawRecord", arg0)
|
ret := m.ctrl.Call(m, "AddRawRecord", arg0)
|
||||||
ret0, _ := ret[0].(bool)
|
ret0, _ := ret[0].(bool)
|
||||||
@ -59,13 +59,13 @@ func (m *MockACLList) AddRawRecord(arg0 *aclrecordproto.RawACLRecordWithId) (boo
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddRawRecord indicates an expected call of AddRawRecord.
|
// AddRawRecord indicates an expected call of AddRawRecord.
|
||||||
func (mr *MockACLListMockRecorder) AddRawRecord(arg0 interface{}) *gomock.Call {
|
func (mr *MockAclListMockRecorder) AddRawRecord(arg0 interface{}) *gomock.Call {
|
||||||
mr.mock.ctrl.T.Helper()
|
mr.mock.ctrl.T.Helper()
|
||||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddRawRecord", reflect.TypeOf((*MockACLList)(nil).AddRawRecord), arg0)
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddRawRecord", reflect.TypeOf((*MockAclList)(nil).AddRawRecord), arg0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close mocks base method.
|
// Close mocks base method.
|
||||||
func (m *MockACLList) Close() error {
|
func (m *MockAclList) Close() error {
|
||||||
m.ctrl.T.Helper()
|
m.ctrl.T.Helper()
|
||||||
ret := m.ctrl.Call(m, "Close")
|
ret := m.ctrl.Call(m, "Close")
|
||||||
ret0, _ := ret[0].(error)
|
ret0, _ := ret[0].(error)
|
||||||
@ -73,42 +73,42 @@ func (m *MockACLList) Close() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Close indicates an expected call of Close.
|
// Close indicates an expected call of Close.
|
||||||
func (mr *MockACLListMockRecorder) Close() *gomock.Call {
|
func (mr *MockAclListMockRecorder) Close() *gomock.Call {
|
||||||
mr.mock.ctrl.T.Helper()
|
mr.mock.ctrl.T.Helper()
|
||||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Close", reflect.TypeOf((*MockACLList)(nil).Close))
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Close", reflect.TypeOf((*MockAclList)(nil).Close))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get mocks base method.
|
// Get mocks base method.
|
||||||
func (m *MockACLList) Get(arg0 string) (*list.ACLRecord, error) {
|
func (m *MockAclList) Get(arg0 string) (*list.AclRecord, error) {
|
||||||
m.ctrl.T.Helper()
|
m.ctrl.T.Helper()
|
||||||
ret := m.ctrl.Call(m, "Get", arg0)
|
ret := m.ctrl.Call(m, "Get", arg0)
|
||||||
ret0, _ := ret[0].(*list.ACLRecord)
|
ret0, _ := ret[0].(*list.AclRecord)
|
||||||
ret1, _ := ret[1].(error)
|
ret1, _ := ret[1].(error)
|
||||||
return ret0, ret1
|
return ret0, ret1
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get indicates an expected call of Get.
|
// Get indicates an expected call of Get.
|
||||||
func (mr *MockACLListMockRecorder) Get(arg0 interface{}) *gomock.Call {
|
func (mr *MockAclListMockRecorder) Get(arg0 interface{}) *gomock.Call {
|
||||||
mr.mock.ctrl.T.Helper()
|
mr.mock.ctrl.T.Helper()
|
||||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockACLList)(nil).Get), arg0)
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockAclList)(nil).Get), arg0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Head mocks base method.
|
// Head mocks base method.
|
||||||
func (m *MockACLList) Head() *list.ACLRecord {
|
func (m *MockAclList) Head() *list.AclRecord {
|
||||||
m.ctrl.T.Helper()
|
m.ctrl.T.Helper()
|
||||||
ret := m.ctrl.Call(m, "Head")
|
ret := m.ctrl.Call(m, "Head")
|
||||||
ret0, _ := ret[0].(*list.ACLRecord)
|
ret0, _ := ret[0].(*list.AclRecord)
|
||||||
return ret0
|
return ret0
|
||||||
}
|
}
|
||||||
|
|
||||||
// Head indicates an expected call of Head.
|
// Head indicates an expected call of Head.
|
||||||
func (mr *MockACLListMockRecorder) Head() *gomock.Call {
|
func (mr *MockAclListMockRecorder) Head() *gomock.Call {
|
||||||
mr.mock.ctrl.T.Helper()
|
mr.mock.ctrl.T.Helper()
|
||||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Head", reflect.TypeOf((*MockACLList)(nil).Head))
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Head", reflect.TypeOf((*MockAclList)(nil).Head))
|
||||||
}
|
}
|
||||||
|
|
||||||
// ID mocks base method.
|
// ID mocks base method.
|
||||||
func (m *MockACLList) ID() string {
|
func (m *MockAclList) ID() string {
|
||||||
m.ctrl.T.Helper()
|
m.ctrl.T.Helper()
|
||||||
ret := m.ctrl.Call(m, "ID")
|
ret := m.ctrl.Call(m, "ID")
|
||||||
ret0, _ := ret[0].(string)
|
ret0, _ := ret[0].(string)
|
||||||
@ -116,13 +116,13 @@ func (m *MockACLList) ID() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ID indicates an expected call of ID.
|
// ID indicates an expected call of ID.
|
||||||
func (mr *MockACLListMockRecorder) ID() *gomock.Call {
|
func (mr *MockAclListMockRecorder) ID() *gomock.Call {
|
||||||
mr.mock.ctrl.T.Helper()
|
mr.mock.ctrl.T.Helper()
|
||||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ID", reflect.TypeOf((*MockACLList)(nil).ID))
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ID", reflect.TypeOf((*MockAclList)(nil).ID))
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsAfter mocks base method.
|
// IsAfter mocks base method.
|
||||||
func (m *MockACLList) IsAfter(arg0, arg1 string) (bool, error) {
|
func (m *MockAclList) IsAfter(arg0, arg1 string) (bool, error) {
|
||||||
m.ctrl.T.Helper()
|
m.ctrl.T.Helper()
|
||||||
ret := m.ctrl.Call(m, "IsAfter", arg0, arg1)
|
ret := m.ctrl.Call(m, "IsAfter", arg0, arg1)
|
||||||
ret0, _ := ret[0].(bool)
|
ret0, _ := ret[0].(bool)
|
||||||
@ -131,107 +131,107 @@ func (m *MockACLList) IsAfter(arg0, arg1 string) (bool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// IsAfter indicates an expected call of IsAfter.
|
// IsAfter indicates an expected call of IsAfter.
|
||||||
func (mr *MockACLListMockRecorder) IsAfter(arg0, arg1 interface{}) *gomock.Call {
|
func (mr *MockAclListMockRecorder) IsAfter(arg0, arg1 interface{}) *gomock.Call {
|
||||||
mr.mock.ctrl.T.Helper()
|
mr.mock.ctrl.T.Helper()
|
||||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsAfter", reflect.TypeOf((*MockACLList)(nil).IsAfter), arg0, arg1)
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsAfter", reflect.TypeOf((*MockAclList)(nil).IsAfter), arg0, arg1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iterate mocks base method.
|
// Iterate mocks base method.
|
||||||
func (m *MockACLList) Iterate(arg0 func(*list.ACLRecord) bool) {
|
func (m *MockAclList) Iterate(arg0 func(*list.AclRecord) bool) {
|
||||||
m.ctrl.T.Helper()
|
m.ctrl.T.Helper()
|
||||||
m.ctrl.Call(m, "Iterate", arg0)
|
m.ctrl.Call(m, "Iterate", arg0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iterate indicates an expected call of Iterate.
|
// Iterate indicates an expected call of Iterate.
|
||||||
func (mr *MockACLListMockRecorder) Iterate(arg0 interface{}) *gomock.Call {
|
func (mr *MockAclListMockRecorder) Iterate(arg0 interface{}) *gomock.Call {
|
||||||
mr.mock.ctrl.T.Helper()
|
mr.mock.ctrl.T.Helper()
|
||||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Iterate", reflect.TypeOf((*MockACLList)(nil).Iterate), arg0)
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Iterate", reflect.TypeOf((*MockAclList)(nil).Iterate), arg0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// IterateFrom mocks base method.
|
// IterateFrom mocks base method.
|
||||||
func (m *MockACLList) IterateFrom(arg0 string, arg1 func(*list.ACLRecord) bool) {
|
func (m *MockAclList) IterateFrom(arg0 string, arg1 func(*list.AclRecord) bool) {
|
||||||
m.ctrl.T.Helper()
|
m.ctrl.T.Helper()
|
||||||
m.ctrl.Call(m, "IterateFrom", arg0, arg1)
|
m.ctrl.Call(m, "IterateFrom", arg0, arg1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// IterateFrom indicates an expected call of IterateFrom.
|
// IterateFrom indicates an expected call of IterateFrom.
|
||||||
func (mr *MockACLListMockRecorder) IterateFrom(arg0, arg1 interface{}) *gomock.Call {
|
func (mr *MockAclListMockRecorder) IterateFrom(arg0, arg1 interface{}) *gomock.Call {
|
||||||
mr.mock.ctrl.T.Helper()
|
mr.mock.ctrl.T.Helper()
|
||||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IterateFrom", reflect.TypeOf((*MockACLList)(nil).IterateFrom), arg0, arg1)
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IterateFrom", reflect.TypeOf((*MockAclList)(nil).IterateFrom), arg0, arg1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lock mocks base method.
|
// Lock mocks base method.
|
||||||
func (m *MockACLList) Lock() {
|
func (m *MockAclList) Lock() {
|
||||||
m.ctrl.T.Helper()
|
m.ctrl.T.Helper()
|
||||||
m.ctrl.Call(m, "Lock")
|
m.ctrl.Call(m, "Lock")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lock indicates an expected call of Lock.
|
// Lock indicates an expected call of Lock.
|
||||||
func (mr *MockACLListMockRecorder) Lock() *gomock.Call {
|
func (mr *MockAclListMockRecorder) Lock() *gomock.Call {
|
||||||
mr.mock.ctrl.T.Helper()
|
mr.mock.ctrl.T.Helper()
|
||||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Lock", reflect.TypeOf((*MockACLList)(nil).Lock))
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Lock", reflect.TypeOf((*MockAclList)(nil).Lock))
|
||||||
}
|
}
|
||||||
|
|
||||||
// RLock mocks base method.
|
// RLock mocks base method.
|
||||||
func (m *MockACLList) RLock() {
|
func (m *MockAclList) RLock() {
|
||||||
m.ctrl.T.Helper()
|
m.ctrl.T.Helper()
|
||||||
m.ctrl.Call(m, "RLock")
|
m.ctrl.Call(m, "RLock")
|
||||||
}
|
}
|
||||||
|
|
||||||
// RLock indicates an expected call of RLock.
|
// RLock indicates an expected call of RLock.
|
||||||
func (mr *MockACLListMockRecorder) RLock() *gomock.Call {
|
func (mr *MockAclListMockRecorder) RLock() *gomock.Call {
|
||||||
mr.mock.ctrl.T.Helper()
|
mr.mock.ctrl.T.Helper()
|
||||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RLock", reflect.TypeOf((*MockACLList)(nil).RLock))
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RLock", reflect.TypeOf((*MockAclList)(nil).RLock))
|
||||||
}
|
}
|
||||||
|
|
||||||
// RUnlock mocks base method.
|
// RUnlock mocks base method.
|
||||||
func (m *MockACLList) RUnlock() {
|
func (m *MockAclList) RUnlock() {
|
||||||
m.ctrl.T.Helper()
|
m.ctrl.T.Helper()
|
||||||
m.ctrl.Call(m, "RUnlock")
|
m.ctrl.Call(m, "RUnlock")
|
||||||
}
|
}
|
||||||
|
|
||||||
// RUnlock indicates an expected call of RUnlock.
|
// RUnlock indicates an expected call of RUnlock.
|
||||||
func (mr *MockACLListMockRecorder) RUnlock() *gomock.Call {
|
func (mr *MockAclListMockRecorder) RUnlock() *gomock.Call {
|
||||||
mr.mock.ctrl.T.Helper()
|
mr.mock.ctrl.T.Helper()
|
||||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RUnlock", reflect.TypeOf((*MockACLList)(nil).RUnlock))
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RUnlock", reflect.TypeOf((*MockAclList)(nil).RUnlock))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Records mocks base method.
|
// Records mocks base method.
|
||||||
func (m *MockACLList) Records() []*list.ACLRecord {
|
func (m *MockAclList) Records() []*list.AclRecord {
|
||||||
m.ctrl.T.Helper()
|
m.ctrl.T.Helper()
|
||||||
ret := m.ctrl.Call(m, "Records")
|
ret := m.ctrl.Call(m, "Records")
|
||||||
ret0, _ := ret[0].([]*list.ACLRecord)
|
ret0, _ := ret[0].([]*list.AclRecord)
|
||||||
return ret0
|
return ret0
|
||||||
}
|
}
|
||||||
|
|
||||||
// Records indicates an expected call of Records.
|
// Records indicates an expected call of Records.
|
||||||
func (mr *MockACLListMockRecorder) Records() *gomock.Call {
|
func (mr *MockAclListMockRecorder) Records() *gomock.Call {
|
||||||
mr.mock.ctrl.T.Helper()
|
mr.mock.ctrl.T.Helper()
|
||||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Records", reflect.TypeOf((*MockACLList)(nil).Records))
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Records", reflect.TypeOf((*MockAclList)(nil).Records))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Root mocks base method.
|
// Root mocks base method.
|
||||||
func (m *MockACLList) Root() *aclrecordproto.RawACLRecordWithId {
|
func (m *MockAclList) Root() *aclrecordproto.RawAclRecordWithId {
|
||||||
m.ctrl.T.Helper()
|
m.ctrl.T.Helper()
|
||||||
ret := m.ctrl.Call(m, "Root")
|
ret := m.ctrl.Call(m, "Root")
|
||||||
ret0, _ := ret[0].(*aclrecordproto.RawACLRecordWithId)
|
ret0, _ := ret[0].(*aclrecordproto.RawAclRecordWithId)
|
||||||
return ret0
|
return ret0
|
||||||
}
|
}
|
||||||
|
|
||||||
// Root indicates an expected call of Root.
|
// Root indicates an expected call of Root.
|
||||||
func (mr *MockACLListMockRecorder) Root() *gomock.Call {
|
func (mr *MockAclListMockRecorder) Root() *gomock.Call {
|
||||||
mr.mock.ctrl.T.Helper()
|
mr.mock.ctrl.T.Helper()
|
||||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Root", reflect.TypeOf((*MockACLList)(nil).Root))
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Root", reflect.TypeOf((*MockAclList)(nil).Root))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unlock mocks base method.
|
// Unlock mocks base method.
|
||||||
func (m *MockACLList) Unlock() {
|
func (m *MockAclList) Unlock() {
|
||||||
m.ctrl.T.Helper()
|
m.ctrl.T.Helper()
|
||||||
m.ctrl.Call(m, "Unlock")
|
m.ctrl.Call(m, "Unlock")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unlock indicates an expected call of Unlock.
|
// Unlock indicates an expected call of Unlock.
|
||||||
func (mr *MockACLListMockRecorder) Unlock() *gomock.Call {
|
func (mr *MockAclListMockRecorder) Unlock() *gomock.Call {
|
||||||
mr.mock.ctrl.T.Helper()
|
mr.mock.ctrl.T.Helper()
|
||||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Unlock", reflect.TypeOf((*MockACLList)(nil).Unlock))
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Unlock", reflect.TypeOf((*MockAclList)(nil).Unlock))
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
package list
|
package list
|
||||||
|
|
||||||
type ACLRecord struct {
|
type AclRecord struct {
|
||||||
Id string
|
Id string
|
||||||
PrevId string
|
PrevId string
|
||||||
CurrentReadKeyHash uint64
|
CurrentReadKeyHash uint64
|
||||||
|
|||||||
@ -7,27 +7,27 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
type inMemoryACLListStorage struct {
|
type inMemoryAclListStorage struct {
|
||||||
id string
|
id string
|
||||||
root *aclrecordproto.RawACLRecordWithId
|
root *aclrecordproto.RawAclRecordWithId
|
||||||
head string
|
head string
|
||||||
records map[string]*aclrecordproto.RawACLRecordWithId
|
records map[string]*aclrecordproto.RawAclRecordWithId
|
||||||
|
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewInMemoryACLListStorage(
|
func NewInMemoryAclListStorage(
|
||||||
id string,
|
id string,
|
||||||
records []*aclrecordproto.RawACLRecordWithId) (ListStorage, error) {
|
records []*aclrecordproto.RawAclRecordWithId) (ListStorage, error) {
|
||||||
|
|
||||||
allRecords := make(map[string]*aclrecordproto.RawACLRecordWithId)
|
allRecords := make(map[string]*aclrecordproto.RawAclRecordWithId)
|
||||||
for _, ch := range records {
|
for _, ch := range records {
|
||||||
allRecords[ch.Id] = ch
|
allRecords[ch.Id] = ch
|
||||||
}
|
}
|
||||||
root := records[0]
|
root := records[0]
|
||||||
head := records[len(records)-1]
|
head := records[len(records)-1]
|
||||||
|
|
||||||
return &inMemoryACLListStorage{
|
return &inMemoryAclListStorage{
|
||||||
id: root.Id,
|
id: root.Id,
|
||||||
root: root,
|
root: root,
|
||||||
head: head.Id,
|
head: head.Id,
|
||||||
@ -35,32 +35,32 @@ func NewInMemoryACLListStorage(
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *inMemoryACLListStorage) Id() string {
|
func (t *inMemoryAclListStorage) Id() string {
|
||||||
t.RLock()
|
t.RLock()
|
||||||
defer t.RUnlock()
|
defer t.RUnlock()
|
||||||
return t.id
|
return t.id
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *inMemoryACLListStorage) Root() (*aclrecordproto.RawACLRecordWithId, error) {
|
func (t *inMemoryAclListStorage) Root() (*aclrecordproto.RawAclRecordWithId, error) {
|
||||||
t.RLock()
|
t.RLock()
|
||||||
defer t.RUnlock()
|
defer t.RUnlock()
|
||||||
return t.root, nil
|
return t.root, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *inMemoryACLListStorage) Head() (string, error) {
|
func (t *inMemoryAclListStorage) Head() (string, error) {
|
||||||
t.RLock()
|
t.RLock()
|
||||||
defer t.RUnlock()
|
defer t.RUnlock()
|
||||||
return t.head, nil
|
return t.head, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *inMemoryACLListStorage) SetHead(head string) error {
|
func (t *inMemoryAclListStorage) SetHead(head string) error {
|
||||||
t.Lock()
|
t.Lock()
|
||||||
defer t.Unlock()
|
defer t.Unlock()
|
||||||
t.head = head
|
t.head = head
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *inMemoryACLListStorage) AddRawRecord(ctx context.Context, record *aclrecordproto.RawACLRecordWithId) error {
|
func (t *inMemoryAclListStorage) AddRawRecord(ctx context.Context, record *aclrecordproto.RawAclRecordWithId) error {
|
||||||
t.Lock()
|
t.Lock()
|
||||||
defer t.Unlock()
|
defer t.Unlock()
|
||||||
// TODO: better to do deep copy
|
// TODO: better to do deep copy
|
||||||
@ -68,7 +68,7 @@ func (t *inMemoryACLListStorage) AddRawRecord(ctx context.Context, record *aclre
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *inMemoryACLListStorage) GetRawRecord(ctx context.Context, recordId string) (*aclrecordproto.RawACLRecordWithId, error) {
|
func (t *inMemoryAclListStorage) GetRawRecord(ctx context.Context, recordId string) (*aclrecordproto.RawAclRecordWithId, error) {
|
||||||
t.RLock()
|
t.RLock()
|
||||||
defer t.RUnlock()
|
defer t.RUnlock()
|
||||||
if res, exists := t.records[recordId]; exists {
|
if res, exists := t.records[recordId]; exists {
|
||||||
|
|||||||
@ -8,17 +8,17 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ErrUnknownACLId = errors.New("acl does not exist")
|
ErrUnknownAclId = errors.New("acl does not exist")
|
||||||
ErrACLExists = errors.New("acl already exists")
|
ErrAclExists = errors.New("acl already exists")
|
||||||
ErrUnknownRecord = errors.New("record doesn't exist")
|
ErrUnknownRecord = errors.New("record doesn't exist")
|
||||||
)
|
)
|
||||||
|
|
||||||
type ListStorage interface {
|
type ListStorage interface {
|
||||||
Id() string
|
Id() string
|
||||||
Root() (*aclrecordproto.RawACLRecordWithId, error)
|
Root() (*aclrecordproto.RawAclRecordWithId, error)
|
||||||
Head() (string, error)
|
Head() (string, error)
|
||||||
SetHead(headId string) error
|
SetHead(headId string) error
|
||||||
|
|
||||||
GetRawRecord(ctx context.Context, id string) (*aclrecordproto.RawACLRecordWithId, error)
|
GetRawRecord(ctx context.Context, id string) (*aclrecordproto.RawAclRecordWithId, error)
|
||||||
AddRawRecord(ctx context.Context, rec *aclrecordproto.RawACLRecordWithId) error
|
AddRawRecord(ctx context.Context, rec *aclrecordproto.RawAclRecordWithId) error
|
||||||
}
|
}
|
||||||
|
|||||||
@ -36,7 +36,7 @@ func (m *MockListStorage) EXPECT() *MockListStorageMockRecorder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddRawRecord mocks base method.
|
// AddRawRecord mocks base method.
|
||||||
func (m *MockListStorage) AddRawRecord(arg0 context.Context, arg1 *aclrecordproto.RawACLRecordWithId) error {
|
func (m *MockListStorage) AddRawRecord(arg0 context.Context, arg1 *aclrecordproto.RawAclRecordWithId) error {
|
||||||
m.ctrl.T.Helper()
|
m.ctrl.T.Helper()
|
||||||
ret := m.ctrl.Call(m, "AddRawRecord", arg0, arg1)
|
ret := m.ctrl.Call(m, "AddRawRecord", arg0, arg1)
|
||||||
ret0, _ := ret[0].(error)
|
ret0, _ := ret[0].(error)
|
||||||
@ -50,10 +50,10 @@ func (mr *MockListStorageMockRecorder) AddRawRecord(arg0, arg1 interface{}) *gom
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetRawRecord mocks base method.
|
// GetRawRecord mocks base method.
|
||||||
func (m *MockListStorage) GetRawRecord(arg0 context.Context, arg1 string) (*aclrecordproto.RawACLRecordWithId, error) {
|
func (m *MockListStorage) GetRawRecord(arg0 context.Context, arg1 string) (*aclrecordproto.RawAclRecordWithId, error) {
|
||||||
m.ctrl.T.Helper()
|
m.ctrl.T.Helper()
|
||||||
ret := m.ctrl.Call(m, "GetRawRecord", arg0, arg1)
|
ret := m.ctrl.Call(m, "GetRawRecord", arg0, arg1)
|
||||||
ret0, _ := ret[0].(*aclrecordproto.RawACLRecordWithId)
|
ret0, _ := ret[0].(*aclrecordproto.RawAclRecordWithId)
|
||||||
ret1, _ := ret[1].(error)
|
ret1, _ := ret[1].(error)
|
||||||
return ret0, ret1
|
return ret0, ret1
|
||||||
}
|
}
|
||||||
@ -94,10 +94,10 @@ func (mr *MockListStorageMockRecorder) Id() *gomock.Call {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Root mocks base method.
|
// Root mocks base method.
|
||||||
func (m *MockListStorage) Root() (*aclrecordproto.RawACLRecordWithId, error) {
|
func (m *MockListStorage) Root() (*aclrecordproto.RawAclRecordWithId, error) {
|
||||||
m.ctrl.T.Helper()
|
m.ctrl.T.Helper()
|
||||||
ret := m.ctrl.Call(m, "Root")
|
ret := m.ctrl.Call(m, "Root")
|
||||||
ret0, _ := ret[0].(*aclrecordproto.RawACLRecordWithId)
|
ret0, _ := ret[0].(*aclrecordproto.RawAclRecordWithId)
|
||||||
ret1, _ := ret[1].(error)
|
ret1, _ := ret[1].(error)
|
||||||
return ret0, ret1
|
return ret0, ret1
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,15 +6,15 @@ import (
|
|||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/objectsync/synchandler"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/objectsync/synchandler"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SyncACL struct {
|
type SyncAcl struct {
|
||||||
list.ACLList
|
list.AclList
|
||||||
synchandler.SyncHandler
|
synchandler.SyncHandler
|
||||||
streamPool objectsync.StreamPool
|
streamPool objectsync.StreamPool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSyncACL(aclList list.ACLList, streamPool objectsync.StreamPool) *SyncACL {
|
func NewSyncAcl(aclList list.AclList, streamPool objectsync.StreamPool) *SyncAcl {
|
||||||
return &SyncACL{
|
return &SyncAcl{
|
||||||
ACLList: aclList,
|
AclList: aclList,
|
||||||
SyncHandler: nil,
|
SyncHandler: nil,
|
||||||
streamPool: streamPool,
|
streamPool: streamPool,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,11 +9,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type syncAclHandler struct {
|
type syncAclHandler struct {
|
||||||
acl list.ACLList
|
acl list.AclList
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *syncAclHandler) HandleMessage(ctx context.Context, senderId string, req *spacesyncproto.ObjectSyncMessage) (err error) {
|
func (s *syncAclHandler) HandleMessage(ctx context.Context, senderId string, req *spacesyncproto.ObjectSyncMessage) (err error) {
|
||||||
aclMsg := &aclrecordproto.ACLSyncMessage{}
|
aclMsg := &aclrecordproto.AclSyncMessage{}
|
||||||
if err = aclMsg.Unmarshal(req.Payload); err != nil {
|
if err = aclMsg.Unmarshal(req.Payload); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -26,6 +26,6 @@ func (s *syncAclHandler) HandleMessage(ctx context.Context, senderId string, req
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *syncAclHandler) handleAddRecords(ctx context.Context, senderId string, addRecord *aclrecordproto.ACLAddRecords) (err error) {
|
func (s *syncAclHandler) handleAddRecords(ctx context.Context, senderId string, addRecord *aclrecordproto.AclAddRecords) (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@ -121,7 +121,7 @@ func (k *YAMLKeychain) AddReadKey(key *Key) {
|
|||||||
} else if key.Value == "derived" {
|
} else if key.Value == "derived" {
|
||||||
signKey, _ := k.SigningKeysByYAMLName[key.Name].Raw()
|
signKey, _ := k.SigningKeysByYAMLName[key.Name].Raw()
|
||||||
encKey, _ := k.EncryptionKeysByYAMLName[key.Name].Raw()
|
encKey, _ := k.EncryptionKeysByYAMLName[key.Name].Raw()
|
||||||
rkey, err = aclrecordproto.ACLReadKeyDerive(signKey, encKey)
|
rkey, err = aclrecordproto.AclReadKeyDerive(signKey, encKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic("should be able to derive symmetric key")
|
panic("should be able to derive symmetric key")
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,23 +18,23 @@ import (
|
|||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ACLListStorageBuilder struct {
|
type AclListStorageBuilder struct {
|
||||||
liststorage.ListStorage
|
liststorage.ListStorage
|
||||||
keychain *YAMLKeychain
|
keychain *YAMLKeychain
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewACLListStorageBuilder(keychain *YAMLKeychain) *ACLListStorageBuilder {
|
func NewAclListStorageBuilder(keychain *YAMLKeychain) *AclListStorageBuilder {
|
||||||
return &ACLListStorageBuilder{
|
return &AclListStorageBuilder{
|
||||||
keychain: keychain,
|
keychain: keychain,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewListStorageWithTestName(name string) (liststorage.ListStorage, error) {
|
func NewListStorageWithTestName(name string) (liststorage.ListStorage, error) {
|
||||||
filePath := path.Join(yamltests.Path(), name)
|
filePath := path.Join(yamltests.Path(), name)
|
||||||
return NewACLListStorageBuilderFromFile(filePath)
|
return NewAclListStorageBuilderFromFile(filePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewACLListStorageBuilderFromFile(file string) (*ACLListStorageBuilder, error) {
|
func NewAclListStorageBuilderFromFile(file string) (*AclListStorageBuilder, error) {
|
||||||
content, err := ioutil.ReadFile(file)
|
content, err := ioutil.ReadFile(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -46,13 +46,13 @@ func NewACLListStorageBuilderFromFile(file string) (*ACLListStorageBuilder, erro
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
tb := NewACLListStorageBuilder(NewKeychain())
|
tb := NewAclListStorageBuilder(NewKeychain())
|
||||||
tb.Parse(&ymlTree)
|
tb.Parse(&ymlTree)
|
||||||
|
|
||||||
return tb, nil
|
return tb, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *ACLListStorageBuilder) createRaw(rec proto.Marshaler, identity []byte) *aclrecordproto.RawACLRecordWithId {
|
func (t *AclListStorageBuilder) createRaw(rec proto.Marshaler, identity []byte) *aclrecordproto.RawAclRecordWithId {
|
||||||
protoMarshalled, err := rec.Marshal()
|
protoMarshalled, err := rec.Marshal()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic("should be able to marshal final acl message!")
|
panic("should be able to marshal final acl message!")
|
||||||
@ -63,7 +63,7 @@ func (t *ACLListStorageBuilder) createRaw(rec proto.Marshaler, identity []byte)
|
|||||||
panic("should be able to sign final acl message!")
|
panic("should be able to sign final acl message!")
|
||||||
}
|
}
|
||||||
|
|
||||||
rawRec := &aclrecordproto.RawACLRecord{
|
rawRec := &aclrecordproto.RawAclRecord{
|
||||||
Payload: protoMarshalled,
|
Payload: protoMarshalled,
|
||||||
Signature: signature,
|
Signature: signature,
|
||||||
}
|
}
|
||||||
@ -75,24 +75,24 @@ func (t *ACLListStorageBuilder) createRaw(rec proto.Marshaler, identity []byte)
|
|||||||
|
|
||||||
id, _ := cidutil.NewCIDFromBytes(rawMarshalled)
|
id, _ := cidutil.NewCIDFromBytes(rawMarshalled)
|
||||||
|
|
||||||
return &aclrecordproto.RawACLRecordWithId{
|
return &aclrecordproto.RawAclRecordWithId{
|
||||||
Payload: rawMarshalled,
|
Payload: rawMarshalled,
|
||||||
Id: id,
|
Id: id,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *ACLListStorageBuilder) GetKeychain() *YAMLKeychain {
|
func (t *AclListStorageBuilder) GetKeychain() *YAMLKeychain {
|
||||||
return t.keychain
|
return t.keychain
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *ACLListStorageBuilder) Parse(l *YMLList) {
|
func (t *AclListStorageBuilder) Parse(l *YMLList) {
|
||||||
// Just to clarify - we are generating new identities for the ones that
|
// Just to clarify - we are generating new identities for the ones that
|
||||||
// are specified in the yml file, because our identities should be Ed25519
|
// are specified in the yml file, because our identities should be Ed25519
|
||||||
// the same thing is happening for the encryption keys
|
// the same thing is happening for the encryption keys
|
||||||
t.keychain.ParseKeys(&l.Keys)
|
t.keychain.ParseKeys(&l.Keys)
|
||||||
rawRoot := t.parseRoot(l.Root)
|
rawRoot := t.parseRoot(l.Root)
|
||||||
var err error
|
var err error
|
||||||
t.ListStorage, err = liststorage.NewInMemoryACLListStorage(rawRoot.Id, []*aclrecordproto.RawACLRecordWithId{rawRoot})
|
t.ListStorage, err = liststorage.NewInMemoryAclListStorage(rawRoot.Id, []*aclrecordproto.RawAclRecordWithId{rawRoot})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@ -109,19 +109,19 @@ func (t *ACLListStorageBuilder) Parse(l *YMLList) {
|
|||||||
t.SetHead(prevId)
|
t.SetHead(prevId)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *ACLListStorageBuilder) parseRecord(rec *Record, prevId string) *aclrecordproto.ACLRecord {
|
func (t *AclListStorageBuilder) parseRecord(rec *Record, prevId string) *aclrecordproto.AclRecord {
|
||||||
k := t.keychain.GetKey(rec.ReadKey).(*SymKey)
|
k := t.keychain.GetKey(rec.ReadKey).(*SymKey)
|
||||||
var aclChangeContents []*aclrecordproto.ACLContentValue
|
var aclChangeContents []*aclrecordproto.AclContentValue
|
||||||
for _, ch := range rec.AclChanges {
|
for _, ch := range rec.AclChanges {
|
||||||
aclChangeContent := t.parseACLChange(ch)
|
aclChangeContent := t.parseAclChange(ch)
|
||||||
aclChangeContents = append(aclChangeContents, aclChangeContent)
|
aclChangeContents = append(aclChangeContents, aclChangeContent)
|
||||||
}
|
}
|
||||||
data := &aclrecordproto.ACLData{
|
data := &aclrecordproto.AclData{
|
||||||
AclContent: aclChangeContents,
|
AclContent: aclChangeContents,
|
||||||
}
|
}
|
||||||
bytes, _ := data.Marshal()
|
bytes, _ := data.Marshal()
|
||||||
|
|
||||||
return &aclrecordproto.ACLRecord{
|
return &aclrecordproto.AclRecord{
|
||||||
PrevId: prevId,
|
PrevId: prevId,
|
||||||
Identity: []byte(t.keychain.GetIdentity(rec.Identity)),
|
Identity: []byte(t.keychain.GetIdentity(rec.Identity)),
|
||||||
Data: bytes,
|
Data: bytes,
|
||||||
@ -130,7 +130,7 @@ func (t *ACLListStorageBuilder) parseRecord(rec *Record, prevId string) *aclreco
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *ACLListStorageBuilder) parseACLChange(ch *ACLChange) (convCh *aclrecordproto.ACLContentValue) {
|
func (t *AclListStorageBuilder) parseAclChange(ch *AclChange) (convCh *aclrecordproto.AclContentValue) {
|
||||||
switch {
|
switch {
|
||||||
case ch.UserAdd != nil:
|
case ch.UserAdd != nil:
|
||||||
add := ch.UserAdd
|
add := ch.UserAdd
|
||||||
@ -138,9 +138,9 @@ func (t *ACLListStorageBuilder) parseACLChange(ch *ACLChange) (convCh *aclrecord
|
|||||||
encKey := t.keychain.GetKey(add.EncryptionKey).(encryptionkey.PrivKey)
|
encKey := t.keychain.GetKey(add.EncryptionKey).(encryptionkey.PrivKey)
|
||||||
rawKey, _ := encKey.GetPublic().Raw()
|
rawKey, _ := encKey.GetPublic().Raw()
|
||||||
|
|
||||||
convCh = &aclrecordproto.ACLContentValue{
|
convCh = &aclrecordproto.AclContentValue{
|
||||||
Value: &aclrecordproto.ACLContentValue_UserAdd{
|
Value: &aclrecordproto.AclContentValue_UserAdd{
|
||||||
UserAdd: &aclrecordproto.ACLUserAdd{
|
UserAdd: &aclrecordproto.AclUserAdd{
|
||||||
Identity: []byte(t.keychain.GetIdentity(add.Identity)),
|
Identity: []byte(t.keychain.GetIdentity(add.Identity)),
|
||||||
EncryptionKey: rawKey,
|
EncryptionKey: rawKey,
|
||||||
EncryptedReadKeys: t.encryptReadKeysWithPubKey(add.EncryptedReadKeys, encKey),
|
EncryptedReadKeys: t.encryptReadKeysWithPubKey(add.EncryptedReadKeys, encKey),
|
||||||
@ -162,9 +162,9 @@ func (t *ACLListStorageBuilder) parseACLChange(ch *ACLChange) (convCh *aclrecord
|
|||||||
}
|
}
|
||||||
acceptPubKey, _ := signKey.GetPublic().Raw()
|
acceptPubKey, _ := signKey.GetPublic().Raw()
|
||||||
|
|
||||||
convCh = &aclrecordproto.ACLContentValue{
|
convCh = &aclrecordproto.AclContentValue{
|
||||||
Value: &aclrecordproto.ACLContentValue_UserJoin{
|
Value: &aclrecordproto.AclContentValue_UserJoin{
|
||||||
UserJoin: &aclrecordproto.ACLUserJoin{
|
UserJoin: &aclrecordproto.AclUserJoin{
|
||||||
Identity: []byte(t.keychain.GetIdentity(join.Identity)),
|
Identity: []byte(t.keychain.GetIdentity(join.Identity)),
|
||||||
EncryptionKey: rawKey,
|
EncryptionKey: rawKey,
|
||||||
AcceptSignature: signature,
|
AcceptSignature: signature,
|
||||||
@ -179,9 +179,9 @@ func (t *ACLListStorageBuilder) parseACLChange(ch *ACLChange) (convCh *aclrecord
|
|||||||
hash := t.keychain.GetKey(invite.EncryptionKey).(*SymKey).Hash
|
hash := t.keychain.GetKey(invite.EncryptionKey).(*SymKey).Hash
|
||||||
encKey := t.keychain.ReadKeysByHash[hash]
|
encKey := t.keychain.ReadKeysByHash[hash]
|
||||||
|
|
||||||
convCh = &aclrecordproto.ACLContentValue{
|
convCh = &aclrecordproto.AclContentValue{
|
||||||
Value: &aclrecordproto.ACLContentValue_UserInvite{
|
Value: &aclrecordproto.AclContentValue_UserInvite{
|
||||||
UserInvite: &aclrecordproto.ACLUserInvite{
|
UserInvite: &aclrecordproto.AclUserInvite{
|
||||||
AcceptPublicKey: rawAcceptKey,
|
AcceptPublicKey: rawAcceptKey,
|
||||||
EncryptSymKeyHash: hash,
|
EncryptSymKeyHash: hash,
|
||||||
EncryptedReadKeys: t.encryptReadKeysWithSymKey(invite.EncryptedReadKeys, encKey.Key),
|
EncryptedReadKeys: t.encryptReadKeysWithSymKey(invite.EncryptedReadKeys, encKey.Key),
|
||||||
@ -192,9 +192,9 @@ func (t *ACLListStorageBuilder) parseACLChange(ch *ACLChange) (convCh *aclrecord
|
|||||||
case ch.UserPermissionChange != nil:
|
case ch.UserPermissionChange != nil:
|
||||||
permissionChange := ch.UserPermissionChange
|
permissionChange := ch.UserPermissionChange
|
||||||
|
|
||||||
convCh = &aclrecordproto.ACLContentValue{
|
convCh = &aclrecordproto.AclContentValue{
|
||||||
Value: &aclrecordproto.ACLContentValue_UserPermissionChange{
|
Value: &aclrecordproto.AclContentValue_UserPermissionChange{
|
||||||
UserPermissionChange: &aclrecordproto.ACLUserPermissionChange{
|
UserPermissionChange: &aclrecordproto.AclUserPermissionChange{
|
||||||
Identity: []byte(t.keychain.GetIdentity(permissionChange.Identity)),
|
Identity: []byte(t.keychain.GetIdentity(permissionChange.Identity)),
|
||||||
Permissions: t.convertPermission(permissionChange.Permission),
|
Permissions: t.convertPermission(permissionChange.Permission),
|
||||||
},
|
},
|
||||||
@ -205,7 +205,7 @@ func (t *ACLListStorageBuilder) parseACLChange(ch *ACLChange) (convCh *aclrecord
|
|||||||
|
|
||||||
newReadKey := t.keychain.GetKey(remove.NewReadKey).(*SymKey)
|
newReadKey := t.keychain.GetKey(remove.NewReadKey).(*SymKey)
|
||||||
|
|
||||||
var replaces []*aclrecordproto.ACLReadKeyReplace
|
var replaces []*aclrecordproto.AclReadKeyReplace
|
||||||
for _, id := range remove.IdentitiesLeft {
|
for _, id := range remove.IdentitiesLeft {
|
||||||
encKey := t.keychain.EncryptionKeysByYAMLName[id]
|
encKey := t.keychain.EncryptionKeysByYAMLName[id]
|
||||||
rawEncKey, _ := encKey.GetPublic().Raw()
|
rawEncKey, _ := encKey.GetPublic().Raw()
|
||||||
@ -213,16 +213,16 @@ func (t *ACLListStorageBuilder) parseACLChange(ch *ACLChange) (convCh *aclrecord
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
replaces = append(replaces, &aclrecordproto.ACLReadKeyReplace{
|
replaces = append(replaces, &aclrecordproto.AclReadKeyReplace{
|
||||||
Identity: []byte(t.keychain.GetIdentity(id)),
|
Identity: []byte(t.keychain.GetIdentity(id)),
|
||||||
EncryptionKey: rawEncKey,
|
EncryptionKey: rawEncKey,
|
||||||
EncryptedReadKey: encReadKey,
|
EncryptedReadKey: encReadKey,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
convCh = &aclrecordproto.ACLContentValue{
|
convCh = &aclrecordproto.AclContentValue{
|
||||||
Value: &aclrecordproto.ACLContentValue_UserRemove{
|
Value: &aclrecordproto.AclContentValue_UserRemove{
|
||||||
UserRemove: &aclrecordproto.ACLUserRemove{
|
UserRemove: &aclrecordproto.AclUserRemove{
|
||||||
Identity: []byte(t.keychain.GetIdentity(remove.RemovedIdentity)),
|
Identity: []byte(t.keychain.GetIdentity(remove.RemovedIdentity)),
|
||||||
ReadKeyReplaces: replaces,
|
ReadKeyReplaces: replaces,
|
||||||
},
|
},
|
||||||
@ -236,7 +236,7 @@ func (t *ACLListStorageBuilder) parseACLChange(ch *ACLChange) (convCh *aclrecord
|
|||||||
return convCh
|
return convCh
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *ACLListStorageBuilder) encryptReadKeysWithPubKey(keys []string, encKey encryptionkey.PrivKey) (enc [][]byte) {
|
func (t *AclListStorageBuilder) encryptReadKeysWithPubKey(keys []string, encKey encryptionkey.PrivKey) (enc [][]byte) {
|
||||||
for _, k := range keys {
|
for _, k := range keys {
|
||||||
realKey := t.keychain.GetKey(k).(*SymKey).Key.Bytes()
|
realKey := t.keychain.GetKey(k).(*SymKey).Key.Bytes()
|
||||||
res, err := encKey.GetPublic().Encrypt(realKey)
|
res, err := encKey.GetPublic().Encrypt(realKey)
|
||||||
@ -249,7 +249,7 @@ func (t *ACLListStorageBuilder) encryptReadKeysWithPubKey(keys []string, encKey
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *ACLListStorageBuilder) encryptReadKeysWithSymKey(keys []string, key *symmetric.Key) (enc [][]byte) {
|
func (t *AclListStorageBuilder) encryptReadKeysWithSymKey(keys []string, key *symmetric.Key) (enc [][]byte) {
|
||||||
for _, k := range keys {
|
for _, k := range keys {
|
||||||
realKey := t.keychain.GetKey(k).(*SymKey).Key.Bytes()
|
realKey := t.keychain.GetKey(k).(*SymKey).Key.Bytes()
|
||||||
res, err := key.Encrypt(realKey)
|
res, err := key.Encrypt(realKey)
|
||||||
@ -262,28 +262,28 @@ func (t *ACLListStorageBuilder) encryptReadKeysWithSymKey(keys []string, key *sy
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *ACLListStorageBuilder) convertPermission(perm string) aclrecordproto.ACLUserPermissions {
|
func (t *AclListStorageBuilder) convertPermission(perm string) aclrecordproto.AclUserPermissions {
|
||||||
switch perm {
|
switch perm {
|
||||||
case "admin":
|
case "admin":
|
||||||
return aclrecordproto.ACLUserPermissions_Admin
|
return aclrecordproto.AclUserPermissions_Admin
|
||||||
case "writer":
|
case "writer":
|
||||||
return aclrecordproto.ACLUserPermissions_Writer
|
return aclrecordproto.AclUserPermissions_Writer
|
||||||
case "reader":
|
case "reader":
|
||||||
return aclrecordproto.ACLUserPermissions_Reader
|
return aclrecordproto.AclUserPermissions_Reader
|
||||||
default:
|
default:
|
||||||
panic(fmt.Sprintf("incorrect permission: %s", perm))
|
panic(fmt.Sprintf("incorrect permission: %s", perm))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *ACLListStorageBuilder) traverseFromHead(f func(rec *aclrecordproto.ACLRecord, id string) error) (err error) {
|
func (t *AclListStorageBuilder) traverseFromHead(f func(rec *aclrecordproto.AclRecord, id string) error) (err error) {
|
||||||
panic("this was removed, add if needed")
|
panic("this was removed, add if needed")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *ACLListStorageBuilder) parseRoot(root *Root) (rawRoot *aclrecordproto.RawACLRecordWithId) {
|
func (t *AclListStorageBuilder) parseRoot(root *Root) (rawRoot *aclrecordproto.RawAclRecordWithId) {
|
||||||
rawSignKey, _ := t.keychain.SigningKeysByYAMLName[root.Identity].GetPublic().Raw()
|
rawSignKey, _ := t.keychain.SigningKeysByYAMLName[root.Identity].GetPublic().Raw()
|
||||||
rawEncKey, _ := t.keychain.EncryptionKeysByYAMLName[root.Identity].GetPublic().Raw()
|
rawEncKey, _ := t.keychain.EncryptionKeysByYAMLName[root.Identity].GetPublic().Raw()
|
||||||
readKey := t.keychain.ReadKeysByYAMLName[root.Identity]
|
readKey := t.keychain.ReadKeysByYAMLName[root.Identity]
|
||||||
aclRoot := &aclrecordproto.ACLRoot{
|
aclRoot := &aclrecordproto.AclRoot{
|
||||||
Identity: rawSignKey,
|
Identity: rawSignKey,
|
||||||
EncryptionKey: rawEncKey,
|
EncryptionKey: rawEncKey,
|
||||||
SpaceId: root.SpaceId,
|
SpaceId: root.SpaceId,
|
||||||
|
|||||||
@ -6,6 +6,6 @@ package acllistbuilder
|
|||||||
|
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
func (t *ACLListStorageBuilder) Graph() (string, error) {
|
func (t *AclListStorageBuilder) Graph() (string, error) {
|
||||||
return "", fmt.Errorf("building graphs is not supported")
|
return "", fmt.Errorf("building graphs is not supported")
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,18 +25,18 @@ type EdgeParameters struct {
|
|||||||
label string
|
label string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *ACLListStorageBuilder) Graph() (string, error) {
|
func (t *AclListStorageBuilder) Graph() (string, error) {
|
||||||
// TODO: check updates on https://github.com/goccy/go-graphviz/issues/52 or make a fix yourself to use better library here
|
// TODO: check updates on https://github.com/goccy/go-graphviz/issues/52 or make a fix yourself to use better library here
|
||||||
graph := gographviz.NewGraph()
|
graph := gographviz.NewGraph()
|
||||||
graph.SetName("G")
|
graph.SetName("G")
|
||||||
graph.SetDir(true)
|
graph.SetDir(true)
|
||||||
var nodes = make(map[string]struct{})
|
var nodes = make(map[string]struct{})
|
||||||
|
|
||||||
var addNodes = func(r *aclrecordproto.ACLRecord, id string) error {
|
var addNodes = func(r *aclrecordproto.AclRecord, id string) error {
|
||||||
style := "solid"
|
style := "solid"
|
||||||
|
|
||||||
var chSymbs []string
|
var chSymbs []string
|
||||||
aclData := &aclrecordproto.ACLData{}
|
aclData := &aclrecordproto.AclData{}
|
||||||
err := proto.Unmarshal(r.GetData(), aclData)
|
err := proto.Unmarshal(r.GetData(), aclData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -44,7 +44,7 @@ func (t *ACLListStorageBuilder) Graph() (string, error) {
|
|||||||
|
|
||||||
for _, chc := range aclData.AclContent {
|
for _, chc := range aclData.AclContent {
|
||||||
tp := fmt.Sprintf("%T", chc.Value)
|
tp := fmt.Sprintf("%T", chc.Value)
|
||||||
tp = strings.Replace(tp, "ACLChangeACLContentValueValueOf", "", 1)
|
tp = strings.Replace(tp, "AclChangeAclContentValueValueOf", "", 1)
|
||||||
res := ""
|
res := ""
|
||||||
for _, ts := range tp {
|
for _, ts := range tp {
|
||||||
if unicode.IsUpper(ts) {
|
if unicode.IsUpper(ts) {
|
||||||
@ -91,7 +91,7 @@ func (t *ACLListStorageBuilder) Graph() (string, error) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var addLinks = func(r *aclrecordproto.ACLRecord, id string) error {
|
var addLinks = func(r *aclrecordproto.AclRecord, id string) error {
|
||||||
if r.PrevId == "" {
|
if r.PrevId == "" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,7 +12,7 @@ type Keys struct {
|
|||||||
Read []*Key `yaml:"Read"`
|
Read []*Key `yaml:"Read"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ACLChange struct {
|
type AclChange struct {
|
||||||
UserAdd *struct {
|
UserAdd *struct {
|
||||||
Identity string `yaml:"identity"`
|
Identity string `yaml:"identity"`
|
||||||
EncryptionKey string `yaml:"encryptionKey"`
|
EncryptionKey string `yaml:"encryptionKey"`
|
||||||
@ -48,7 +48,7 @@ type ACLChange struct {
|
|||||||
|
|
||||||
type Record struct {
|
type Record struct {
|
||||||
Identity string `yaml:"identity"`
|
Identity string `yaml:"identity"`
|
||||||
AclChanges []*ACLChange `yaml:"aclChanges"`
|
AclChanges []*AclChange `yaml:"aclChanges"`
|
||||||
ReadKey string `yaml:"readKey"`
|
ReadKey string `yaml:"readKey"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -7,10 +7,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type ObjectTreeValidator interface {
|
type ObjectTreeValidator interface {
|
||||||
// ValidateFullTree should always be entered while holding a read lock on ACLList
|
// ValidateFullTree should always be entered while holding a read lock on AclList
|
||||||
ValidateFullTree(tree *Tree, aclList list.ACLList) error
|
ValidateFullTree(tree *Tree, aclList list.AclList) error
|
||||||
// ValidateNewChanges should always be entered while holding a read lock on ACLList
|
// ValidateNewChanges should always be entered while holding a read lock on AclList
|
||||||
ValidateNewChanges(tree *Tree, aclList list.ACLList, newChanges []*Change) error
|
ValidateNewChanges(tree *Tree, aclList list.AclList, newChanges []*Change) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type objectTreeValidator struct{}
|
type objectTreeValidator struct{}
|
||||||
@ -19,7 +19,7 @@ func newTreeValidator() ObjectTreeValidator {
|
|||||||
return &objectTreeValidator{}
|
return &objectTreeValidator{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *objectTreeValidator) ValidateFullTree(tree *Tree, aclList list.ACLList) (err error) {
|
func (v *objectTreeValidator) ValidateFullTree(tree *Tree, aclList list.AclList) (err error) {
|
||||||
tree.Iterate(tree.RootId(), func(c *Change) (isContinue bool) {
|
tree.Iterate(tree.RootId(), func(c *Change) (isContinue bool) {
|
||||||
err = v.validateChange(tree, aclList, c)
|
err = v.validateChange(tree, aclList, c)
|
||||||
return err == nil
|
return err == nil
|
||||||
@ -27,7 +27,7 @@ func (v *objectTreeValidator) ValidateFullTree(tree *Tree, aclList list.ACLList)
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *objectTreeValidator) ValidateNewChanges(tree *Tree, aclList list.ACLList, newChanges []*Change) (err error) {
|
func (v *objectTreeValidator) ValidateNewChanges(tree *Tree, aclList list.AclList, newChanges []*Change) (err error) {
|
||||||
for _, c := range newChanges {
|
for _, c := range newChanges {
|
||||||
err = v.validateChange(tree, aclList, c)
|
err = v.validateChange(tree, aclList, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -37,10 +37,10 @@ func (v *objectTreeValidator) ValidateNewChanges(tree *Tree, aclList list.ACLLis
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *objectTreeValidator) validateChange(tree *Tree, aclList list.ACLList, c *Change) (err error) {
|
func (v *objectTreeValidator) validateChange(tree *Tree, aclList list.AclList, c *Change) (err error) {
|
||||||
var (
|
var (
|
||||||
perm list.UserPermissionPair
|
perm list.UserPermissionPair
|
||||||
state = aclList.ACLState()
|
state = aclList.AclState()
|
||||||
)
|
)
|
||||||
// checking if the user could write
|
// checking if the user could write
|
||||||
perm, err = state.PermissionsAtRecord(c.AclHeadId, c.Identity)
|
perm, err = state.PermissionsAtRecord(c.AclHeadId, c.Identity)
|
||||||
@ -48,7 +48,7 @@ func (v *objectTreeValidator) validateChange(tree *Tree, aclList list.ACLList, c
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if perm.Permission != aclrecordproto.ACLUserPermissions_Writer && perm.Permission != aclrecordproto.ACLUserPermissions_Admin {
|
if perm.Permission != aclrecordproto.AclUserPermissions_Writer && perm.Permission != aclrecordproto.AclUserPermissions_Admin {
|
||||||
err = list.ErrInsufficientPermissions
|
err = list.ErrInsufficientPermissions
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@ -74,7 +74,7 @@ type objectTree struct {
|
|||||||
validator ObjectTreeValidator
|
validator ObjectTreeValidator
|
||||||
rawChangeLoader *rawChangeLoader
|
rawChangeLoader *rawChangeLoader
|
||||||
treeBuilder *treeBuilder
|
treeBuilder *treeBuilder
|
||||||
aclList list2.ACLList
|
aclList list2.AclList
|
||||||
|
|
||||||
id string
|
id string
|
||||||
root *treechangeproto.RawTreeChangeWithId
|
root *treechangeproto.RawTreeChangeWithId
|
||||||
@ -99,13 +99,13 @@ type objectTreeDeps struct {
|
|||||||
treeStorage treestorage.TreeStorage
|
treeStorage treestorage.TreeStorage
|
||||||
validator ObjectTreeValidator
|
validator ObjectTreeValidator
|
||||||
rawChangeLoader *rawChangeLoader
|
rawChangeLoader *rawChangeLoader
|
||||||
aclList list2.ACLList
|
aclList list2.AclList
|
||||||
}
|
}
|
||||||
|
|
||||||
func defaultObjectTreeDeps(
|
func defaultObjectTreeDeps(
|
||||||
rootChange *treechangeproto.RawTreeChangeWithId,
|
rootChange *treechangeproto.RawTreeChangeWithId,
|
||||||
treeStorage treestorage.TreeStorage,
|
treeStorage treestorage.TreeStorage,
|
||||||
aclList list2.ACLList) objectTreeDeps {
|
aclList list2.AclList) objectTreeDeps {
|
||||||
|
|
||||||
keychain := keychain.NewKeychain()
|
keychain := keychain.NewKeychain()
|
||||||
changeBuilder := NewChangeBuilder(keychain, rootChange)
|
changeBuilder := NewChangeBuilder(keychain, rootChange)
|
||||||
@ -195,12 +195,12 @@ func (ot *objectTree) prepareBuilderContent(content SignableChangeContent) (cnt
|
|||||||
defer ot.aclList.RUnlock()
|
defer ot.aclList.RUnlock()
|
||||||
|
|
||||||
var (
|
var (
|
||||||
state = ot.aclList.ACLState() // special method for own keys
|
state = ot.aclList.AclState() // special method for own keys
|
||||||
readKey *symmetric.Key
|
readKey *symmetric.Key
|
||||||
readKeyHash uint64
|
readKeyHash uint64
|
||||||
)
|
)
|
||||||
canWrite := state.HasPermission(content.Identity, aclrecordproto.ACLUserPermissions_Writer) ||
|
canWrite := state.HasPermission(content.Identity, aclrecordproto.AclUserPermissions_Writer) ||
|
||||||
state.HasPermission(content.Identity, aclrecordproto.ACLUserPermissions_Admin)
|
state.HasPermission(content.Identity, aclrecordproto.AclUserPermissions_Admin)
|
||||||
if !canWrite {
|
if !canWrite {
|
||||||
err = list2.ErrInsufficientPermissions
|
err = list2.ErrInsufficientPermissions
|
||||||
return
|
return
|
||||||
@ -606,7 +606,7 @@ func (ot *objectTree) snapshotPathIsActual() bool {
|
|||||||
func (ot *objectTree) validateTree(newChanges []*Change) error {
|
func (ot *objectTree) validateTree(newChanges []*Change) error {
|
||||||
ot.aclList.RLock()
|
ot.aclList.RLock()
|
||||||
defer ot.aclList.RUnlock()
|
defer ot.aclList.RUnlock()
|
||||||
state := ot.aclList.ACLState()
|
state := ot.aclList.AclState()
|
||||||
|
|
||||||
// just not to take lock many times, updating the key map from aclList
|
// just not to take lock many times, updating the key map from aclList
|
||||||
if len(ot.keys) != len(state.UserReadKeys()) {
|
if len(ot.keys) != len(state.UserReadKeys()) {
|
||||||
|
|||||||
@ -85,33 +85,33 @@ func (c *mockChangeBuilder) BuildRaw(ch *Change) (raw *treechangeproto.RawTreeCh
|
|||||||
|
|
||||||
type mockChangeValidator struct{}
|
type mockChangeValidator struct{}
|
||||||
|
|
||||||
func (m *mockChangeValidator) ValidateNewChanges(tree *Tree, aclList list.ACLList, newChanges []*Change) error {
|
func (m *mockChangeValidator) ValidateNewChanges(tree *Tree, aclList list.AclList, newChanges []*Change) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockChangeValidator) ValidateFullTree(tree *Tree, aclList list.ACLList) error {
|
func (m *mockChangeValidator) ValidateFullTree(tree *Tree, aclList list.AclList) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type testTreeContext struct {
|
type testTreeContext struct {
|
||||||
aclList list.ACLList
|
aclList list.AclList
|
||||||
treeStorage treestorage.TreeStorage
|
treeStorage treestorage.TreeStorage
|
||||||
changeBuilder *mockChangeBuilder
|
changeBuilder *mockChangeBuilder
|
||||||
changeCreator *mockChangeCreator
|
changeCreator *mockChangeCreator
|
||||||
objTree ObjectTree
|
objTree ObjectTree
|
||||||
}
|
}
|
||||||
|
|
||||||
func prepareACLList(t *testing.T) list.ACLList {
|
func prepareAclList(t *testing.T) list.AclList {
|
||||||
st, err := acllistbuilder.NewListStorageWithTestName("userjoinexample.yml")
|
st, err := acllistbuilder.NewListStorageWithTestName("userjoinexample.yml")
|
||||||
require.NoError(t, err, "building storage should not result in error")
|
require.NoError(t, err, "building storage should not result in error")
|
||||||
|
|
||||||
aclList, err := list.BuildACLList(st)
|
aclList, err := list.BuildAclList(st)
|
||||||
require.NoError(t, err, "building acl list should be without error")
|
require.NoError(t, err, "building acl list should be without error")
|
||||||
|
|
||||||
return aclList
|
return aclList
|
||||||
}
|
}
|
||||||
|
|
||||||
func prepareTreeContext(t *testing.T, aclList list.ACLList) testTreeContext {
|
func prepareTreeContext(t *testing.T, aclList list.AclList) testTreeContext {
|
||||||
changeCreator := &mockChangeCreator{}
|
changeCreator := &mockChangeCreator{}
|
||||||
treeStorage := changeCreator.createNewTreeStorage("0", aclList.Head().Id)
|
treeStorage := changeCreator.createNewTreeStorage("0", aclList.Head().Id)
|
||||||
root, _ := treeStorage.Root()
|
root, _ := treeStorage.Root()
|
||||||
@ -149,7 +149,7 @@ func prepareTreeContext(t *testing.T, aclList list.ACLList) testTreeContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestObjectTree(t *testing.T) {
|
func TestObjectTree(t *testing.T) {
|
||||||
aclList := prepareACLList(t)
|
aclList := prepareAclList(t)
|
||||||
|
|
||||||
t.Run("add simple", func(t *testing.T) {
|
t.Run("add simple", func(t *testing.T) {
|
||||||
ctx := prepareTreeContext(t, aclList)
|
ctx := prepareTreeContext(t, aclList)
|
||||||
|
|||||||
@ -21,7 +21,7 @@ type ObjectTreeCreatePayload struct {
|
|||||||
IsEncrypted bool
|
IsEncrypted bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func BuildObjectTree(treeStorage treestorage.TreeStorage, aclList list.ACLList) (ObjectTree, error) {
|
func BuildObjectTree(treeStorage treestorage.TreeStorage, aclList list.AclList) (ObjectTree, error) {
|
||||||
rootChange, err := treeStorage.Root()
|
rootChange, err := treeStorage.Root()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -32,14 +32,14 @@ func BuildObjectTree(treeStorage treestorage.TreeStorage, aclList list.ACLList)
|
|||||||
|
|
||||||
func CreateDerivedObjectTree(
|
func CreateDerivedObjectTree(
|
||||||
payload ObjectTreeCreatePayload,
|
payload ObjectTreeCreatePayload,
|
||||||
aclList list.ACLList,
|
aclList list.AclList,
|
||||||
createStorage treestorage.TreeStorageCreatorFunc) (objTree ObjectTree, err error) {
|
createStorage treestorage.TreeStorageCreatorFunc) (objTree ObjectTree, err error) {
|
||||||
return createObjectTree(payload, 0, nil, aclList, createStorage)
|
return createObjectTree(payload, 0, nil, aclList, createStorage)
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateObjectTree(
|
func CreateObjectTree(
|
||||||
payload ObjectTreeCreatePayload,
|
payload ObjectTreeCreatePayload,
|
||||||
aclList list.ACLList,
|
aclList list.AclList,
|
||||||
createStorage treestorage.TreeStorageCreatorFunc) (objTree ObjectTree, err error) {
|
createStorage treestorage.TreeStorageCreatorFunc) (objTree ObjectTree, err error) {
|
||||||
bytes := make([]byte, 32)
|
bytes := make([]byte, 32)
|
||||||
_, err = rand.Read(bytes)
|
_, err = rand.Read(bytes)
|
||||||
@ -53,7 +53,7 @@ func createObjectTree(
|
|||||||
payload ObjectTreeCreatePayload,
|
payload ObjectTreeCreatePayload,
|
||||||
timestamp int64,
|
timestamp int64,
|
||||||
seed []byte,
|
seed []byte,
|
||||||
aclList list.ACLList,
|
aclList list.AclList,
|
||||||
createStorage treestorage.TreeStorageCreatorFunc) (objTree ObjectTree, err error) {
|
createStorage treestorage.TreeStorageCreatorFunc) (objTree ObjectTree, err error) {
|
||||||
aclList.RLock()
|
aclList.RLock()
|
||||||
aclHeadId := aclList.Head().Id
|
aclHeadId := aclList.Head().Id
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import (
|
|||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/object/tree/treestorage"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/object/tree/treestorage"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ValidateRawTree(payload treestorage.TreeStorageCreatePayload, aclList list.ACLList) (err error) {
|
func ValidateRawTree(payload treestorage.TreeStorageCreatePayload, aclList list.AclList) (err error) {
|
||||||
provider := treestorage.NewInMemoryTreeStorageProvider()
|
provider := treestorage.NewInMemoryTreeStorageProvider()
|
||||||
treeStorage, err := provider.CreateTreeStorage(payload)
|
treeStorage, err := provider.CreateTreeStorage(payload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -61,7 +61,7 @@ type CreateDeps struct {
|
|||||||
Payload objecttree.ObjectTreeCreatePayload
|
Payload objecttree.ObjectTreeCreatePayload
|
||||||
Configuration nodeconf.Configuration
|
Configuration nodeconf.Configuration
|
||||||
ObjectSync objectsync.ObjectSync
|
ObjectSync objectsync.ObjectSync
|
||||||
AclList list.ACLList
|
AclList list.AclList
|
||||||
SpaceStorage spacestorage.SpaceStorage
|
SpaceStorage spacestorage.SpaceStorage
|
||||||
SyncStatus syncstatus.StatusUpdater
|
SyncStatus syncstatus.StatusUpdater
|
||||||
HeadNotifiable HeadNotifiable
|
HeadNotifiable HeadNotifiable
|
||||||
@ -73,7 +73,7 @@ type BuildDeps struct {
|
|||||||
Configuration nodeconf.Configuration
|
Configuration nodeconf.Configuration
|
||||||
HeadNotifiable HeadNotifiable
|
HeadNotifiable HeadNotifiable
|
||||||
Listener updatelistener.UpdateListener
|
Listener updatelistener.UpdateListener
|
||||||
AclList list.ACLList
|
AclList list.AclList
|
||||||
SpaceStorage spacestorage.SpaceStorage
|
SpaceStorage spacestorage.SpaceStorage
|
||||||
TreeStorage treestorage.TreeStorage
|
TreeStorage treestorage.TreeStorage
|
||||||
TreeUsage *atomic.Int32
|
TreeUsage *atomic.Int32
|
||||||
|
|||||||
@ -50,13 +50,13 @@ func Test_DeriveSyncTree(t *testing.T) {
|
|||||||
defer ctrl.Finish()
|
defer ctrl.Finish()
|
||||||
|
|
||||||
syncClientMock := mock_synctree.NewMockSyncClient(ctrl)
|
syncClientMock := mock_synctree.NewMockSyncClient(ctrl)
|
||||||
aclListMock := mock_list.NewMockACLList(ctrl)
|
aclListMock := mock_list.NewMockAclList(ctrl)
|
||||||
objTreeMock := newTestObjMock(mock_objecttree.NewMockObjectTree(ctrl))
|
objTreeMock := newTestObjMock(mock_objecttree.NewMockObjectTree(ctrl))
|
||||||
spaceStorageMock := mock_spacestorage.NewMockSpaceStorage(ctrl)
|
spaceStorageMock := mock_spacestorage.NewMockSpaceStorage(ctrl)
|
||||||
headNotifiableMock := mock_synctree.NewMockHeadNotifiable(ctrl)
|
headNotifiableMock := mock_synctree.NewMockHeadNotifiable(ctrl)
|
||||||
spaceId := "spaceId"
|
spaceId := "spaceId"
|
||||||
expectedPayload := objecttree.ObjectTreeCreatePayload{SpaceId: spaceId}
|
expectedPayload := objecttree.ObjectTreeCreatePayload{SpaceId: spaceId}
|
||||||
createDerivedObjectTree = func(payload objecttree.ObjectTreeCreatePayload, l list.ACLList, create treestorage.TreeStorageCreatorFunc) (objTree objecttree.ObjectTree, err error) {
|
createDerivedObjectTree = func(payload objecttree.ObjectTreeCreatePayload, l list.AclList, create treestorage.TreeStorageCreatorFunc) (objTree objecttree.ObjectTree, err error) {
|
||||||
require.Equal(t, l, aclListMock)
|
require.Equal(t, l, aclListMock)
|
||||||
require.Equal(t, expectedPayload, payload)
|
require.Equal(t, expectedPayload, payload)
|
||||||
return objTreeMock, nil
|
return objTreeMock, nil
|
||||||
@ -87,13 +87,13 @@ func Test_CreateSyncTree(t *testing.T) {
|
|||||||
defer ctrl.Finish()
|
defer ctrl.Finish()
|
||||||
|
|
||||||
syncClientMock := mock_synctree.NewMockSyncClient(ctrl)
|
syncClientMock := mock_synctree.NewMockSyncClient(ctrl)
|
||||||
aclListMock := mock_list.NewMockACLList(ctrl)
|
aclListMock := mock_list.NewMockAclList(ctrl)
|
||||||
objTreeMock := newTestObjMock(mock_objecttree.NewMockObjectTree(ctrl))
|
objTreeMock := newTestObjMock(mock_objecttree.NewMockObjectTree(ctrl))
|
||||||
spaceStorageMock := mock_spacestorage.NewMockSpaceStorage(ctrl)
|
spaceStorageMock := mock_spacestorage.NewMockSpaceStorage(ctrl)
|
||||||
headNotifiableMock := mock_synctree.NewMockHeadNotifiable(ctrl)
|
headNotifiableMock := mock_synctree.NewMockHeadNotifiable(ctrl)
|
||||||
spaceId := "spaceId"
|
spaceId := "spaceId"
|
||||||
expectedPayload := objecttree.ObjectTreeCreatePayload{SpaceId: spaceId}
|
expectedPayload := objecttree.ObjectTreeCreatePayload{SpaceId: spaceId}
|
||||||
createObjectTree = func(payload objecttree.ObjectTreeCreatePayload, l list.ACLList, create treestorage.TreeStorageCreatorFunc) (objTree objecttree.ObjectTree, err error) {
|
createObjectTree = func(payload objecttree.ObjectTreeCreatePayload, l list.AclList, create treestorage.TreeStorageCreatorFunc) (objTree objecttree.ObjectTree, err error) {
|
||||||
require.Equal(t, l, aclListMock)
|
require.Equal(t, l, aclListMock)
|
||||||
require.Equal(t, expectedPayload, payload)
|
require.Equal(t, expectedPayload, payload)
|
||||||
return objTreeMock, nil
|
return objTreeMock, nil
|
||||||
|
|||||||
@ -37,7 +37,7 @@ func (m *MockListStorage) EXPECT() *MockListStorageMockRecorder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddRawRecord mocks base method.
|
// AddRawRecord mocks base method.
|
||||||
func (m *MockListStorage) AddRawRecord(arg0 context.Context, arg1 *aclrecordproto.RawACLRecordWithId) error {
|
func (m *MockListStorage) AddRawRecord(arg0 context.Context, arg1 *aclrecordproto.RawAclRecordWithId) error {
|
||||||
m.ctrl.T.Helper()
|
m.ctrl.T.Helper()
|
||||||
ret := m.ctrl.Call(m, "AddRawRecord", arg0, arg1)
|
ret := m.ctrl.Call(m, "AddRawRecord", arg0, arg1)
|
||||||
ret0, _ := ret[0].(error)
|
ret0, _ := ret[0].(error)
|
||||||
@ -51,10 +51,10 @@ func (mr *MockListStorageMockRecorder) AddRawRecord(arg0, arg1 interface{}) *gom
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetRawRecord mocks base method.
|
// GetRawRecord mocks base method.
|
||||||
func (m *MockListStorage) GetRawRecord(arg0 context.Context, arg1 string) (*aclrecordproto.RawACLRecordWithId, error) {
|
func (m *MockListStorage) GetRawRecord(arg0 context.Context, arg1 string) (*aclrecordproto.RawAclRecordWithId, error) {
|
||||||
m.ctrl.T.Helper()
|
m.ctrl.T.Helper()
|
||||||
ret := m.ctrl.Call(m, "GetRawRecord", arg0, arg1)
|
ret := m.ctrl.Call(m, "GetRawRecord", arg0, arg1)
|
||||||
ret0, _ := ret[0].(*aclrecordproto.RawACLRecordWithId)
|
ret0, _ := ret[0].(*aclrecordproto.RawAclRecordWithId)
|
||||||
ret1, _ := ret[1].(error)
|
ret1, _ := ret[1].(error)
|
||||||
return ret0, ret1
|
return ret0, ret1
|
||||||
}
|
}
|
||||||
@ -95,10 +95,10 @@ func (mr *MockListStorageMockRecorder) Id() *gomock.Call {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Root mocks base method.
|
// Root mocks base method.
|
||||||
func (m *MockListStorage) Root() (*aclrecordproto.RawACLRecordWithId, error) {
|
func (m *MockListStorage) Root() (*aclrecordproto.RawAclRecordWithId, error) {
|
||||||
m.ctrl.T.Helper()
|
m.ctrl.T.Helper()
|
||||||
ret := m.ctrl.Call(m, "Root")
|
ret := m.ctrl.Call(m, "Root")
|
||||||
ret0, _ := ret[0].(*aclrecordproto.RawACLRecordWithId)
|
ret0, _ := ret[0].(*aclrecordproto.RawAclRecordWithId)
|
||||||
ret1, _ := ret[1].(error)
|
ret1, _ := ret[1].(error)
|
||||||
return ret0, ret1
|
return ret0, ret1
|
||||||
}
|
}
|
||||||
|
|||||||
@ -75,7 +75,7 @@ func storagePayloadForSpaceCreate(payload SpaceCreatePayload) (storagePayload sp
|
|||||||
}
|
}
|
||||||
|
|
||||||
// preparing acl
|
// preparing acl
|
||||||
aclRoot := &aclrecordproto2.ACLRoot{
|
aclRoot := &aclrecordproto2.AclRoot{
|
||||||
Identity: identity,
|
Identity: identity,
|
||||||
EncryptionKey: encPubKey,
|
EncryptionKey: encPubKey,
|
||||||
SpaceId: spaceId,
|
SpaceId: spaceId,
|
||||||
@ -83,7 +83,7 @@ func storagePayloadForSpaceCreate(payload SpaceCreatePayload) (storagePayload sp
|
|||||||
CurrentReadKeyHash: readKeyHash,
|
CurrentReadKeyHash: readKeyHash,
|
||||||
Timestamp: time.Now().UnixNano(),
|
Timestamp: time.Now().UnixNano(),
|
||||||
}
|
}
|
||||||
rawWithId, err := marshalACLRoot(aclRoot, payload.SigningKey)
|
rawWithId, err := marshalAclRoot(aclRoot, payload.SigningKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -171,7 +171,7 @@ func storagePayloadForSpaceDerive(payload SpaceDerivePayload) (storagePayload sp
|
|||||||
}
|
}
|
||||||
|
|
||||||
// deriving and encrypting read key
|
// deriving and encrypting read key
|
||||||
readKey, err := aclrecordproto2.ACLReadKeyDerive(signPrivKey, encPrivKey)
|
readKey, err := aclrecordproto2.AclReadKeyDerive(signPrivKey, encPrivKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -187,7 +187,7 @@ func storagePayloadForSpaceDerive(payload SpaceDerivePayload) (storagePayload sp
|
|||||||
}
|
}
|
||||||
|
|
||||||
// preparing acl
|
// preparing acl
|
||||||
aclRoot := &aclrecordproto2.ACLRoot{
|
aclRoot := &aclrecordproto2.AclRoot{
|
||||||
Identity: identity,
|
Identity: identity,
|
||||||
EncryptionKey: encPubKey,
|
EncryptionKey: encPubKey,
|
||||||
SpaceId: spaceId,
|
SpaceId: spaceId,
|
||||||
@ -195,7 +195,7 @@ func storagePayloadForSpaceDerive(payload SpaceDerivePayload) (storagePayload sp
|
|||||||
DerivationScheme: SpaceDerivationScheme,
|
DerivationScheme: SpaceDerivationScheme,
|
||||||
CurrentReadKeyHash: readKeyHash,
|
CurrentReadKeyHash: readKeyHash,
|
||||||
}
|
}
|
||||||
rawWithId, err := marshalACLRoot(aclRoot, payload.SigningKey)
|
rawWithId, err := marshalAclRoot(aclRoot, payload.SigningKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -221,7 +221,7 @@ func storagePayloadForSpaceDerive(payload SpaceDerivePayload) (storagePayload sp
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func marshalACLRoot(aclRoot *aclrecordproto2.ACLRoot, key signingkey.PrivKey) (rawWithId *aclrecordproto2.RawACLRecordWithId, err error) {
|
func marshalAclRoot(aclRoot *aclrecordproto2.AclRoot, key signingkey.PrivKey) (rawWithId *aclrecordproto2.RawAclRecordWithId, err error) {
|
||||||
marshalledRoot, err := aclRoot.Marshal()
|
marshalledRoot, err := aclRoot.Marshal()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@ -230,7 +230,7 @@ func marshalACLRoot(aclRoot *aclrecordproto2.ACLRoot, key signingkey.PrivKey) (r
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
raw := &aclrecordproto2.RawACLRecord{
|
raw := &aclrecordproto2.RawAclRecord{
|
||||||
Payload: marshalledRoot,
|
Payload: marshalledRoot,
|
||||||
Signature: signature,
|
Signature: signature,
|
||||||
}
|
}
|
||||||
@ -242,7 +242,7 @@ func marshalACLRoot(aclRoot *aclrecordproto2.ACLRoot, key signingkey.PrivKey) (r
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
rawWithId = &aclrecordproto2.RawACLRecordWithId{
|
rawWithId = &aclrecordproto2.RawAclRecordWithId{
|
||||||
Payload: marshalledRaw,
|
Payload: marshalledRaw,
|
||||||
Id: aclHeadId,
|
Id: aclHeadId,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -99,7 +99,7 @@ type space struct {
|
|||||||
storage spacestorage.SpaceStorage
|
storage spacestorage.SpaceStorage
|
||||||
cache treegetter.TreeGetter
|
cache treegetter.TreeGetter
|
||||||
account accountservice.Service
|
account accountservice.Service
|
||||||
aclList *syncacl.SyncACL
|
aclList *syncacl.SyncAcl
|
||||||
configuration nodeconf.Configuration
|
configuration nodeconf.Configuration
|
||||||
settingsObject settings.SettingsObject
|
settingsObject settings.SettingsObject
|
||||||
|
|
||||||
@ -156,15 +156,15 @@ func (s *space) Init(ctx context.Context) (err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
aclStorage, err := s.storage.ACLStorage()
|
aclStorage, err := s.storage.AclStorage()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
aclList, err := list.BuildACLListWithIdentity(s.account.Account(), aclStorage)
|
aclList, err := list.BuildAclListWithIdentity(s.account.Account(), aclStorage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
s.aclList = syncacl.NewSyncACL(aclList, s.objectSync.StreamPool())
|
s.aclList = syncacl.NewSyncAcl(aclList, s.objectSync.StreamPool())
|
||||||
|
|
||||||
deletionState := deletionstate.NewDeletionState(s.storage)
|
deletionState := deletionstate.NewDeletionState(s.storage)
|
||||||
deps := settings.Deps{
|
deps := settings.Deps{
|
||||||
|
|||||||
@ -134,7 +134,7 @@ func (s *spaceService) NewSpace(ctx context.Context, id string) (Space, error) {
|
|||||||
|
|
||||||
func (s *spaceService) addSpaceStorage(ctx context.Context, spaceDescription SpaceDescription) (st spacestorage.SpaceStorage, err error) {
|
func (s *spaceService) addSpaceStorage(ctx context.Context, spaceDescription SpaceDescription) (st spacestorage.SpaceStorage, err error) {
|
||||||
payload := spacestorage.SpaceStorageCreatePayload{
|
payload := spacestorage.SpaceStorageCreatePayload{
|
||||||
AclWithId: &aclrecordproto.RawACLRecordWithId{
|
AclWithId: &aclrecordproto.RawAclRecordWithId{
|
||||||
Payload: spaceDescription.AclPayload,
|
Payload: spaceDescription.AclPayload,
|
||||||
Id: spaceDescription.AclId,
|
Id: spaceDescription.AclId,
|
||||||
},
|
},
|
||||||
@ -176,7 +176,7 @@ func (s *spaceService) getSpaceStorageFromRemote(ctx context.Context, id string)
|
|||||||
}
|
}
|
||||||
|
|
||||||
st, err = s.storageProvider.CreateSpaceStorage(spacestorage.SpaceStorageCreatePayload{
|
st, err = s.storageProvider.CreateSpaceStorage(spacestorage.SpaceStorageCreatePayload{
|
||||||
AclWithId: &aclrecordproto.RawACLRecordWithId{
|
AclWithId: &aclrecordproto.RawAclRecordWithId{
|
||||||
Payload: res.Payload.AclPayload,
|
Payload: res.Payload.AclPayload,
|
||||||
Id: res.Payload.AclPayloadId,
|
Id: res.Payload.AclPayloadId,
|
||||||
},
|
},
|
||||||
|
|||||||
@ -119,19 +119,19 @@ func (m *MockSpaceStorage) EXPECT() *MockSpaceStorageMockRecorder {
|
|||||||
return m.recorder
|
return m.recorder
|
||||||
}
|
}
|
||||||
|
|
||||||
// ACLStorage mocks base method.
|
// AclStorage mocks base method.
|
||||||
func (m *MockSpaceStorage) ACLStorage() (liststorage.ListStorage, error) {
|
func (m *MockSpaceStorage) AclStorage() (liststorage.ListStorage, error) {
|
||||||
m.ctrl.T.Helper()
|
m.ctrl.T.Helper()
|
||||||
ret := m.ctrl.Call(m, "ACLStorage")
|
ret := m.ctrl.Call(m, "AclStorage")
|
||||||
ret0, _ := ret[0].(liststorage.ListStorage)
|
ret0, _ := ret[0].(liststorage.ListStorage)
|
||||||
ret1, _ := ret[1].(error)
|
ret1, _ := ret[1].(error)
|
||||||
return ret0, ret1
|
return ret0, ret1
|
||||||
}
|
}
|
||||||
|
|
||||||
// ACLStorage indicates an expected call of ACLStorage.
|
// AclStorage indicates an expected call of AclStorage.
|
||||||
func (mr *MockSpaceStorageMockRecorder) ACLStorage() *gomock.Call {
|
func (mr *MockSpaceStorageMockRecorder) AclStorage() *gomock.Call {
|
||||||
mr.mock.ctrl.T.Helper()
|
mr.mock.ctrl.T.Helper()
|
||||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ACLStorage", reflect.TypeOf((*MockSpaceStorage)(nil).ACLStorage))
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AclStorage", reflect.TypeOf((*MockSpaceStorage)(nil).AclStorage))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close mocks base method.
|
// Close mocks base method.
|
||||||
|
|||||||
@ -32,14 +32,14 @@ type SpaceStorage interface {
|
|||||||
SetTreeDeletedStatus(id, state string) error
|
SetTreeDeletedStatus(id, state string) error
|
||||||
TreeDeletedStatus(id string) (string, error)
|
TreeDeletedStatus(id string) (string, error)
|
||||||
SpaceSettingsId() string
|
SpaceSettingsId() string
|
||||||
ACLStorage() (liststorage.ListStorage, error)
|
AclStorage() (liststorage.ListStorage, error)
|
||||||
SpaceHeader() (*spacesyncproto.RawSpaceHeaderWithId, error)
|
SpaceHeader() (*spacesyncproto.RawSpaceHeaderWithId, error)
|
||||||
StoredIds() ([]string, error)
|
StoredIds() ([]string, error)
|
||||||
Close() error
|
Close() error
|
||||||
}
|
}
|
||||||
|
|
||||||
type SpaceStorageCreatePayload struct {
|
type SpaceStorageCreatePayload struct {
|
||||||
AclWithId *aclrecordproto.RawACLRecordWithId
|
AclWithId *aclrecordproto.RawAclRecordWithId
|
||||||
SpaceHeaderWithId *spacesyncproto.RawSpaceHeaderWithId
|
SpaceHeaderWithId *spacesyncproto.RawSpaceHeaderWithId
|
||||||
SpaceSettingsWithId *treechangeproto.RawTreeChangeWithId
|
SpaceSettingsWithId *treechangeproto.RawTreeChangeWithId
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,8 +22,8 @@ func New() Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Service interface {
|
type Service interface {
|
||||||
CreateLog(ctx context.Context, aclId string, rawRec *aclrecordproto.RawACLRecord) (firstRecId string, err error)
|
CreateLog(ctx context.Context, aclId string, rawRec *aclrecordproto.RawAclRecord) (firstRecId string, err error)
|
||||||
AddRecord(ctx context.Context, aclId string, rawRec *aclrecordproto.RawACLRecord) (id string, err error)
|
AddRecord(ctx context.Context, aclId string, rawRec *aclrecordproto.RawAclRecord) (id string, err error)
|
||||||
Watch(ctx context.Context, spaceId, aclId string, h synchandler.SyncHandler) (err error)
|
Watch(ctx context.Context, spaceId, aclId string, h synchandler.SyncHandler) (err error)
|
||||||
UnWatch(aclId string) (err error)
|
UnWatch(aclId string) (err error)
|
||||||
app.Component
|
app.Component
|
||||||
@ -44,7 +44,7 @@ func (s *service) Name() (name string) {
|
|||||||
return CName
|
return CName
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) CreateLog(ctx context.Context, aclId string, rawRec *aclrecordproto.RawACLRecord) (firstRecId string, err error) {
|
func (s *service) CreateLog(ctx context.Context, aclId string, rawRec *aclrecordproto.RawAclRecord) (firstRecId string, err error) {
|
||||||
logId, err := cidToByte(aclId)
|
logId, err := cidToByte(aclId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@ -68,7 +68,7 @@ func (s *service) CreateLog(ctx context.Context, aclId string, rawRec *aclrecord
|
|||||||
return cidToString(recId)
|
return cidToString(recId)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) AddRecord(ctx context.Context, aclId string, rawRec *aclrecordproto.RawACLRecord) (id string, err error) {
|
func (s *service) AddRecord(ctx context.Context, aclId string, rawRec *aclrecordproto.RawAclRecord) (id string, err error) {
|
||||||
logId, err := cidToByte(aclId)
|
logId, err := cidToByte(aclId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@ -108,8 +108,8 @@ func (s *service) UnWatch(aclId string) (err error) {
|
|||||||
return s.consService.UnWatch(logId)
|
return s.consService.UnWatch(logId)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) signAndMarshal(rawRec *aclrecordproto.RawACLRecord) (recId, prevId, payload []byte, err error) {
|
func (s *service) signAndMarshal(rawRec *aclrecordproto.RawAclRecord) (recId, prevId, payload []byte, err error) {
|
||||||
var rec = &aclrecordproto.ACLRecord{}
|
var rec = &aclrecordproto.AclRecord{}
|
||||||
if err = rec.Unmarshal(rawRec.Payload); err != nil {
|
if err = rec.Unmarshal(rawRec.Payload); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,7 +30,7 @@ func TestService_CreateLog(t *testing.T) {
|
|||||||
|
|
||||||
aclId, _ := cidutil.NewCIDFromBytes([]byte("aclId"))
|
aclId, _ := cidutil.NewCIDFromBytes([]byte("aclId"))
|
||||||
|
|
||||||
rec := &aclrecordproto.ACLRecord{
|
rec := &aclrecordproto.AclRecord{
|
||||||
PrevId: "",
|
PrevId: "",
|
||||||
Identity: fx.account.Account().Identity,
|
Identity: fx.account.Account().Identity,
|
||||||
Data: []byte{'1', '2', '3'},
|
Data: []byte{'1', '2', '3'},
|
||||||
@ -38,7 +38,7 @@ func TestService_CreateLog(t *testing.T) {
|
|||||||
}
|
}
|
||||||
pl, _ := rec.Marshal()
|
pl, _ := rec.Marshal()
|
||||||
|
|
||||||
firstRecId, err := fx.CreateLog(ctx, aclId, &aclrecordproto.RawACLRecord{
|
firstRecId, err := fx.CreateLog(ctx, aclId, &aclrecordproto.RawAclRecord{
|
||||||
Payload: pl,
|
Payload: pl,
|
||||||
})
|
})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@ -48,7 +48,7 @@ func TestService_CreateLog(t *testing.T) {
|
|||||||
assert.NotEmpty(t, firstRecIdBytes)
|
assert.NotEmpty(t, firstRecIdBytes)
|
||||||
require.Len(t, clog.Records, 1)
|
require.Len(t, clog.Records, 1)
|
||||||
|
|
||||||
var resultRawAcl = &aclrecordproto.RawACLRecord{}
|
var resultRawAcl = &aclrecordproto.RawAclRecord{}
|
||||||
require.NoError(t, resultRawAcl.Unmarshal(clog.Records[0].Payload))
|
require.NoError(t, resultRawAcl.Unmarshal(clog.Records[0].Payload))
|
||||||
valid, err := fx.account.Account().SignKey.GetPublic().Verify(resultRawAcl.Payload, resultRawAcl.AcceptorSignature)
|
valid, err := fx.account.Account().SignKey.GetPublic().Verify(resultRawAcl.Payload, resultRawAcl.AcceptorSignature)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@ -65,7 +65,7 @@ func TestService_AddRecord(t *testing.T) {
|
|||||||
|
|
||||||
aclId, _ := cidutil.NewCIDFromBytes([]byte("aclId"))
|
aclId, _ := cidutil.NewCIDFromBytes([]byte("aclId"))
|
||||||
|
|
||||||
rec := &aclrecordproto.ACLRecord{
|
rec := &aclrecordproto.AclRecord{
|
||||||
PrevId: "",
|
PrevId: "",
|
||||||
Identity: fx.account.Account().Identity,
|
Identity: fx.account.Account().Identity,
|
||||||
Data: []byte{'1', '2', '3'},
|
Data: []byte{'1', '2', '3'},
|
||||||
@ -73,7 +73,7 @@ func TestService_AddRecord(t *testing.T) {
|
|||||||
}
|
}
|
||||||
pl, _ := rec.Marshal()
|
pl, _ := rec.Marshal()
|
||||||
|
|
||||||
firstRecId, err := fx.CreateLog(ctx, aclId, &aclrecordproto.RawACLRecord{
|
firstRecId, err := fx.CreateLog(ctx, aclId, &aclrecordproto.RawAclRecord{
|
||||||
Payload: pl,
|
Payload: pl,
|
||||||
})
|
})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@ -85,7 +85,7 @@ func TestService_AddRecord(t *testing.T) {
|
|||||||
fx.mockClient.EXPECT().AddRecord(ctx, aclIdBytes, gomock.Any()).Do(func(ctx context.Context, logId []byte, rec *consensusproto.Record) {
|
fx.mockClient.EXPECT().AddRecord(ctx, aclIdBytes, gomock.Any()).Do(func(ctx context.Context, logId []byte, rec *consensusproto.Record) {
|
||||||
addRec = rec
|
addRec = rec
|
||||||
})
|
})
|
||||||
rec = &aclrecordproto.ACLRecord{
|
rec = &aclrecordproto.AclRecord{
|
||||||
PrevId: firstRecId,
|
PrevId: firstRecId,
|
||||||
Identity: fx.account.Account().Identity,
|
Identity: fx.account.Account().Identity,
|
||||||
Data: []byte{'1', '2', '3', '4'},
|
Data: []byte{'1', '2', '3', '4'},
|
||||||
@ -93,7 +93,7 @@ func TestService_AddRecord(t *testing.T) {
|
|||||||
}
|
}
|
||||||
pl, _ = rec.Marshal()
|
pl, _ = rec.Marshal()
|
||||||
|
|
||||||
newRecId, err := fx.AddRecord(ctx, aclId, &aclrecordproto.RawACLRecord{
|
newRecId, err := fx.AddRecord(ctx, aclId, &aclrecordproto.RawAclRecord{
|
||||||
Payload: pl,
|
Payload: pl,
|
||||||
})
|
})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|||||||
@ -37,7 +37,7 @@ func (w *watcher) AddConsensusRecords(recs []*consensusproto.Record) {
|
|||||||
w.isReady.Do(func() {
|
w.isReady.Do(func() {
|
||||||
close(w.ready)
|
close(w.ready)
|
||||||
})
|
})
|
||||||
records := make([]*aclrecordproto.RawACLRecordWithId, 0, len(recs))
|
records := make([]*aclrecordproto.RawAclRecordWithId, 0, len(recs))
|
||||||
|
|
||||||
for _, rec := range recs {
|
for _, rec := range recs {
|
||||||
recId, err := cidToString(rec.Id)
|
recId, err := cidToString(rec.Id)
|
||||||
@ -45,16 +45,16 @@ func (w *watcher) AddConsensusRecords(recs []*consensusproto.Record) {
|
|||||||
log.Error("received invalid id from consensus node", zap.Error(err))
|
log.Error("received invalid id from consensus node", zap.Error(err))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
records = append(records, &aclrecordproto.RawACLRecordWithId{
|
records = append(records, &aclrecordproto.RawAclRecordWithId{
|
||||||
Payload: rec.Payload,
|
Payload: rec.Payload,
|
||||||
Id: recId,
|
Id: recId,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
aclReq := &aclrecordproto.ACLSyncMessage{
|
aclReq := &aclrecordproto.AclSyncMessage{
|
||||||
Content: &aclrecordproto.ACLSyncContentValue{
|
Content: &aclrecordproto.AclSyncContentValue{
|
||||||
Value: &aclrecordproto.ACLSyncContentValue_AddRecords{
|
Value: &aclrecordproto.AclSyncContentValue_AddRecords{
|
||||||
AddRecords: &aclrecordproto.ACLAddRecords{
|
AddRecords: &aclrecordproto.AclAddRecords{
|
||||||
Records: records,
|
Records: records,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@ -11,7 +11,7 @@ type listStorage struct {
|
|||||||
db *pogreb.DB
|
db *pogreb.DB
|
||||||
keys aclKeys
|
keys aclKeys
|
||||||
id string
|
id string
|
||||||
root *aclrecordproto.RawACLRecordWithId
|
root *aclrecordproto.RawAclRecordWithId
|
||||||
}
|
}
|
||||||
|
|
||||||
func newListStorage(db *pogreb.DB) (ls liststorage.ListStorage, err error) {
|
func newListStorage(db *pogreb.DB) (ls liststorage.ListStorage, err error) {
|
||||||
@ -21,7 +21,7 @@ func newListStorage(db *pogreb.DB) (ls liststorage.ListStorage, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if rootId == nil {
|
if rootId == nil {
|
||||||
err = liststorage.ErrUnknownACLId
|
err = liststorage.ErrUnknownAclId
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,11 +30,11 @@ func newListStorage(db *pogreb.DB) (ls liststorage.ListStorage, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if root == nil {
|
if root == nil {
|
||||||
err = liststorage.ErrUnknownACLId
|
err = liststorage.ErrUnknownAclId
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
rootWithId := &aclrecordproto.RawACLRecordWithId{
|
rootWithId := &aclrecordproto.RawAclRecordWithId{
|
||||||
Payload: root,
|
Payload: root,
|
||||||
Id: string(rootId),
|
Id: string(rootId),
|
||||||
}
|
}
|
||||||
@ -48,7 +48,7 @@ func newListStorage(db *pogreb.DB) (ls liststorage.ListStorage, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func createListStorage(db *pogreb.DB, root *aclrecordproto.RawACLRecordWithId) (ls liststorage.ListStorage, err error) {
|
func createListStorage(db *pogreb.DB, root *aclrecordproto.RawAclRecordWithId) (ls liststorage.ListStorage, err error) {
|
||||||
keys := aclKeys{}
|
keys := aclKeys{}
|
||||||
has, err := db.Has(keys.RootIdKey())
|
has, err := db.Has(keys.RootIdKey())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -86,7 +86,7 @@ func (l *listStorage) Id() string {
|
|||||||
return l.id
|
return l.id
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *listStorage) Root() (*aclrecordproto.RawACLRecordWithId, error) {
|
func (l *listStorage) Root() (*aclrecordproto.RawAclRecordWithId, error) {
|
||||||
return l.root, nil
|
return l.root, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,14 +96,14 @@ func (l *listStorage) Head() (head string, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if bytes == nil {
|
if bytes == nil {
|
||||||
err = liststorage.ErrUnknownACLId
|
err = liststorage.ErrUnknownAclId
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
head = string(bytes)
|
head = string(bytes)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *listStorage) GetRawRecord(ctx context.Context, id string) (raw *aclrecordproto.RawACLRecordWithId, err error) {
|
func (l *listStorage) GetRawRecord(ctx context.Context, id string) (raw *aclrecordproto.RawAclRecordWithId, err error) {
|
||||||
res, err := l.db.Get(l.keys.RawRecordKey(id))
|
res, err := l.db.Get(l.keys.RawRecordKey(id))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@ -113,7 +113,7 @@ func (l *listStorage) GetRawRecord(ctx context.Context, id string) (raw *aclreco
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
raw = &aclrecordproto.RawACLRecordWithId{
|
raw = &aclrecordproto.RawAclRecordWithId{
|
||||||
Payload: res,
|
Payload: res,
|
||||||
Id: id,
|
Id: id,
|
||||||
}
|
}
|
||||||
@ -124,6 +124,6 @@ func (l *listStorage) SetHead(headId string) (err error) {
|
|||||||
return l.db.Put(l.keys.HeadIdKey(), []byte(headId))
|
return l.db.Put(l.keys.HeadIdKey(), []byte(headId))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *listStorage) AddRawRecord(ctx context.Context, rec *aclrecordproto.RawACLRecordWithId) error {
|
func (l *listStorage) AddRawRecord(ctx context.Context, rec *aclrecordproto.RawAclRecordWithId) error {
|
||||||
return l.db.Put(l.keys.RawRecordKey(rec.Id), rec.Payload)
|
return l.db.Put(l.keys.RawRecordKey(rec.Id), rec.Payload)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func testList(t *testing.T, store liststorage.ListStorage, root *aclrecordproto.RawACLRecordWithId, head string) {
|
func testList(t *testing.T, store liststorage.ListStorage, root *aclrecordproto.RawAclRecordWithId, head string) {
|
||||||
require.Equal(t, store.Id(), root.Id)
|
require.Equal(t, store.Id(), root.Id)
|
||||||
|
|
||||||
aclRoot, err := store.Root()
|
aclRoot, err := store.Root()
|
||||||
@ -25,7 +25,7 @@ func TestListStorage_Create(t *testing.T) {
|
|||||||
fx.open(t)
|
fx.open(t)
|
||||||
defer fx.stop(t)
|
defer fx.stop(t)
|
||||||
|
|
||||||
aclRoot := &aclrecordproto.RawACLRecordWithId{Payload: []byte("root"), Id: "someRootId"}
|
aclRoot := &aclrecordproto.RawAclRecordWithId{Payload: []byte("root"), Id: "someRootId"}
|
||||||
listStore, err := createListStorage(fx.db, aclRoot)
|
listStore, err := createListStorage(fx.db, aclRoot)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
testList(t, listStore, aclRoot, aclRoot.Id)
|
testList(t, listStore, aclRoot, aclRoot.Id)
|
||||||
@ -41,7 +41,7 @@ func TestListStorage_Create(t *testing.T) {
|
|||||||
func TestListStorage_Methods(t *testing.T) {
|
func TestListStorage_Methods(t *testing.T) {
|
||||||
fx := newFixture(t)
|
fx := newFixture(t)
|
||||||
fx.open(t)
|
fx.open(t)
|
||||||
aclRoot := &aclrecordproto.RawACLRecordWithId{Payload: []byte("root"), Id: "someRootId"}
|
aclRoot := &aclrecordproto.RawAclRecordWithId{Payload: []byte("root"), Id: "someRootId"}
|
||||||
_, err := createListStorage(fx.db, aclRoot)
|
_, err := createListStorage(fx.db, aclRoot)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
fx.stop(t)
|
fx.stop(t)
|
||||||
@ -61,7 +61,7 @@ func TestListStorage_Methods(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("add raw record and get raw record", func(t *testing.T) {
|
t.Run("add raw record and get raw record", func(t *testing.T) {
|
||||||
newRec := &aclrecordproto.RawACLRecordWithId{Payload: []byte("rec"), Id: "someRecId"}
|
newRec := &aclrecordproto.RawAclRecordWithId{Payload: []byte("rec"), Id: "someRecId"}
|
||||||
require.NoError(t, listStore.AddRawRecord(context.Background(), newRec))
|
require.NoError(t, listStore.AddRawRecord(context.Background(), newRec))
|
||||||
aclRec, err := listStore.GetRawRecord(context.Background(), newRec.Id)
|
aclRec, err := listStore.GetRawRecord(context.Background(), newRec.Id)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|||||||
@ -182,7 +182,7 @@ func (s *spaceStorage) CreateTreeStorage(payload treestorage.TreeStorageCreatePa
|
|||||||
return createTreeStorage(s.objDb, payload)
|
return createTreeStorage(s.objDb, payload)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *spaceStorage) ACLStorage() (liststorage.ListStorage, error) {
|
func (s *spaceStorage) AclStorage() (liststorage.ListStorage, error) {
|
||||||
return s.aclStorage, nil
|
return s.aclStorage, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -17,7 +17,7 @@ func spaceTestPayload() spacestorage.SpaceStorageCreatePayload {
|
|||||||
RawHeader: []byte("header"),
|
RawHeader: []byte("header"),
|
||||||
Id: "headerId",
|
Id: "headerId",
|
||||||
}
|
}
|
||||||
aclRoot := &aclrecordproto.RawACLRecordWithId{
|
aclRoot := &aclrecordproto.RawAclRecordWithId{
|
||||||
Payload: []byte("aclRoot"),
|
Payload: []byte("aclRoot"),
|
||||||
Id: "aclRootId",
|
Id: "aclRootId",
|
||||||
}
|
}
|
||||||
@ -37,7 +37,7 @@ func testSpace(t *testing.T, store spacestorage.SpaceStorage, payload spacestora
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, payload.SpaceHeaderWithId, header)
|
require.Equal(t, payload.SpaceHeaderWithId, header)
|
||||||
|
|
||||||
aclStorage, err := store.ACLStorage()
|
aclStorage, err := store.AclStorage()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
testList(t, aclStorage, payload.AclWithId, payload.AclWithId.Id)
|
testList(t, aclStorage, payload.AclWithId, payload.AclWithId.Id)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user