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) DecodeRuleConfig(name string, ret interface{}) error
- func (c *GRPCClient) EmitIssue(rule tflint.Rule, message string, location hcl.Range) error
- func (*GRPCClient) EnsureNoError(err error, proc func() error) error
- func (c *GRPCClient) EvaluateExpr(expr hcl.Expression, ret 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) 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) 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) 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
}
GRPCClient is a plugin-side implementation. Plugin can send requests through the client to host's gRPC 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) EnsureNoError ¶
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.
func (*GRPCClient) EvaluateExpr ¶
func (c *GRPCClient) EvaluateExpr(expr hcl.Expression, ret interface{}, opts *tflint.EvaluateExprOption) error
EvaluateExpr evals the passed expression based on the type.
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 ¶ added in v0.12.0
func (c *GRPCClient) GetModulePath() (addrs.Module, error)
GetModulePath gets the current module path address.
func (*GRPCClient) GetProviderContent ¶ added in v0.12.0
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 ¶ added in v0.12.0
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) 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 ¶ added in v0.12.0
func (s *GRPCServer) GetModulePath(ctx context.Context, req *proto.GetModulePath_Request) (*proto.GetModulePath_Response, error)
GetModulePath gets the current module path address.
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 {
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) error
}
Server is the interface that the host should implement when a plugin communicates with the host.