Skip to content

Commit 2731759

Browse files
authored
Merge pull request #51 from anyproto/GO-2836-coordinator-acl
GO-2836 use BuildAclListWithIdentity instead BuildAclList
2 parents b6dfcf2 + b1a7d52 commit 2731759

File tree

3 files changed

+23
-20
lines changed

3 files changed

+23
-20
lines changed

acl/acl.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"time"
66

7+
commonaccount "github.com/anyproto/any-sync/accountservice"
78
"github.com/anyproto/any-sync/app"
89
"github.com/anyproto/any-sync/app/logger"
910
"github.com/anyproto/any-sync/app/ocache"
@@ -29,12 +30,14 @@ type Acl interface {
2930
}
3031

3132
type aclService struct {
32-
consService consensusclient.Service
33-
cache ocache.OCache
33+
consService consensusclient.Service
34+
cache ocache.OCache
35+
accountService commonaccount.Service
3436
}
3537

3638
func (as *aclService) Init(a *app.App) (err error) {
3739
as.consService = app.MustComponent[consensusclient.Service](a)
40+
as.accountService = app.MustComponent[commonaccount.Service](a)
3841

3942
var metricReg *prometheus.Registry
4043
if m := a.Component(metric.CName); m != nil {
@@ -53,7 +56,7 @@ func (as *aclService) Name() (name string) {
5356
}
5457

5558
func (as *aclService) loadObject(ctx context.Context, id string) (ocache.Object, error) {
56-
return newAclObject(ctx, as.consService, id)
59+
return as.newAclObject(ctx, id)
5760
}
5861

5962
func (as *aclService) get(ctx context.Context, spaceId string) (list.AclList, error) {

acl/acl_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/anyproto/any-sync/consensus/consensusclient"
1212
"github.com/anyproto/any-sync/consensus/consensusclient/mock_consensusclient"
1313
"github.com/anyproto/any-sync/consensus/consensusproto"
14+
"github.com/anyproto/any-sync/testutil/accounttest"
1415
"github.com/stretchr/testify/assert"
1516
"github.com/stretchr/testify/require"
1617
"go.uber.org/mock/gomock"
@@ -115,7 +116,7 @@ func newFixture(t *testing.T) *fixture {
115116
fx.consCl.EXPECT().Run(gomock.Any()).AnyTimes()
116117
fx.consCl.EXPECT().Close(gomock.Any()).AnyTimes()
117118

118-
fx.a.Register(fx.consCl).Register(fx.Acl)
119+
fx.a.Register(fx.consCl).Register(fx.Acl).Register(&accounttest.AccountTestService{})
119120

120121
require.NoError(t, fx.a.Start(ctx))
121122
return fx

acl/object.go

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,42 +7,41 @@ import (
77

88
"github.com/anyproto/any-sync/commonspace/object/acl/list"
99
"github.com/anyproto/any-sync/commonspace/object/acl/liststorage"
10-
"github.com/anyproto/any-sync/consensus/consensusclient"
1110
"github.com/anyproto/any-sync/consensus/consensusproto"
1211
"go.uber.org/atomic"
1312
"go.uber.org/zap"
1413
)
1514

16-
func newAclObject(ctx context.Context, cs consensusclient.Service, id string) (*aclObject, error) {
15+
func (as *aclService) newAclObject(ctx context.Context, id string) (*aclObject, error) {
1716
obj := &aclObject{
18-
id: id,
19-
consService: cs,
20-
ready: make(chan struct{}),
17+
id: id,
18+
aclService: as,
19+
ready: make(chan struct{}),
2120
}
22-
if err := cs.Watch(id, obj); err != nil {
21+
if err := as.consService.Watch(id, obj); err != nil {
2322
return nil, err
2423
}
2524
select {
2625
case <-obj.ready:
2726
if obj.consErr != nil {
28-
_ = cs.UnWatch(id)
27+
_ = as.consService.UnWatch(id)
2928
return nil, obj.consErr
3029
}
3130
return obj, nil
3231
case <-ctx.Done():
33-
_ = cs.UnWatch(id)
32+
_ = as.consService.UnWatch(id)
3433
return nil, ctx.Err()
3534
}
3635
}
3736

3837
type aclObject struct {
39-
id string
40-
store liststorage.ListStorage
41-
list.AclList
38+
id string
39+
aclService *aclService
40+
store liststorage.ListStorage
4241

43-
ready chan struct{}
44-
consErr error
45-
consService consensusclient.Service
42+
list.AclList
43+
ready chan struct{}
44+
consErr error
4645

4746
lastUsage atomic.Time
4847

@@ -57,7 +56,7 @@ func (a *aclObject) AddConsensusRecords(recs []*consensusproto.RawRecordWithId)
5756
if a.store, a.consErr = liststorage.NewInMemoryAclListStorage(a.id, recs); a.consErr != nil {
5857
return
5958
}
60-
if a.AclList, a.consErr = list.BuildAclList(a.store, list.NoOpAcceptorVerifier{}); a.consErr != nil {
59+
if a.AclList, a.consErr = list.BuildAclListWithIdentity(a.aclService.accountService.Account(), a.store, list.NoOpAcceptorVerifier{}); a.consErr != nil {
6160
return
6261
}
6362
} else {
@@ -82,7 +81,7 @@ func (a *aclObject) AddConsensusError(err error) {
8281
}
8382

8483
func (a *aclObject) Close() (err error) {
85-
return a.consService.UnWatch(a.id)
84+
return a.aclService.consService.UnWatch(a.id)
8685
}
8786

8887
func (a *aclObject) TryClose(objectTTL time.Duration) (res bool, err error) {

0 commit comments

Comments
 (0)