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
47
48
49
50
51
52
53
54
55
56
57
package local
import (
"context"
"strings"
commonv1 "github.com/johnandersen777/socialweb-computer-kcp/api/common/v1alpha1"
atpds "github.com/johnandersen777/socialweb-computer-kcp/internal/atproto/pds"
"github.com/johnandersen777/socialweb-computer-kcp/internal/contract/atprotorepo"
"github.com/johnandersen777/socialweb-computer-kcp/internal/contract/pds"
)
const scopeAll = "*"
var (
_ atprotorepo.Repo = (*Repo)(nil)
_ atprotorepo.SwapDeleter = (*Repo)(nil)
_ atprotorepo.SwapPutter = (*Repo)(nil)
_ pds.Accounts = (*Accounts)(nil)
_ pds.Sessions = (*Sessions)(nil)
_ pds.Sync = (*Sync)(nil)
)
type Secrets func(ctx context.Context, ref commonv1.SecretRef) (map[string]any, error)
func NewRepo(ctx context.Context, srv *atpds.Server, scope []string) (*Repo, error) {
did, err := pds.AccountDID(scope)
if err != nil {
return nil, err
}
return openRepo(ctx, srv, did)
}
func NewAccounts(srv *atpds.Server, secrets Secrets, scope []string) *Accounts {
return &Accounts{srv: srv, secrets: secrets, scope: scope}
}
func NewSessions(srv *atpds.Server, secrets Secrets, scope []string) *Sessions {
return &Sessions{srv: srv, secrets: secrets, scope: scope}
}
func NewSync(srv *atpds.Server) *Sync {
return &Sync{srv: srv}
}
func inScope(scope []string, did string) bool {
if len(scope) == 0 {
return true
}
for _, entry := range scope {
entry = strings.TrimSpace(entry)
if entry == scopeAll || entry == did {
return true
}
}
return false
}