host2plugin

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: MPL-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package host2plugin contains a gRPC server (plugin) and client (host).

In the plugin system, this communication is the first thing that happens, and a plugin must use this package to provide a gRPC server. However, the detailed implementation is hidden in the tflint.RuleSet interface, and plugin developers usually don't need to be aware of gRPC server behavior.

When the host initializes a gRPC client, go-plugin starts a gRPC server on the plugin side as another process. This package acts as a wrapper for go-plugin. Separately, the Check function initializes a new gRPC client for plugin-to-host communication. See the plugin2host package for details.

Index

Constants

View Source
const SDKVersion = "0.20.0"

SDKVersion is the SDK version.

Variables

This section is empty.

Functions

func NewClient

func NewClient(opts *ClientOpts) *plugin.Client

NewClient is a wrapper of plugin.NewClient.

func Serve

func Serve(opts *ServeOpts)

Serve is a wrapper of plugin.Serve. This is entrypoint of all plugins.

Types

type ClientOpts

type ClientOpts struct {
	Cmd *exec.Cmd
}

ClientOpts is an option for initializing a Client.

type GRPCClient

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

GRPCClient is a host-side implementation. Host can send requests through the client to plugin's gRPC server.

func (*GRPCClient) ApplyConfig

func (c *GRPCClient) ApplyConfig(content *hclext.BodyContent, sources map[string][]byte) error

ApplyConfig applies the config to a plugin.

func (*GRPCClient) ApplyGlobalConfig

func (c *GRPCClient) ApplyGlobalConfig(config *tflint.Config) error

ApplyGlobalConfig applies a common config to a plugin.

func (*GRPCClient) Check

func (c *GRPCClient) Check(runner plugin2host.Server) error

Check calls its own plugin implementation with an gRPC client that can send requests to the host process.

func (*GRPCClient) ConfigSchema

func (c *GRPCClient) ConfigSchema() (*hclext.BodySchema, error)

ConfigSchema fetches the config schema from a plugin.

func (*GRPCClient) RuleNames

func (c *GRPCClient) RuleNames() ([]string, error)

RuleNames returns the list of rule names provided by a plugin.

func (*GRPCClient) RuleSetName

func (c *GRPCClient) RuleSetName() (string, error)

RuleSetName returns the name of a plugin.

func (*GRPCClient) RuleSetVersion

func (c *GRPCClient) RuleSetVersion() (string, error)

RuleSetVersion returns the version of a plugin.

func (*GRPCClient) SDKVersion

func (c *GRPCClient) SDKVersion() (*version.Version, error)

SDKVersion returns the SDK version.

func (*GRPCClient) VersionConstraints

func (c *GRPCClient) VersionConstraints() (version.Constraints, error)

VersionConstraints returns constraints of TFLint versions.

type GRPCServer

type GRPCServer struct {
	proto.UnimplementedRuleSetServer
	// contains filtered or unexported fields
}

GRPCServer is a plugin-side implementation. Plugin must implement a server that returns a response for a request from host. The behavior as gRPC server is implemented in the SDK, and the actual behavior is delegated to impl.

func (*GRPCServer) ApplyConfig

ApplyConfig applies the plugin config retrieved from the host to the plugin.

func (*GRPCServer) ApplyGlobalConfig

ApplyGlobalConfig applies a common config to the plugin.

func (*GRPCServer) Check

Check calls plugin rules with a gRPC client that can send requests to the host process.

func (*GRPCServer) GetConfigSchema

GetConfigSchema returns the config schema of the plugin.

func (*GRPCServer) GetName

GetName returns the name of the plugin.

func (*GRPCServer) GetRuleNames

GetRuleNames returns the list of rule names provided by the plugin.

func (*GRPCServer) GetSDKVersion

GetSDKVersion returns the SDK version.

func (*GRPCServer) GetVersion

GetVersion returns the version of the plugin.

func (*GRPCServer) GetVersionConstraint

GetVersionConstraint returns a constraint of TFLint versions.

type RuleSetPlugin

type RuleSetPlugin struct {
	plugin.NetRPCUnsupportedPlugin
	// contains filtered or unexported fields
}

RuleSetPlugin is a wrapper to satisfy the interface of go-plugin.

func (*RuleSetPlugin) GRPCClient

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

GRPCClient returns an RPC client for the host.

func (*RuleSetPlugin) GRPCServer

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

GRPCServer returns an gRPC server acting as a plugin.

type ServeOpts

type ServeOpts struct {
	RuleSet tflint.RuleSet
}

ServeOpts is an option for serving a plugin. Each plugin can pass a RuleSet that represents its own functionality.

Jump to

Keyboard shortcuts

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