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 ¶
- type GRPCClient
- func (c *GRPCClient) ApplyChanges() error
- func (c *GRPCClient) DecodeRuleConfig(name string, ret interface{}) error
- func (c *GRPCClient) EmitIssue(rule tflint.Rule, message string, location hcl.Range) error
- func (c *GRPCClient) EmitIssueWithFix(rule tflint.Rule, message string, location hcl.Range, ...) error
- func (*GRPCClient) EnsureNoError(err error, proc func() error) errordeprecated
- func (c *GRPCClient) EvaluateExpr(expr hcl.Expression, target interface{}, opts *tflint.EvaluateExprOption) error
- func (c *GRPCClient) GetFile(file string) (*hcl.File, error)
- func (c *GRPCClient) GetFiles() (map[string]*hcl.File, error)
- func (c *GRPCClient) GetModuleContent(schema *hclext.BodySchema, opts *tflint.GetModuleContentOption) (*hclext.BodyContent, error)
- func (c *GRPCClient) GetModulePath() (addrs.Module, error)
- func (c *GRPCClient) GetOriginalwd() (string, error)
- func (c *GRPCClient) GetProviderContent(name string, inner *hclext.BodySchema, opts *tflint.GetModuleContentOption) (*hclext.BodyContent, error)
- func (c *GRPCClient) GetResourceContent(name string, inner *hclext.BodySchema, opts *tflint.GetModuleContentOption) (*hclext.BodyContent, error)
- func (c *GRPCClient) WalkExpressions(walker tflint.ExprWalker) hcl.Diagnostics
- type GRPCServer
- func (s *GRPCServer) ApplyChanges(ctx context.Context, req *proto.ApplyChanges_Request) (*proto.ApplyChanges_Response, error)
- func (s *GRPCServer) EmitIssue(ctx context.Context, req *proto.EmitIssue_Request) (*proto.EmitIssue_Response, error)
- func (s *GRPCServer) EvaluateExpr(ctx context.Context, req *proto.EvaluateExpr_Request) (*proto.EvaluateExpr_Response, error)
- func (s *GRPCServer) GetFile(ctx context.Context, req *proto.GetFile_Request) (*proto.GetFile_Response, error)
- func (s *GRPCServer) GetFiles(ctx context.Context, req *proto.GetFiles_Request) (*proto.GetFiles_Response, error)
- func (s *GRPCServer) GetModuleContent(ctx context.Context, req *proto.GetModuleContent_Request) (*proto.GetModuleContent_Response, error)
- func (s *GRPCServer) GetModulePath(ctx context.Context, req *proto.GetModulePath_Request) (*proto.GetModulePath_Response, error)
- func (s *GRPCServer) GetOriginalwd(ctx context.Context, req *proto.GetOriginalwd_Request) (*proto.GetOriginalwd_Response, error)
- func (s *GRPCServer) GetRuleConfigContent(ctx context.Context, req *proto.GetRuleConfigContent_Request) (*proto.GetRuleConfigContent_Response, error)
- type Server
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 ¶
func (s *GRPCServer) ApplyChanges(ctx context.Context, req *proto.ApplyChanges_Request) (*proto.ApplyChanges_Response, error)
ApplyChanges applies the passed changes.
func (*GRPCServer) EmitIssue ¶
func (s *GRPCServer) EmitIssue(ctx context.Context, req *proto.EmitIssue_Request) (*proto.EmitIssue_Response, error)
EmitIssue emits the issue with the passed rule, message, location
func (*GRPCServer) EvaluateExpr ¶
func (s *GRPCServer) EvaluateExpr(ctx context.Context, req *proto.EvaluateExpr_Request) (*proto.EvaluateExpr_Response, error)
EvaluateExpr evals the passed expression based on the type.
func (*GRPCServer) GetFile ¶
func (s *GRPCServer) GetFile(ctx context.Context, req *proto.GetFile_Request) (*proto.GetFile_Response, error)
GetFile returns bytes of hcl.File based on the passed file name.
func (*GRPCServer) GetFiles ¶
func (s *GRPCServer) GetFiles(ctx context.Context, req *proto.GetFiles_Request) (*proto.GetFiles_Response, error)
GetFiles returns bytes of hcl.File in the self module context.
func (*GRPCServer) GetModuleContent ¶
func (s *GRPCServer) GetModuleContent(ctx context.Context, req *proto.GetModuleContent_Request) (*proto.GetModuleContent_Response, error)
GetModuleContent gets the contents of the module based on the schema.
func (*GRPCServer) GetModulePath ¶
func (s *GRPCServer) GetModulePath(ctx context.Context, req *proto.GetModulePath_Request) (*proto.GetModulePath_Response, error)
GetModulePath gets the current module path address.
func (*GRPCServer) GetOriginalwd ¶
func (s *GRPCServer) GetOriginalwd(ctx context.Context, req *proto.GetOriginalwd_Request) (*proto.GetOriginalwd_Response, error)
GetOriginalwd gets the original working directory.
func (*GRPCServer) GetRuleConfigContent ¶
func (s *GRPCServer) GetRuleConfigContent(ctx context.Context, req *proto.GetRuleConfigContent_Request) (*proto.GetRuleConfigContent_Response, error)
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.