-
Notifications
You must be signed in to change notification settings - Fork 53
/
core.go
47 lines (41 loc) · 1.1 KB
/
core.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
package plugins
import (
"context"
"errors"
"github.com/hashicorp/go-plugin"
"github.com/rancher/opni/pkg/plugins/meta"
"google.golang.org/grpc"
rpb "google.golang.org/grpc/reflection/grpc_reflection_v1alpha"
)
var ErrNotImplemented = errors.New("not implemented")
var (
GatewayScheme = meta.NewScheme(meta.WithMode(meta.ModeGateway))
AgentScheme = meta.NewScheme(meta.WithMode(meta.ModeAgent))
)
var Handshake = plugin.HandshakeConfig{
ProtocolVersion: plugin.CoreProtocolVersion,
MagicCookieKey: "OPNI_MAGIC_COOKIE",
MagicCookieValue: "opni",
}
func CheckAvailability(ctx context.Context, cc *grpc.ClientConn, id string) error {
ref := rpb.NewServerReflectionClient(cc)
stream, err := ref.ServerReflectionInfo(ctx)
if err != nil {
return err
}
if err := stream.Send(&rpb.ServerReflectionRequest{
MessageRequest: &rpb.ServerReflectionRequest_ListServices{},
}); err != nil {
return err
}
response, err := stream.Recv()
if err != nil {
return err
}
for _, svc := range response.GetListServicesResponse().GetService() {
if svc.Name == id {
return nil
}
}
return ErrNotImplemented
}