-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.go
55 lines (42 loc) · 1.27 KB
/
plugin.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
package configuration
import (
api "github.com/dodo-cli/dodo-core/api/v1alpha3"
dodo "github.com/dodo-cli/dodo-core/pkg/plugin"
"github.com/hashicorp/go-plugin"
"golang.org/x/net/context"
"google.golang.org/grpc"
)
const Type pluginType = "configuration"
type pluginType string
func (t pluginType) String() string {
return string(t)
}
func (t pluginType) GRPCClient() (plugin.Plugin, error) {
return &grpcPlugin{}, nil
}
func (t pluginType) GRPCServer(p dodo.Plugin) (plugin.Plugin, error) {
config, ok := p.(Configuration)
if !ok {
return nil, dodo.ErrInvalidPlugin{
Plugin: p.PluginInfo().Name,
Message: "plugin does not implement Configuration API",
}
}
return &grpcPlugin{Impl: config}, nil
}
type Configuration interface {
dodo.Plugin
ListBackdrops() ([]*api.Backdrop, error)
GetBackdrop(string) (*api.Backdrop, error)
}
type grpcPlugin struct {
plugin.NetRPCUnsupportedPlugin
Impl Configuration
}
func (p *grpcPlugin) GRPCClient(_ context.Context, _ *plugin.GRPCBroker, conn *grpc.ClientConn) (interface{}, error) {
return &client{configClient: api.NewConfigurationPluginClient(conn)}, nil
}
func (p *grpcPlugin) GRPCServer(_ *plugin.GRPCBroker, s *grpc.Server) error {
api.RegisterConfigurationPluginServer(s, &server{impl: p.Impl})
return nil
}