/
access.go
46 lines (42 loc) · 1.24 KB
/
access.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package local
import (
"context"
"time"
"github.com/textileio/go-buckets/collection"
"github.com/textileio/go-threads/core/did"
)
// PushPathAccessRoles updates path access roles by merging the pushed roles with existing roles
// and returns the merged roles.
// roles is a map of string marshaled public keys to path roles. A non-nil error is returned
// if the map keys are not unmarshalable to public keys.
// To delete a role for a public key, set its value to buckets.None.
func (b *Bucket) PushPathAccessRoles(
ctx context.Context,
pth string,
roles map[did.DID]collection.Role,
) (merged map[did.DID]collection.Role, err error) {
ctx, err = b.authCtx(ctx, time.Hour)
if err != nil {
return
}
id, err := b.Thread()
if err != nil {
return
}
if err = b.c.PushPathAccessRoles(ctx, id, b.Key(), pth, roles); err != nil {
return
}
return b.c.PullPathAccessRoles(ctx, id, b.Key(), pth)
}
// PullPathAccessRoles returns access roles for a path.
func (b *Bucket) PullPathAccessRoles(ctx context.Context, pth string) (roles map[did.DID]collection.Role, err error) {
ctx, err = b.authCtx(ctx, time.Hour)
if err != nil {
return
}
id, err := b.Thread()
if err != nil {
return
}
return b.c.PullPathAccessRoles(ctx, id, b.Key(), pth)
}