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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package remotepds
import (
"context"
"fmt"
"k8s.io/apimachinery/pkg/runtime/schema"
commonv1 "github.com/johnandersen777/socialweb-computer-kcp/api/common/v1alpha1"
pdsv1alpha1 "github.com/johnandersen777/socialweb-computer-kcp/api/pds/v1alpha1"
"github.com/johnandersen777/socialweb-computer-kcp/internal/bus"
"github.com/johnandersen777/socialweb-computer-kcp/internal/contract/atprotorepo"
"github.com/johnandersen777/socialweb-computer-kcp/internal/contract/pds"
"github.com/johnandersen777/socialweb-computer-kcp/internal/pds/remote"
)
const Kind = "RemotePDS"
var GroupKind = schema.GroupKind{Group: pdsv1alpha1.GroupName, Kind: Kind}
func (c *Controller) host(to commonv1.ObjectRef) (*remote.Host, error) {
host, ok := c.hosts.Get(to.Workspace, to.Name)
if !ok || host == nil {
return nil, fmt.Errorf("%w: the RemotePDS %s is not ready", pds.ErrNotFound, to.String())
}
return host, nil
}
func (c *Controller) Provide() {
bus.Provide(c.bus, GroupKind, pds.CapabilityAccount, func(_ context.Context, to commonv1.ObjectRef, _ []string) (pds.Transport, error) {
return c.host(to)
})
bus.Provide(c.bus, GroupKind, pds.CapabilityAccount, func(_ context.Context, to commonv1.ObjectRef, scope []string) (pds.Accounts, error) {
host, err := c.host(to)
if err != nil {
return nil, err
}
return host.Accounts(scope), nil
})
bus.Provide(c.bus, GroupKind, pds.CapabilitySession, func(_ context.Context, to commonv1.ObjectRef, scope []string) (pds.Sessions, error) {
host, err := c.host(to)
if err != nil {
return nil, err
}
return host.Sessions(scope), nil
})
bus.Provide(c.bus, GroupKind, pds.CapabilityServiceAuth, func(_ context.Context, to commonv1.ObjectRef, scope []string) (pds.ServiceAuth, error) {
host, err := c.host(to)
if err != nil {
return nil, err
}
return host.ServiceAuth(scope), nil
})
bus.Provide(c.bus, GroupKind, pds.CapabilitySync, func(_ context.Context, to commonv1.ObjectRef, _ []string) (pds.Sync, error) {
host, err := c.host(to)
if err != nil {
return nil, err
}
return host.Sync(), nil
})
bus.Provide(c.bus, GroupKind, pds.CapabilityAccount, func(_ context.Context, to commonv1.ObjectRef, scope []string) (atprotorepo.Repo, error) {
host, err := c.host(to)
if err != nil {
return nil, err
}
did, err := pds.AccountDID(scope)
if err != nil {
return nil, err
}
return host.Repo(did)
})
}