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