forked from cloudquery/cloudquery
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterface.go
More file actions
43 lines (35 loc) · 1.16 KB
/
interface.go
File metadata and controls
43 lines (35 loc) · 1.16 KB
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
package plugin
import (
"context"
"github.com/cloudquery/cloudquery/plugin/proto"
"github.com/hashicorp/go-plugin"
"google.golang.org/grpc"
)
var Handshake = plugin.HandshakeConfig{
MagicCookieKey: "CQ_PLUGIN_COOKIE",
MagicCookieValue: "6753812e-79c2-4af5-ad01-e6083c374e1f",
}
// PluginMap is the map of plugins we can dispense.
var PluginMap = map[string]plugin.Plugin{
"provider": &CQPlugin{},
}
type CQProvider interface {
Init(driver string, dsn string, verbose bool) error
Fetch(data []byte) error
GenConfig() (string, error)
}
// This is the implementation of plugin.GRPCPlugin so we can serve/consume this.
type CQPlugin struct {
// GRPCPlugin must still implement the Plugin interface
plugin.Plugin
// Concrete implementation, written in Go. This is only used for plugins
// that are written in Go.
Impl CQProvider
}
func (p *CQPlugin) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Server) error {
proto.RegisterProviderServer(s, &GRPCServer{Impl: p.Impl})
return nil
}
func (p *CQPlugin) GRPCClient(ctx context.Context, broker *plugin.GRPCBroker, c *grpc.ClientConn) (interface{}, error) {
return &GRPCClient{client: proto.NewProviderClient(c)}, nil
}