plugin

package
v3.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 23, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package plugin orchestrates the plugin relationship between rules and the tfvet process

It uses hashicorp's go-plugin which implements a local client/server relationship with plugins and allows communication to the plugins over grpc.

To read more about hashicorp's plugin system see here: https://github.com/hashicorp/go-plugin/blob/master/docs/internals.md

Index

Constants

This section is empty.

Variables

View Source
var Handshake = plugin.HandshakeConfig{
	ProtocolVersion:  1,
	MagicCookieKey:   "TFVET_PLUGIN",
	MagicCookieValue: "26pGPy",
}

Handshake is a common handshake that is shared by plugin and host. If any of the below values do not match for the plugin being run, the handshake will fail. This means that the handshake acts as a type of versioning to instantly deprecate plugin apis that will no longer work.

More documentation on the HandshakeConfig here: https://pkg.go.dev/github.com/hashicorp/go-plugin#HandshakeConfig

Functions

This section is empty.

Types

type GRPCClient

type GRPCClient struct {
	// contains filtered or unexported fields
}

GRPCClient represents the implementation for a client that can talk to plugins. The client in this case is the main Tfvet process.

func (*GRPCClient) ExecuteRule

func (m *GRPCClient) ExecuteRule(request *proto.ExecuteRuleRequest) (*proto.ExecuteRuleResponse, error)

ExecuteRule calls the corresponding ExecuteRule on the plugin through the GRPC client

func (*GRPCClient) GetRuleInfo

func (m *GRPCClient) GetRuleInfo(request *proto.GetRuleInfoRequest) (*proto.GetRuleInfoResponse, error)

GetRuleInfo calls the corresponding GetRuleInfo method on the plugin through the GRPC client

type GRPCServer

type GRPCServer struct {
	proto.UnimplementedTfvetRulePluginServer
	Impl RuleDefinition
}

GRPCServer is the implementation that allows the plugin to respond to requests from the main process.

func (*GRPCServer) ExecuteRule

ExecuteRule executes a single rule on a plugin

func (*GRPCServer) GetRuleInfo

GetRuleInfo gets information about the plugin

type RuleDefinition

type RuleDefinition interface {
	ExecuteRule(request *proto.ExecuteRuleRequest) (*proto.ExecuteRuleResponse, error)
	GetRuleInfo(request *proto.GetRuleInfoRequest) (*proto.GetRuleInfoResponse, error)
}

RuleDefinition is the interface in which both the plugin and the host has to implement

type TfvetRulePlugin

type TfvetRulePlugin struct {
	plugin.Plugin
	Impl RuleDefinition
}

TfvetRulePlugin is just a wrapper so we implement the correct go-plugin interface it allows us to serve/consume the plugin

func (*TfvetRulePlugin) GRPCClient

func (p *TfvetRulePlugin) GRPCClient(ctx context.Context, broker *plugin.GRPCBroker, c *grpc.ClientConn) (interface{}, error)

GRPCClient is the client implementation that allows our main process to send RPCs to plugins.

func (*TfvetRulePlugin) GRPCServer

func (p *TfvetRulePlugin) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Server) error

GRPCServer is the server implementation that allows our plugins to receive RPCs.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL