Skip to content

Commit

Permalink
fix: align accesscontroller interface with orbitdb requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
glouvigny committed Jun 20, 2019
1 parent dc7dfdc commit 504e3bc
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion accesscontroller/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type Default struct {

// CanAppend Checks whether a given identity can append an entry to the log.
// This implementation allows anyone to write to the log.
func (d *Default) CanAppend(*entry.Entry, *identityprovider.Identity) error {
func (d *Default) CanAppend(*entry.Entry, identityprovider.Interface) error {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion accesscontroller/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ import (
)

type Interface interface {
CanAppend(*entry.Entry, *identityprovider.Identity) error
CanAppend(*entry.Entry, identityprovider.Interface) error
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ require (
github.com/ipfs/go-ipld-cbor v0.0.2
github.com/ipfs/go-ipld-format v0.0.2
github.com/ipfs/go-merkledag v0.0.3
github.com/ipfs/interface-go-ipfs-core v0.0.8
github.com/libp2p/go-libp2p-crypto v0.0.2
github.com/mattn/go-colorable v0.1.2 // indirect
github.com/minio/sha256-simd v0.1.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions log.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func (l *Log) Append(payload []byte, pointerCount int) (*entry.Entry, error) {
return nil, errors.Wrap(err, "append failed")
}

if err := l.AccessController.CanAppend(e, l.Identity); err != nil {
if err := l.AccessController.CanAppend(e, l.Identity.Provider); err != nil {
return nil, errors.Wrap(err, "append failed")
}

Expand Down Expand Up @@ -345,7 +345,7 @@ func (l *Log) Join(otherLog *Log, size int) (*Log, error) {

for _, k := range newItems.Keys() {
e := newItems.UnsafeGet(k)
if err := l.AccessController.CanAppend(e, l.Identity); err != nil {
if err := l.AccessController.CanAppend(e, l.Identity.Provider); err != nil {
return nil, errors.Wrap(err, "join failed")
}

Expand Down
2 changes: 1 addition & 1 deletion test/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func TestLog(t *testing.T) {
log1, err := ipfslog.NewLog(ipfs, identities[0], nil)
c.So(err, ShouldBeNil)

err = log1.AccessController.CanAppend(&entry.Entry{Payload: []byte("any")}, identities[0])
err = log1.AccessController.CanAppend(&entry.Entry{Payload: []byte("any")}, identities[0].Provider)
c.So(err, ShouldBeNil)
})

Expand Down
4 changes: 2 additions & 2 deletions test/signed_log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ func mustBytes(data []byte, err error) []byte {
type DenyAll struct {
}

func (*DenyAll) CanAppend(*entry.Entry, *idp.Identity) error {
func (*DenyAll) CanAppend(*entry.Entry, idp.Interface) error {
return errors.New("denied")
}

type TestACL struct {
refIdentity *idp.Identity
}

func (t *TestACL) CanAppend(e *entry.Entry, i *idp.Identity) error {
func (t *TestACL) CanAppend(e *entry.Entry, p idp.Interface) error {
if e.Identity.ID == t.refIdentity.ID {
return errors.New("denied")
}
Expand Down

0 comments on commit 504e3bc

Please sign in to comment.