loader

package
v3.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

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

Functions

func ValidateInputType

func ValidateInputType(name string) error

func ValidateInputTypes

func ValidateInputTypes(names []string) error

Types

type ArmDetector

type ArmDetector struct{}

func (*ArmDetector) DetectDirectory

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

func (*ArmDetector) DetectFile

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

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

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

type ConfigurationLoader

type ConfigurationLoader func() (LoadedConfigurations, error)

func LocalConfigurationLoader

func LocalConfigurationLoader(options LoadPathsOptions) ConfigurationLoader

type DetectOptions

type DetectOptions struct {
	IgnoreExt  bool
	IgnoreDirs bool
	VarFiles   []string
}

DetectOptions are options passed to the configuration detectors.

type HclConfiguration

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

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
	// Azure Resource Manager JSON
	Arm
)

func InputTypeFromString

func InputTypeFromString(name string) (InputType, error)

func InputTypesFromStrings

func InputTypesFromStrings(names []string) ([]InputType, error)

type KubernetesDetector

type KubernetesDetector struct{}

func (*KubernetesDetector) DetectDirectory

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

func (*KubernetesDetector) DetectFile

type LoadPathsOptions

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

type LoadedConfigurations

type LoadedConfigurations interface {
	// AddConfiguration adds a configuration entry for the given path
	AddConfiguration(path string, config IACConfiguration)
	// ConfigurationPath checks if the given path has already been loaded as a
	// part of another IACConfiguration, and if so, returns the path for that
	// configuration.
	ConfigurationPath(path string) *string
	// AlreadyLoaded indicates whether the given path has already been loaded as
	// part of another IACConfiguration.
	AlreadyLoaded(path string) bool
	// 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)
	// 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.

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

func (l Location) String() string

type LocationStack

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

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

func LoadMultiSourceInfoNode

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

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

func LoadSourceInfoNode

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

func (*SourceInfoNode) GetIndex

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

func (*SourceInfoNode) GetKey

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

func (*SourceInfoNode) GetPath

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

GetPath tries to retrieve a path as far as possible.

func (*SourceInfoNode) Location

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

type TfDetector

type TfDetector struct{}

This is the loader that supports reading files and directories of HCL (.tf) files. The implementation is in the `./pkg/hcl_interpreter/` package in the upgraded policy engine: this file just wraps that. That directory also contains a README explaining how everything fits together.

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 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 WalkFunc

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