plugin2host

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: 22 Imported by: 0

Documentation

Overview

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

Communication from the plugin to the host is the second one that occurs. To understand what happens first, see the host2plugin package first. The gRPC client used by the plugin is implicitly initialized by the host2plugin package and hidden in the tflint.Runner interface. Normally, plugin developers do not need to be aware of the details of this client.

The host starts a gRPC server as goroutine to respond from the plugin side when calling Check function in host2plugin. Please note that the gRPC server and client startup in plugin2host is not due to go-plugin.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GRPCClient

type GRPCClient struct {
	Client     proto.RunnerClient
	Fixer      *internal.Fixer
	FixEnabled bool
}

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

func (*GRPCClient) ApplyChanges

func (c *GRPCClient) ApplyChanges() error

ApplyChanges applies the changes in the fixer to the server

func (*GRPCClient) DecodeRuleConfig

func (c *GRPCClient) DecodeRuleConfig(name string, ret interface{}) error

DecodeRuleConfig guesses the schema of the rule config from the passed interface and sends the schema to GRPC server. Content retrieved based on the schema is decoded into the passed interface.

func (*GRPCClient) EmitIssue

func (c *GRPCClient) EmitIssue(rule tflint.Rule, message string, location hcl.Range) error

EmitIssue emits the issue with the passed rule, message, location

func (*GRPCClient) EmitIssueWithFix

func (c *GRPCClient) EmitIssueWithFix(rule tflint.Rule, message string, location hcl.Range, fixFunc func(f tflint.Fixer) error) error

EmitIssueWithFix emits the issue with the passed rule, message, location. Invoke the fix function and add the changes to the fixer. If the fix function returns ErrFixNotSupported, the emitted issue will not be marked as fixable.

func (*GRPCClient) EnsureNoError deprecated

func (*GRPCClient) EnsureNoError(err error, proc func() error) error

EnsureNoError is a helper for error handling. Depending on the type of error generated by EvaluateExpr, determine whether to exit, skip, or continue. If it is continued, the passed function will be executed.

Deprecated: Use errors.Is() instead to determine which errors can be ignored.

func (*GRPCClient) EvaluateExpr

func (c *GRPCClient) EvaluateExpr(expr hcl.Expression, target interface{}, opts *tflint.EvaluateExprOption) error

EvaluateExpr evals the passed expression based on the type. Passing a callback function instead of a value as the target will invoke the callback, passing the evaluated value to the argument.

func (*GRPCClient) GetFile

func (c *GRPCClient) GetFile(file string) (*hcl.File, error)

GetFile returns hcl.File based on the passed file name.

func (*GRPCClient) GetFiles

func (c *GRPCClient) GetFiles() (map[string]*hcl.File, error)

GetFiles returns bytes of hcl.File in the self module context.

func (*GRPCClient) GetModuleContent

func (c *GRPCClient) GetModuleContent(schema *hclext.BodySchema, opts *tflint.GetModuleContentOption) (*hclext.BodyContent, error)

GetModuleContent gets the contents of the module based on the schema.

func (*GRPCClient) GetModulePath

func (c *GRPCClient) GetModulePath() (addrs.Module, error)

GetModulePath gets the current module path address.

func (*GRPCClient) GetOriginalwd

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

GetOriginalwd gets the original working directory.

func (*GRPCClient) GetProviderContent

func (c *GRPCClient) GetProviderContent(name string, inner *hclext.BodySchema, opts *tflint.GetModuleContentOption) (*hclext.BodyContent, error)

GetProviderContent gets the contents of providers based on the schema. This is shorthand of GetModuleContent for providers

func (*GRPCClient) GetResourceContent

func (c *GRPCClient) GetResourceContent(name string, inner *hclext.BodySchema, opts *tflint.GetModuleContentOption) (*hclext.BodyContent, error)

GetResourceContent gets the contents of resources based on the schema. This is shorthand of GetModuleContent for resources

func (*GRPCClient) WalkExpressions

func (c *GRPCClient) WalkExpressions(walker tflint.ExprWalker) hcl.Diagnostics

WalkExpressions traverses expressions in all files by the passed walker. Note that it behaves differently in native HCL syntax and JSON syntax.

In the HCL syntax, `var.foo` and `var.bar` in `[var.foo, var.bar]` are also passed to the walker. In other words, it traverses expressions recursively. To avoid redundant checks, the walker should check the kind of expression.

In the JSON syntax, only an expression of an attribute seen from the top level of the file is passed. In other words, it doesn't traverse expressions recursively. This is a limitation of JSON syntax.

type GRPCServer

type GRPCServer struct {
	proto.UnimplementedRunnerServer

	Impl Server
}

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

func (*GRPCServer) ApplyChanges

ApplyChanges applies the passed changes.

func (*GRPCServer) EmitIssue

EmitIssue emits the issue with the passed rule, message, location

func (*GRPCServer) EvaluateExpr

EvaluateExpr evals the passed expression based on the type.

func (*GRPCServer) GetFile

GetFile returns bytes of hcl.File based on the passed file name.

func (*GRPCServer) GetFiles

GetFiles returns bytes of hcl.File in the self module context.

func (*GRPCServer) GetModuleContent

GetModuleContent gets the contents of the module based on the schema.

func (*GRPCServer) GetModulePath

GetModulePath gets the current module path address.

func (*GRPCServer) GetOriginalwd

GetOriginalwd gets the original working directory.

func (*GRPCServer) GetRuleConfigContent

GetRuleConfigContent returns BodyContent based on the rule name and config schema.

type Server

type Server interface {
	GetOriginalwd() string
	GetModulePath() []string
	GetModuleContent(*hclext.BodySchema, tflint.GetModuleContentOption) (*hclext.BodyContent, hcl.Diagnostics)
	GetFile(string) (*hcl.File, error)
	// For performance, GetFiles returns map[string][]bytes instead of map[string]*hcl.File.
	GetFiles(tflint.ModuleCtxType) map[string][]byte
	GetRuleConfigContent(string, *hclext.BodySchema) (*hclext.BodyContent, map[string][]byte, error)
	EvaluateExpr(hcl.Expression, tflint.EvaluateExprOption) (cty.Value, error)
	EmitIssue(rule tflint.Rule, message string, location hcl.Range, fixable bool) (bool, error)
	ApplyChanges(map[string][]byte) error
}

Server is the interface that the host should implement when a plugin communicates with the host.

Jump to

Keyboard shortcuts

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