-
Notifications
You must be signed in to change notification settings - Fork 507
/
service.go
64 lines (47 loc) · 1.88 KB
/
service.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package userd
import (
"context"
"google.golang.org/grpc"
"github.com/datawire/dlib/dgroup"
"github.com/telepresenceio/telepresence/rpc/v2/manager"
"github.com/telepresenceio/telepresence/v2/pkg/client"
"github.com/telepresenceio/telepresence/v2/pkg/client/remotefs"
)
const ProcessName = "connector"
// A Service is one that runs during the entire lifecycle of the daemon.
// This should be used to augment the daemon with GRPC services.
type Service interface {
// As will cast this instance to what the given ptr points to, and assign
// that to the pointer. It will panic if type is not implemented.
As(ptr any)
Server() *grpc.Server
// SetManagerClient will assign the manager client that this Service will use when acting as
// a ManagerServer proxy
SetManagerClient(manager.ManagerClient, ...grpc.CallOption)
// FuseFTPMgr returns the manager responsible for creating a client that can connect to the FuseFTP service.
FuseFTPMgr() remotefs.FuseFTPManager
RootSessionInProcess() bool
WithSession(context.Context, string, func(context.Context, Session) error) error
ManageSessions(c context.Context) error
}
type NewServiceFunc func(context.Context, *dgroup.Group, client.Config, *grpc.Server) (Service, error)
type newServiceKey struct{}
func WithNewServiceFunc(ctx context.Context, f NewServiceFunc) context.Context {
return context.WithValue(ctx, newServiceKey{}, f)
}
func GetNewServiceFunc(ctx context.Context) NewServiceFunc {
if f, ok := ctx.Value(newServiceKey{}).(NewServiceFunc); ok {
return f
}
panic("No User daemon Service creator has been registered")
}
type serviceKey struct{}
func WithService(ctx context.Context, s Service) context.Context {
return context.WithValue(ctx, serviceKey{}, s)
}
func GetService(ctx context.Context) Service {
if f, ok := ctx.Value(serviceKey{}).(Service); ok {
return f
}
panic("No User daemon Service has been registered")
}