loader

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2021 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var InputTypeIDs = map[InputType][]string{
	Auto:   {"auto"},
	TfPlan: {"tf-plan", "tf_plan"},
	Cfn:    {"cfn"},
	Tf:     {"tf"},
	K8s:    {"k8s", "kubernetes"},
}

InputTypeIDs maps the InputType enums to string values that can be specified in CLI options.

Functions

func TfFilePathJoin added in v1.1.0

func TfFilePathJoin(leading, trailing string) string

TfFilePathJoin is like `filepath.Join` but avoids cleaning the path. This allows to get unique paths for submodules including a parent module, e.g.:

.
examples/mssql/../../
examples/complete/../../

Types

type AutoDetector

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

func NewAutoDetector

func NewAutoDetector(detectors ...ConfigurationDetector) *AutoDetector

func (*AutoDetector) DetectDirectory

func (a *AutoDetector) DetectDirectory(i InputDirectory, opts DetectOptions) (IACConfiguration, error)

func (*AutoDetector) DetectFile

func (a *AutoDetector) DetectFile(i InputFile, opts DetectOptions) (IACConfiguration, error)

type CfnDetector

type CfnDetector struct{}

func (*CfnDetector) DetectDirectory

func (c *CfnDetector) DetectDirectory(i InputDirectory, opts DetectOptions) (IACConfiguration, error)

func (*CfnDetector) DetectFile

func (c *CfnDetector) DetectFile(i InputFile, opts DetectOptions) (IACConfiguration, error)

type ConfigurationDetector

type ConfigurationDetector interface {
	DetectDirectory(i InputDirectory, opts DetectOptions) (IACConfiguration, error)
	DetectFile(i InputFile, opts DetectOptions) (IACConfiguration, error)
}

ConfigurationDetector implements the visitor part of the visitor pattern for the concrete InputPath implementations. A ConfigurationDetector implementation must contain functions to visit both directories and files. An empty implementation must return nil, nil to indicate that the InputPath has been ignored.

func DetectorByInputTypes added in v1.2.0

func DetectorByInputTypes(inputTypes []InputType) (ConfigurationDetector, error)

type DetectOptions

type DetectOptions struct {
	IgnoreExt  bool
	IgnoreDirs bool
}

DetectOptions are options passed to the configuration detectors.

type HclConfiguration

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

func ParseDirectory

func ParseDirectory(
	path []string,
	dir string,
	moduleRegister *terraformModuleRegister,
) (*HclConfiguration, error)

func (*HclConfiguration) GetChild

func (c *HclConfiguration) GetChild(name string) (*HclConfiguration, bool)

func (*HclConfiguration) GetOutput

func (c *HclConfiguration) GetOutput(name string) interface{}

func (*HclConfiguration) LoadedFiles

func (c *HclConfiguration) LoadedFiles() []string

func (*HclConfiguration) Location

func (c *HclConfiguration) Location(path []string) (LocationStack, error)

func (*HclConfiguration) RegulaInput

func (c *HclConfiguration) RegulaInput() RegulaInput

type IACConfiguration

type IACConfiguration interface {
	// RegulaInput returns a input for regula.
	RegulaInput() RegulaInput
	// LoadedFiles are all of the files contained within this configuration.
	LoadedFiles() []string
	// Location resolves an attribute path to to a file, line and column.
	// The first element of the attributePath is usually the resource ID.
	Location(attributePath []string) (LocationStack, error)
}

IACConfiguration is a loaded IaC Configuration.

type InputDirectory

type InputDirectory interface {
	InputPath
	Walk(w WalkFunc) error
	Children() []InputPath
}

type InputFile

type InputFile interface {
	InputPath
	Ext() string
	Contents() ([]byte, error)
}

type InputPath

type InputPath interface {
	DetectType(d ConfigurationDetector, opts DetectOptions) (IACConfiguration, error)
	IsDir() bool
	Path() string
	Name() string
}

InputPath is a generic interface to represent both directories and files that can serve as inputs for a ConfigurationDetector.

type InputType

type InputType int

InputType is a flag that determines which types regula should look for.

const (
	// Auto means that regula will automatically try to determine which input types are
	// in the given paths.
	Auto InputType = iota
	// TfPlan means that regula will only look for Terraform plan JSON files in given
	// directories and it will assume that given files are Terraform plan JSON.
	TfPlan
	// Cfn means that regula will only look for CloudFormation template files in given
	// directories and it will assume that given files are CloudFormation YAML or JSON.
	Cfn
	// Tf means that regula will load the HCL in the directory in a similar
	// way to terraform plan, or it can also load individual files.
	Tf
	// Kubernetes manifests will be loaded
	K8s
)

func InputTypeForString

func InputTypeForString(typeStr string) (InputType, error)

InputTypeForString is a utility function to translate the string name of an input type to an InputType enum

type KubernetesDetector added in v1.5.0

type KubernetesDetector struct{}

