tflint

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 23, 2020 License: MPL-2.0 Imports: 7 Imported by: 151

Documentation

Index

Constants

View Source
const (
	// EvaluationError is an error when interpolation failed (unexpected)
	EvaluationError string = "E:Evaluation"
	// UnknownValueError is an error when an unknown value is referenced
	UnknownValueError string = "W:UnknownValue"
	// NullValueError is an error when null value is referenced
	NullValueError string = "W:NullValue"
	// TypeConversionError is an error when type conversion of cty.Value failed
	TypeConversionError string = "E:TypeConversion"
	// TypeMismatchError is an error when a type of cty.Value is not as expected
	TypeMismatchError string = "E:TypeMismatch"
	// UnevaluableError is an error when a received expression has unevaluable references.
	UnevaluableError string = "W:Unevaluable"
	// UnexpectedAttributeError is an error when handle unexpected attributes (e.g. block)
	UnexpectedAttributeError string = "E:UnexpectedAttribute"
	// ExternalAPIError is an error when calling the external API (e.g. AWS SDK)
	ExternalAPIError string = "E:ExternalAPI"
	// ContextError is pseudo error code for propagating runtime context.
	ContextError string = "I:Context"

	// FatalLevel is a recorverable error, it cause panic
	FatalLevel string = "Fatal"
	// ErrorLevel is a user-level error, it display and feedback error information
	ErrorLevel string = "Error"
	// WarningLevel is a user-level warning. Although it is an error, it has no effect on execution.
	WarningLevel string = "Warning"
)
View Source
const (
	// ERROR is possible errors
	ERROR = "Error"
	// WARNING doesn't cause problem immediately, but not good
	WARNING = "Warning"
	// NOTICE is not important, it's mentioned
	NOTICE = "Notice"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AttributesRequest

type AttributesRequest struct {
	Resource      string
	AttributeName string
}

AttributesRequest is the interface used to communicate via RPC.

type AttributesResponse

type AttributesResponse struct {
	Attributes []*hcl.Attribute
	Err        error
}

AttributesResponse is the interface used to communicate via RPC.

type Client

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

Client is an RPC client for plugins to query the host process for Terraform configurations Actually, it is an RPC client, but its details are hidden on the plugin side because it satisfies the Runner interface

func NewClient

func NewClient(conn net.Conn) *Client

NewClient returns a new Client

func (*Client) EmitIssue

func (c *Client) EmitIssue(rule Rule, message string, location hcl.Range, meta Metadata) error

EmitIssue emits attributes to build the issue to the host process Note that the passed rule need to be converted to generic objects because the custom structure defined in the plugin cannot be sent via RPC.

func (*Client) EnsureNoError

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

EnsureNoError is a helper for processing when no error occurs This function skips processing without returning an error to the caller when the error is warning

func (*Client) EvaluateExpr

func (c *Client) EvaluateExpr(expr hcl.Expression, ret interface{}) error

EvaluateExpr queries the host process for the result of evaluating the value of the passed expression and reflects it as the value of the second argument based on that.

func (*Client) WalkResourceAttributes

func (c *Client) WalkResourceAttributes(resource, attributeName string, walker func(*hcl.Attribute) error) error

WalkResourceAttributes queries the host process, receives a list of attributes that match the conditions, and passes each to the walker function.

type Config

type Config struct {
	Rules map[string]*RuleConfig
}

Config is a TFLint configuration applied to a plugin At this time, it is not expected that each plugin will reference this directly

type EmitIssueRequest

type EmitIssueRequest struct {
	Rule     *RuleObject
	Message  string
	Location hcl.Range
	Meta     Metadata
}

EmitIssueRequest is the interface used to communicate via RPC.

type Error

type Error struct {
	Code    string
	Level   string
	Message string
	Cause   error
}

Error is application error object. It has own error code for processing according to a type of error.

func (Error) Error

func (e Error) Error() string

Error shows error message. This must be implemented for error interface.

type EvalExprRequest

type EvalExprRequest struct {
	Expr hcl.Expression
	Ret  interface{}
}

EvalExprRequest is the interface used to communicate via RPC.

type EvalExprResponse

type EvalExprResponse struct {
	Val cty.Value
	Err error
}

EvalExprResponse is the interface used to communicate with RPC.

type Metadata

type Metadata struct {
	Expr hcl.Expression
}

Metadata is the additional data sent to the host process to build the issue.

type Rule

type Rule interface {
	Name() string
	Enabled() bool
	Severity() string
	Link() string
	Check(Runner) error
}

Rule is the interface that the plugin's rules should satisfy.

type RuleConfig

type RuleConfig struct {
	Name    string
	Enabled bool
}

RuleConfig is a TFLint's rule config

type RuleObject

type RuleObject struct {
	Data *RuleObjectData
}

RuleObject is an intermediate representation for communicating with RPC.

func (*RuleObject) Enabled

func (r *RuleObject) Enabled() bool

Enabled is a reference method to internal data

func (r *RuleObject) Link() string

Link is a reference method to internal data

func (*RuleObject) Name

func (r *RuleObject) Name() string

Name is a reference method to internal data

func (*RuleObject) Severity

func (r *RuleObject) Severity() string

Severity is a reference method to internal data

type RuleObjectData

type RuleObjectData struct {
	Name     string
	Enabled  bool
	Severity string
	Link     string
}

RuleObjectData holds the data that RuleObject needs to satisfy the Rule interface.

type RuleSet

type RuleSet struct {
	Name    string
	Version string
	Rules   []Rule
}

RuleSet is a list of rules that a plugin should provide

func (*RuleSet) ApplyConfig

func (r *RuleSet) ApplyConfig(config *Config)

ApplyConfig reflects the plugin configuration in the ruleset. Currently used only to enable/disable rules.

func (*RuleSet) Check

func (r *RuleSet) Check(runner *Client) error

Check runs inspection for each rule by applying Runner.

func (*RuleSet) RuleNames

func (r *RuleSet) RuleNames() []string

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

func (*RuleSet) RuleSetName

func (r *RuleSet) RuleSetName() string

RuleSetName is the name of the rule set. Generally, this is synonymous with the name of the plugin.

func (*RuleSet) RuleSetVersion

func (r *RuleSet) RuleSetVersion() string

RuleSetVersion is the version of the plugin.

type Runner

type Runner interface {
	WalkResourceAttributes(string, string, func(*hcl.Attribute) error) error
	EvaluateExpr(expr hcl.Expression, ret interface{}) error
	EmitIssue(rule Rule, message string, location hcl.Range, meta Metadata) error
	EnsureNoError(error, func() error) error
}

Runner acts as a client for each plugin to query the host process about the Terraform configurations.

type Server

type Server interface {
	Attributes(*AttributesRequest, *AttributesResponse) error
	EvalExpr(*EvalExprRequest, *EvalExprResponse) error
	EmitIssue(*EmitIssueRequest, *interface{}) error
}

Server is the interface that hosts that provide the plugin mechanism must meet in order to respond to queries from the plugin.

Jump to

Keyboard shortcuts

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