Documentation
¶
Index ¶
- Variables
- func ValidateInputType(name string) error
- func ValidateInputTypes(names []string) error
- type ArmDetector
- type AutoDetector
- type CfnDetector
- type ConfigurationDetector
- type ConfigurationLoader
- type DetectOptions
- type HclConfiguration
- type IACConfiguration
- type InputDirectory
- type InputFile
- type InputPath
- type InputType
- type KubernetesDetector
- type LoadPathsOptions
- type LoadedConfigurations
- type Location
- type LocationStack
- type NoLoadableConfigsError
- type RegulaInput
- type SourceInfoNode
- type TfDetector
- type TfPlanDetector
- type WalkFunc
Constants ¶
This section is empty.
Variables ¶
var DefaultInputTypes = InputTypeIDs[Auto]
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 ValidateInputTypes ¶
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 ¶
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 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 InputTypesFromStrings ¶
type KubernetesDetector ¶
type KubernetesDetector struct{}
func (*KubernetesDetector) DetectDirectory ¶
func (c *KubernetesDetector) DetectDirectory(i InputDirectory, opts DetectOptions) (IACConfiguration, error)
func (*KubernetesDetector) DetectFile ¶
func (c *KubernetesDetector) DetectFile(i InputFile, opts DetectOptions) (IACConfiguration, error)
type LoadPathsOptions ¶
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 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)