func (*KubernetesDetector) DetectDirectory added in v1.5.0

func (c *KubernetesDetector) DetectDirectory(i InputDirectory, opts DetectOptions) (IACConfiguration, error)

func (*KubernetesDetector) DetectFile added in v1.5.0

type LoadPathsOptions

type LoadPathsOptions struct {
	Paths       []string
	InputTypes  []InputType
	NoGitIgnore bool
	IgnoreDirs  bool
}

type LoadedConfigurations

type LoadedConfigurations interface {
	// AddConfiguration adds a configuration entry for the given path
	AddConfiguration(path string, config IACConfiguration)
	// Location resolves a file path and attribute path from the regula output to a
	// location within a file.
	Location(path string, attributePath []string) (LocationStack, error)
	// AlreadyLoaded indicates whether the given path has already been loaded as part
	// of another IACConfiguration.
	AlreadyLoaded(path string) bool
	// RegulaInput renders the RegulaInput from all of the contained configurations.
	RegulaInput() []RegulaInput
	// Count returns the number of loaded configurations.
	Count() int
}

LoadedConfigurations is a container for IACConfigurations loaded by Regula.

func LoadPaths

func LoadPaths(options LoadPathsOptions) (LoadedConfigurations, error)

type Location

type Location struct {
	Path string `json:"path"`
	Line int    `json:"line"`
	Col  int    `json:"column"`
}

Location is a filepath, line and column.

func (Location) String added in v1.1.0

func (l Location) String() string

type LocationStack added in v1.1.0

type LocationStack = []Location

In some cases, we have more than one location, for example:

attribute "foo" at line 4...
included in "rds" module at line 8...
included in "main" module at line 3...

These are stored as a call stack, with the most specific location in the first position, and the "root of the call stack" at the last position.

type NoLoadableConfigsError

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

func (*NoLoadableConfigsError) Error

func (e *NoLoadableConfigsError) Error() string

type RegulaInput

type RegulaInput map[string]interface{}

RegulaInput is a generic map that can be fed to OPA for regula.

type SourceInfoNode added in v1.6.0

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

func LoadMultiSourceInfoNode added in v1.6.0

func LoadMultiSourceInfoNode(contents []byte) ([]SourceInfoNode, error)

LoadMultiSourceInfoNode parses YAML documents with multiple entries, or normal single YAML/JSON documents.

func LoadSourceInfoNode added in v1.6.0

func LoadSourceInfoNode(contents []byte) (*SourceInfoNode, error)

func (*SourceInfoNode) GetIndex added in v1.6.0

func (node *SourceInfoNode) GetIndex(index int) (*SourceInfoNode, error)

func (*SourceInfoNode) GetKey added in v1.6.0

func (node *SourceInfoNode) GetKey(key string) (*SourceInfoNode, error)

func (*SourceInfoNode) GetPath added in v1.6.0

func (node *SourceInfoNode) GetPath(path []string) (*SourceInfoNode, error)

GetPath tries to retrieve a path as far as possible.

func (*SourceInfoNode) Location added in v1.6.0

func (node *SourceInfoNode) Location() (int, int)

type TfDetector

type TfDetector struct{}

func (*TfDetector) DetectDirectory

func (t *TfDetector) DetectDirectory(i InputDirectory, opts DetectOptions) (IACConfiguration, error)

func (*TfDetector) DetectFile

func (t *TfDetector) DetectFile(i InputFile, opts DetectOptions) (IACConfiguration, error)

type TfNode

type TfNode struct {
	// Exactly one of the next three fields will be set.
	Object    hcl.Body
	Array     hcl.Blocks
	Attribute *hcl.Attribute

	// This will always be set.
	Range hcl.Range
}

A `TfNode` represents a syntax tree in the HCL config.

func (*TfNode) GetChild

func (node *TfNode) GetChild(key string) (*TfNode, error)

func (*TfNode) GetDescendant

func (node *TfNode) GetDescendant(path []string) (*TfNode, error)

type TfPlanDetector

type TfPlanDetector struct{}

func (*TfPlanDetector) DetectDirectory

func (t *TfPlanDetector) DetectDirectory(i InputDirectory, opts DetectOptions) (IACConfiguration, error)

func (*TfPlanDetector) DetectFile

func (t *TfPlanDetector) DetectFile(i InputFile, opts DetectOptions) (IACConfiguration, error)

type UnsupportedOperationDiag

type UnsupportedOperationDiag struct {
}

func (UnsupportedOperationDiag) Description

func (UnsupportedOperationDiag) FromExpr

func (UnsupportedOperationDiag) Severity

func (UnsupportedOperationDiag) Source

type WalkFunc added in v1.3.0

type WalkFunc func(i InputPath) (skip bool, err error)

WalkFunc is a callback that's invoked on each descendent of an InputDirectory. It returns a boolean that, when true, indicates that i.Walk() should not be called.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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