flightplan

package
v0.0.30 Latest Latest
Warning

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

Go to latest
Published: May 31, 2024 License: MPL-2.0 Imports: 41 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DecodeTargetUnset = iota
	DecodeTargetVariables
	DecodeTargetGlobals
	DecodeTargetSamples
	DecodeTargetQualities
	DecodeTargetScenariosNamesNoVariants
	DecodeTargetScenariosMatrixOnly
	DecodeTargetScenariosNamesExpandVariants
	DecodeTargetTerraformSettings
	DecodeTargetTerraformCLIs
	DecodeTargetProviders
	DecodeTargetModules
	DecodeTargetScenariosOutlines
	DecodeTargetScenariosComplete
	DecodeTargetAll // Make sure this is always the latest decoding target
)
View Source
const EnvVarPrefix = "ENOS_VAR_"

Variables

View Source
var (
	FlightPlanFileNamePattern = regexp.MustCompile(`^enos[-\w]*?\.hcl$`)
	VariablesNamePattern      = regexp.MustCompile(`^enos[-\w]*?\.vars\.hcl$`)
)

FlightPlanFileNamePattern is what file names match valid enos configuration files.

View Source
var StepVariableType cty.Type

StepVariableType is a cty capsule type that represents "step" variables. Step variables might be known values or unknown references to module outputs. Due to the complex nature of these values we have our cty Type to carry this information for us.

Functions

func CompareQuality

func CompareQuality(a, b *Quality) int

CompareQuality implements a slices.SortFunc for Quality's.

func CompareQualityProto

func CompareQualityProto(ap, bp *pb.Quality) int

CompareQuality implements a slices.SortFunc for pb.Quality's.

func StepVariableVal

func StepVariableVal(stepVar *StepVariable) cty.Value

StepVariableVal returns a new cty.Value of type StepVariableType.

func WithScenarioDecoderDecodeTarget

func WithScenarioDecoderDecodeTarget(t DecodeTarget) func(*ScenarioDecoder)

WithScenarioDecoderDecodeTarget sets the desired target level for the scenario decoder.

func WithScenarioDecoderEvalContext

func WithScenarioDecoderEvalContext(evctx *hcl.EvalContext) func(*ScenarioDecoder)

WithScenarioDecoderEvalContext sets the parent hcl.EvalContext for the decoder.

func WithScenarioDecoderScenarioFilter

func WithScenarioDecoderScenarioFilter(f *ScenarioFilter) func(*ScenarioDecoder)

WithScenarioDecoderScenarioFilter sets the decoders scenario filter.

Types

type DecodeTarget

type DecodeTarget int

DecodeTarget determines the depth of flight plan decoding so we only ever decode, expand and validate information relevant to our operation.

type DecodedMatrices

type DecodedMatrices struct {
	Original        *Matrix
	IncludeProducts []*Matrix
	Excludes        []*Exclude
	FinalProduct    *Matrix
}

func (*DecodedMatrices) Filter

func (d *DecodedMatrices) Filter(f *ScenarioFilter) *Matrix

func (*DecodedMatrices) GetExcludes added in v0.0.29

func (d *DecodedMatrices) GetExcludes() []*Exclude

func (*DecodedMatrices) GetIncludeProducts added in v0.0.29

func (d *DecodedMatrices) GetIncludeProducts() []*Matrix

func (*DecodedMatrices) GetOriginal added in v0.0.29

func (d *DecodedMatrices) GetOriginal() *Matrix

func (*DecodedMatrices) Matrix

func (d *DecodedMatrices) Matrix() *Matrix

func (*DecodedMatrices) Set

func (d *DecodedMatrices) Set(m *Matrix)

type DecodedScenarioBlock

type DecodedScenarioBlock struct {
	Name            string
	Block           *hcl.Block
	EvalContext     *hcl.EvalContext
	DecodeTarget    DecodeTarget
	Scenarios       []*Scenario
	Diagnostics     hcl.Diagnostics
	DecodedMatrices *DecodedMatrices
}

DecodedScenarioBlock is a decoded scenario block.

func (*DecodedScenarioBlock) Matrix

func (d *DecodedScenarioBlock) Matrix() *Matrix

type DecodedScenarioBlocks

type DecodedScenarioBlocks []*DecodedScenarioBlock

DecodedScenarioBlocks are all of the scenario blocks that have been decoded.

func (DecodedScenarioBlocks) CombinedMatrix

func (d DecodedScenarioBlocks) CombinedMatrix() *Matrix

CombinedMatrix returns a combined matrix of all scenario blocks matrices. Uniqueness is by values.

func (DecodedScenarioBlocks) Diagnostics

func (d DecodedScenarioBlocks) Diagnostics() hcl.Diagnostics

func (DecodedScenarioBlocks) Scenarios

func (d DecodedScenarioBlocks) Scenarios() []*Scenario

Scenarios returns all of the scenarios that were decoded.

type Decoder

type Decoder struct {
	FPParser   *hclparse.Parser
	VarsParser *hclparse.Parser
	// contains filtered or unexported fields
}

Decoder is our Enos flight plan, or, our representation of the HCL file(s) an author has composed.

func NewDecoder

func NewDecoder(opts ...DecoderOpt) (*Decoder, error)

NewDecoder takes functional options and returns a new flight plan.

func (*Decoder) Decode

func (d *Decoder) Decode(ctx context.Context) (*FlightPlan, hcl.Diagnostics)

Decode decodes the HCL into a flight plan.

func (*Decoder) Parse

func (d *Decoder) Parse() hcl.Diagnostics

Parse locates enos configuration files and parses them.

func (*Decoder) ParserFiles

func (d *Decoder) ParserFiles() map[string]*hcl.File

ParserFiles returns combined parser files. These files can be used to add context to diagnostics.

type DecoderOpt

type DecoderOpt func(*Decoder) error

DecoderOpt is a functional option for a new flight plan.

func WithDecoderBaseDir

func WithDecoderBaseDir(path string) DecoderOpt

WithDecoderBaseDir sets the flight plan base directory.

func WithDecoderDecodeTarget

func WithDecoderDecodeTarget(mode DecodeTarget) DecoderOpt

WithDecoderDecodeTarget sets the decoding mode.

func WithDecoderEnv

func WithDecoderEnv(vars []string) DecoderOpt

WithDecoderEnv sets flight plan variables from env vars.

func WithDecoderFPFiles

func WithDecoderFPFiles(files RawFiles) DecoderOpt

WithDecoderFPFiles sets the flight plan contents as raw bytes.

func WithDecoderScenarioFilter

func WithDecoderScenarioFilter(filter *ScenarioFilter) DecoderOpt

WithDecoderScenarioFilter sets the scenario decoding filter.

func WithDecoderVarFiles

func WithDecoderVarFiles(files RawFiles) DecoderOpt

WithDecoderVarFiles sets the flight plan variable contents as raw bytes.

type Element

type Element struct {
	Key string
	Val string
	// contains filtered or unexported fields
}

An Element represents a single element of a matrix vector.

func NewElement

func NewElement(key string, val string) Element

NewElement takes an element key and value and returns a new Element.

func (Element) Equal

func (e Element) Equal(other Element) bool

Equals compares the element with another Element.

func (Element) Proto

func (e Element) Proto() *pb.Matrix_Element

Proto returns the element as a proto message.

func (Element) String

func (e Element) String() string

String returns the element as a string.

type Exclude

type Exclude struct {
	Mode   pb.Matrix_Exclude_Mode
	Vector *Vector
}

Exclude is an exclusion filter that can be passed to the matrix. It includes the exclusion mode to use and a matching vector.

func NewExclude

func NewExclude(mode pb.Matrix_Exclude_Mode, vec *Vector) (*Exclude, error)

NewExclude takes an ExcludeMode and Vector, validates the ExcludeMode and returns a pointer to a new instance of Exclude and any errors encountered.

func (*Exclude) FromProto

func (ex *Exclude) FromProto(pfe *pb.Matrix_Exclude)

FromProto unmarshals a proto Matrix_Exclude into itself.

func (*Exclude) Match

func (ex *Exclude) Match(vec *Vector) bool

Match determines if Exclude directive matches the given Vector.

func (*Exclude) Proto

func (ex *Exclude) Proto() *pb.Matrix_Exclude

Proto returns the exclude as a proto message.

type FlightPlan

type FlightPlan struct {
	BaseDir           string
	BodyContent       *hcl.BodyContent
	Files             map[string]*hcl.File
	Modules           []*Module
	Providers         []*Provider
	Qualities         []*Quality
	TerraformSettings []*TerraformSetting
	TerraformCLIs     []*TerraformCLI
	Samples           []*Sample
	ScenarioBlocks    DecodedScenarioBlocks
}

FlightPlan represents our flight plan, the main configuration of Enos.

func DecodeProto

func DecodeProto(
	ctx context.Context,
	pfp *pb.FlightPlan,
	target DecodeTarget,
	f *pb.Scenario_Filter,
) (*FlightPlan, *pb.DecodeResponse)

DecodeProto takes a wire request of a FlightPlan and returns a new flight plan and a wire encodable decode response.

func NewFlightPlan

func NewFlightPlan(opts ...Opt) (*FlightPlan, error)

NewFlightPlan returns a new instance of a FlightPlan.

func (*FlightPlan) Scenarios

func (fp *FlightPlan) Scenarios() []*Scenario

func (*FlightPlan) ScenariosSelect

func (fp *FlightPlan) ScenariosSelect(f *ScenarioFilter) []*Scenario

ScenariosSelect takes a scenario filter and returns a slice of matching scenarios.

type Matrix

type Matrix struct {
	Vectors []*Vector
}

Matrix is an ordered list of vectors. Vectors can be of any length. A matrix can be irregular if different length vectors are used.

func NewMatrix

func NewMatrix() *Matrix

NewMatrix returns a pointer to a new instance of Matrix.

func (*Matrix) AddVector

func (m *Matrix) AddVector(vec *Vector)

AddVector adds a Vector the Matrix.

func (*Matrix) AddVectorSorted

func (m *Matrix) AddVectorSorted(vec *Vector)

AddVectorSorted adds a sorted Vector to a sorted Matrix.

func (*Matrix) CartesianProduct

func (m *Matrix) CartesianProduct() *Matrix

CartesianProduct returns a pointer to a new Matrix whose Vectors are the Cartesian product of combining all possible Vector Elements from the Matrix.

func (*Matrix) Compact

func (m *Matrix) Compact()

Compact removes duplicate Vectors from a Matrix.

func (*Matrix) ContainsVectorUnordered

func (m *Matrix) ContainsVectorUnordered(other *Vector) bool

ContainsVectorUnordered returns whether or not a matrix has a Vector whose unordered values contain those of the other Vector.

func (*Matrix) Copy

func (m *Matrix) Copy() *Matrix

Copy creates a new copy of the Matrix.

func (*Matrix) Equal

func (m *Matrix) Equal(other *Matrix) bool

Equal returns true if the Matrix and other Matrix have equal verticies.

func (*Matrix) EqualUnordered

func (m *Matrix) EqualUnordered(other *Matrix) bool

EqualUnordered returns true if the Matrix and other Matrix have equal but unordered verticies.

func (*Matrix) Exclude

func (m *Matrix) Exclude(Excludes ...*Exclude) *Matrix

Exclude takes exclude vararg exclude directives as instances of Exclude. It returns a new Matrix with all Exclude directives having been processed on the parent Matrix.

func (*Matrix) Filter

func (m *Matrix) Filter(filter *ScenarioFilter) *Matrix

Filter takes a CcenarioFilter returns a new filtered Matrix.

func (*Matrix) FromProto

func (m *Matrix) FromProto(in *pb.Matrix)

FromProto takes a proto representation of a Matrix and unmarshals it into itself.

func (*Matrix) GetVectors

func (m *Matrix) GetVectors() []*Vector

GetVectors is an accessor for the vectors.

func (*Matrix) HasVector

func (m *Matrix) HasVector(other *Vector) bool

HasVector returns whether or not a Matrix has a Vector that exactly matches the Elements of another that is given.

func (*Matrix) HasVectorSorted

func (m *Matrix) HasVectorSorted(other *Vector) bool

HasVectorSorted returns whether or not a sorted Matrix has a sorted Vector. It assumes the Matrix and Vector have both already been sorted.

func (*Matrix) HasVectorUnordered

func (m *Matrix) HasVectorUnordered(other *Vector) bool

HasVectorUnordered returns whether or not a Matrix has a Vector whose unordered values match exactly with another that is given.

func (*Matrix) IntersectionContainsUnordered

func (m *Matrix) IntersectionContainsUnordered(other *Matrix) *Matrix

IntersectionContainsUnordered takes another Matrix and returns a new Matrix whose Vectors are composed of the result of a intersection of both matrices vector elements that are contained and unordered. It's important to note that contains does not mean equal, so a vector [1,2,3] contains [3,1] but a vector of [3,1] does not contain [1,2,3] because it doesn't have all of the elements.

func (*Matrix) Proto

func (m *Matrix) Proto() *pb.Matrix

Proto returns the Matrix as a proto message. If a Matrix is created with a ScenarioFilter that has Includes and Excludes a round trip is lossy and will only retain the Vectors.

func (*Matrix) Sort

func (m *Matrix) Sort()

Sort sorts by all Vectors and Elements included.

func (*Matrix) SortVectorElements

func (m *Matrix) SortVectorElements()

SortVectorElements sorts all the elements of each Vector.

func (*Matrix) String

func (m *Matrix) String() string

String returns the Matrix Vectors as a string.

func (*Matrix) SymmetricDifferenceUnordered

func (m *Matrix) SymmetricDifferenceUnordered(other *Matrix) *Matrix

SymmetricDifferenceUnordered returns a new Matrix that includes the symmetric difference between two matrices of unordered vertices.

func (*Matrix) Unique

func (m *Matrix) Unique() *Matrix

Unique returns a new Matrix with all unique Vectors.

func (*Matrix) UniqueValues

func (m *Matrix) UniqueValues() *Matrix

UniqueValues returns a new Matrix with all Vectors that have unique values.

type Module

type Module struct {
	Name    string
	Source  string
	Version string
	Attrs   map[string]cty.Value
}

Module represents an Enos Terraform module block.

func NewModule

func NewModule() *Module

NewModule returns a new Module.

func (*Module) FromCtyValue

func (m *Module) FromCtyValue(val cty.Value) error

FromCtyValue takes a cty.Value and unmarshals it onto itself. It expects a valid object created from ToCtyValue().

func (*Module) ToCtyValue

func (m *Module) ToCtyValue() cty.Value

ToCtyValue returns the module contents as an object cty.Value. We can then embed this into the Variables section of the eval context to allowed method style expression references.

type Opt

type Opt func(*FlightPlan) error

Opt is a flight plan option.

func WithFlightPlanBaseDirectory

func WithFlightPlanBaseDirectory(dir string) Opt

WithFlightPlanBaseDirectory sets the base directory to the absolute path of the directory given.

type Provider

type Provider struct {
	Type   string           `cty:"type"`
	Alias  string           `cty:"alias"`
	Config *SchemalessBlock `cty:"config"`
}

Provider is a Enos transport configuration.

func NewProvider

func NewProvider() *Provider

NewProvider returns a new Provider.

func (*Provider) FromCtyValue

func (p *Provider) FromCtyValue(val cty.Value) error

FromCtyValue takes a cty.Value and unmarshals it onto itself. It expects a valid object created from ToCtyValue().

func (*Provider) ToCtyValue

func (p *Provider) ToCtyValue() cty.Value

ToCtyValue returns the provider contents as an object cty.Value.

type Quality

type Quality struct {
	Name        string
	Description string
}

Quality represents an Enos Terraform quality block.

func NewQuality

func NewQuality() *Quality

NewQuality returns a new Quality.

func (*Quality) FromCtyValue

func (q *Quality) FromCtyValue(val cty.Value) error

FromCtyValue takes a cty.Value and unmarshals it onto itself. It expects a valid object created from ToCtyValue().

func (*Quality) FromProto

func (q *Quality) FromProto(p *pb.Quality)

FromProto unmarshal the Quality wire representation onto the struct.

func (*Quality) ToCtyValue

func (q *Quality) ToCtyValue() cty.Value

ToCtyValue returns the quality contents as an object cty.Value. We can then embed this into the quality section of the eval context to allowed method style expression references.

func (*Quality) ToProto

func (q *Quality) ToProto() *pb.Quality

ToProto coverts the Quality struct to the wire representation.

type RawFiles

type RawFiles map[string][]byte

RawFiles are a map of flightplan configuration files and their contents.

func FindRawFiles

func FindRawFiles(dir string, pattern *regexp.Regexp) (RawFiles, error)

FindRawFiles scans a directory for files matching the given pattern and returns the loaded raw files.

func LoadRawFiles

func LoadRawFiles(paths []string) (RawFiles, error)

LoadRawFiles takes a slice of paths and returns the loaded raw files.

type Sample

type Sample struct {
	Name       string
	Attributes cty.Value
	Subsets    []*SampleSubset
}

A sample is named collection of subsets and attributes.

func NewSample

func NewSample() *Sample

NewSample returns a new Sample.

func (*Sample) Decode

func (s *Sample) Decode(block *hcl.Block, ctx *hcl.EvalContext) hcl.Diagnostics

Decode decodes a sample from an HCL block and eval context.

func (*Sample) Frame

func (s *Sample) Frame(
	ctx context.Context,
	ws *pb.Workspace,
	filter *pb.Sample_Filter,
) (
	*SampleFrame,
	*pb.DecodeResponse,
)

Frame takes a context, workspace, and sample filter and decodes and filters a matching field.

func (*Sample) Ref

func (s *Sample) Ref() *pb.Ref_Sample

Ref returns the proto reference.

type SampleFrame

type SampleFrame struct {
	*Sample
	Filter       *pb.Sample_Filter
	SubsetFrames SampleSubsetFrames
}

A sample field is a collection of subset fields one-or-more subsets.

func (*SampleFrame) Elements

func (s *SampleFrame) Elements(subsetFrameName string, r *rand.Rand, m *Matrix) ([]*pb.Sample_Element, error)

Elements takes a SubsetFrames name, a random number source, and optionally a matrix whose vertices refer elements in the sample subset frame to include. If no matrix is given the entire subset frame will be returned.

func (*SampleFrame) FilterMax

func (s *SampleFrame) FilterMax() (int32, error)

func (*SampleFrame) FilterMin

func (s *SampleFrame) FilterMin() (int32, error)

func (*SampleFrame) FilterMinMax

func (s *SampleFrame) FilterMinMax() (int32, int32, error)

func (*SampleFrame) FilterPercentage

func (s *SampleFrame) FilterPercentage() (float32, error)

func (*SampleFrame) FilterValidate

func (s *SampleFrame) FilterValidate() (bool, error)

FilterValidate compares the sample frame with our filter configuration settings. It returns a boolean if we should return the entire frame. It will raise an error if our frame is unable to meet out filter configuration.

func (*SampleFrame) Keys

func (s *SampleFrame) Keys() []string

func (*SampleFrame) Ref

func (s *SampleFrame) Ref() *pb.Ref_Sample

func (*SampleFrame) Size

func (s *SampleFrame) Size() int32

func (*SampleFrame) Validate added in v0.0.29

func (s *SampleFrame) Validate() error

Validate validates the sample frame by ensuring that at least one subset frame exists and is valid.

type SampleObservation

type SampleObservation struct {
	*SampleFrame       // The sample frame that was used to create the observation
	SubsetObservations SampleSubsetObservations
}

SampleObservation is a result of taking an algorithmic observation of a sample frame. Each subset is represented by a matrix whose vertices correspond to the sampled elements.

func SampleFuncAll

func SampleFuncAll(ctx context.Context, frame *SampleFrame, r *rand.Rand) (*SampleObservation, error)

SampleFuncAll takes a sample frame and returns all of the subsets elements as the observation. If the frame filter is not compatible with returning all an error will be returned.

func SampleFuncPurposiveStratified

func SampleFuncPurposiveStratified(ctx context.Context, frame *SampleFrame, r *rand.Rand) (*SampleObservation, error)

SampleFuncPurposiveStratified takes a sample frame and random number generator and returns a new sample observation. We're purposive (or judgemental) in that our algorithm will prefer that each subset is represented before doing a stratified distribution by proportion. If there are any remainders after our purposive and stratified distributions then we'll distribute remaining elements across subsets evenly by order of subset remaining capacity.

func (*SampleObservation) Elements

func (s *SampleObservation) Elements(r *rand.Rand) ([]*pb.Sample_Element, error)

Elements takes a random source, expands all of the sample elements in all frames, and returns the elements in the wire format.

func (*SampleObservation) Size

func (s *SampleObservation) Size() int32

Size is the length of the our SubsetObservations.

type SampleObservationFunc

type SampleObservationFunc func(context.Context, *SampleFrame, *rand.Rand) (*SampleObservation, error)

SampleObservationFunc takes a context, a sample frame, and a random number source and returns a SampleObservation.

type SampleObservationOpt

type SampleObservationOpt func(*SampleObservationReq)

SampleObservationOpt is a functional option for a NewSampleObservationReq.

func WithSampleObservationReqFilter

func WithSampleObservationReqFilter(f *pb.Sample_Filter) SampleObservationOpt

func WithSampleObservationReqRandSeed

func WithSampleObservationReqRandSeed(seed int64) SampleObservationOpt

func WithSampleObservationReqWorkSpace

func WithSampleObservationReqWorkSpace(ws *pb.Workspace) SampleObservationOpt

type SampleObservationReq

type SampleObservationReq struct {
	Ws     *pb.Workspace
	Filter *pb.Sample_Filter
	Func   SampleObservationFunc
	Rand   *rand.Rand
}

SampleObservationReq is a request to take an observation of a sample set.

func NewSampleObservationReq

func NewSampleObservationReq(opts ...SampleObservationOpt) (*SampleObservationReq, error)

NewSampleObservationReq takes optional NewSampleObservationOpt's and returns a new SampleObservationReq. Some validation is performed to ensure a valid request but not all validation can happen until the observation request is executed.

func (*SampleObservationReq) Frame

Frame returns the valid sample Frame.

func (*SampleObservationReq) Observe

Observe returns a sample observation.

type SampleSubset

type SampleSubset struct {
	Name           string
	SampleName     string
	ScenarioName   string
	ScenarioFilter string
	Attributes     cty.Value
	Matrix         *Matrix
}

SampleSubset is a subset of samples.

func NewSampleSubset

func NewSampleSubset() *SampleSubset

NewSampleSubset returns a new SampleSubset.

func (*SampleSubset) Frame

Frame takes a context and workspace and decodes and filters the samples scenario matrix into a frame.

type SampleSubsetFrame

type SampleSubsetFrame struct {
	*SampleSubset
	ScenarioFilter *pb.Scenario_Filter
	*Matrix
}

SampleSubsetFrame is filtered frame of a subset.

func (*SampleSubsetFrame) ObserveSimpleRandom

func (s *SampleSubsetFrame) ObserveSimpleRandom(take int32, r *rand.Rand) (*SampleSubsetObservation, error)

ObserveSimpleRandom takes a sample size and a randomness source and returns a sample subset observation from the sample subset using a simple random sampling strategy.

func (*SampleSubsetFrame) Ref

Ref converts our frame to a wire reference. As it only refers to a frame it is lossy.

func (*SampleSubsetFrame) Size

func (s *SampleSubsetFrame) Size() int32

Size returns the total size of elements in the frame.

func (*SampleSubsetFrame) Validate added in v0.0.29

func (s *SampleSubsetFrame) Validate() error

Validate that a sample frame is capable of being used to sample from.

type SampleSubsetFrames

type SampleSubsetFrames map[string]*SampleSubsetFrame // subset name -> subset frame

SampleSubsetFrames are a collection from one-or-more named subset frames.

func (SampleSubsetFrames) Size

func (s SampleSubsetFrames) Size() int32

Size returns the total size of elements in the frame.

type SampleSubsetObservation

type SampleSubsetObservation struct {
	*SampleSubsetFrame
	*Matrix
}

SampleSubsetObservation is an obserservation of a sample subset frame.

func (*SampleSubsetObservation) Size

func (s *SampleSubsetObservation) Size() int32

Size is the size of the sample subset observation.

type SampleSubsetObservations

type SampleSubsetObservations map[string]*SampleSubsetObservation

SampleSubsetObservations are a map of subsets to their observations.

func (SampleSubsetObservations) Keys

func (s SampleSubsetObservations) Keys() []string

Keys are sorted keys of the subset obserservation.

func (SampleSubsetObservations) Size

Size is the size of all sample subset observations.

type SampleValidationOpt added in v0.0.29

type SampleValidationOpt func(*SampleValidationReq)

SampleValidationOpt is a functional option for a NewSampleValidationReq.

func WithSampleValidationReqFilter added in v0.0.29

func WithSampleValidationReqFilter(f *pb.Sample_Filter) SampleValidationOpt

func WithSampleValidationReqWorkSpace added in v0.0.29

func WithSampleValidationReqWorkSpace(ws *pb.Workspace) SampleValidationOpt

func WithSampleValidationWorkerCount added in v0.0.29

func WithSampleValidationWorkerCount(c int) SampleValidationOpt

type SampleValidationReq added in v0.0.29

type SampleValidationReq struct {
	Ws          *pb.Workspace
	Filter      *pb.Sample_Filter
	WorkerCount int
}

SampleValidationReq is a request to validate samples decode and have valid sub-frames.

func NewSampleValidationReq added in v0.0.29

func NewSampleValidationReq(opts ...SampleValidationOpt) (*SampleValidationReq, error)

NewSampleValidationReq takes optional NewSampleValidationOpt's and returns a new SampleValidationReq. Some validation is performed to ensure a valid request but not all validation can happen until the observation request is executed.

func (*SampleValidationReq) Validate added in v0.0.29

Validate takes a sample observation request and validates that the sample can be decoded and that there are no empty sub-frames in the sample frame.

type Scenario

type Scenario struct {
	Name             string
	Description      string
	Variants         *Vector
	TerraformCLI     *TerraformCLI
	TerraformSetting *TerraformSetting
	Steps            []*ScenarioStep
	Providers        []*Provider
	Outputs          []*ScenarioOutput
}

Scenario represents an Enos scenario.

func NewScenario

func NewScenario() *Scenario

NewScenario returns a new Scenario.

func (*Scenario) FilterStr

func (s *Scenario) FilterStr() string

func (*Scenario) FromRef

func (s *Scenario) FromRef(ref *pb.Ref_Scenario)

FromRef takes a unmarshals a scenario reference into itself.

func (*Scenario) Match

func (s *Scenario) Match(filter *ScenarioFilter) bool

Match takes a filter and determines whether or not the scenario matches it.

func (*Scenario) Outline

func (s *Scenario) Outline() *pb.Scenario_Outline

Outline returns the scenario as a scenario outline.

func (*Scenario) Ref

func (s *Scenario) Ref() *pb.Ref_Scenario

Ref returns the proto reference.

func (*Scenario) String

func (s *Scenario) String() string

String returns the scenario identifiers as a string.

func (*Scenario) UID

func (s *Scenario) UID() string

UID returns a unique identifier from the name and variants.

type ScenarioDecoder

type ScenarioDecoder struct {
	*hcl.EvalContext
	DecodeTarget
	*ScenarioFilter
}

ScenarioDecoder decodes filters and decodes scenario blocks to a desired target level.

func NewScenarioDecoder

func NewScenarioDecoder(opts ...ScenarioDecoderOpt) (*ScenarioDecoder, error)

NewScenarioDecoder takes any number of scenario decoder opts and returns a new scenario decoder. If the scenario decoder has not been configured in a valid way an error will be returned.

func (*ScenarioDecoder) DecodeScenario

func (d *ScenarioDecoder) DecodeScenario(
	vec *Vector,
	block *hcl.Block,
) (bool, *Scenario, hcl.Diagnostics)

DecodeScenario configures a child eval context and decodes the scenario.

func (*ScenarioDecoder) DecodeScenarioBlocks

func (d *ScenarioDecoder) DecodeScenarioBlocks(ctx context.Context, blocks []*hcl.Block) DecodedScenarioBlocks

DecodeScenarioBlcoks decodes the "scenario" blocks that are defined in the top-level schem to the target level configured in the decode spec.

type ScenarioDecoderOpt

type ScenarioDecoderOpt func(*ScenarioDecoder)

ScenarioDecoderOpt is a scenario decoder option.

type ScenarioFilter

type ScenarioFilter struct {
	Name               string     // The scenario name
	Include            *Vector    // A scenanario filter broken include a matrix vector
	Exclude            []*Exclude // Explicit scenario/variant exclusions
	SelectAll          bool       // Get all scenarios and variants
	IntersectionMatrix *Matrix    // Like Include but can contain more than one Vector
}

ScenarioFilter is a filter for scenarios.

func NewScenarioFilter

func NewScenarioFilter(opts ...ScenarioFilterOpt) (*ScenarioFilter, error)

NewScenarioFilter takes in options and returns a new filter.

func ParseScenarioFilter

func ParseScenarioFilter(args []string) (*ScenarioFilter, error)

ParseScenarioFilter takes command arguments that have been split by spaces and validates that they are composed of a valid scenario filter.

func (*ScenarioFilter) FromProto

func (sf *ScenarioFilter) FromProto(filter *pb.Scenario_Filter)

FromProto unmarshals a proto filter into itself.

func (*ScenarioFilter) FromSampleSubset

func (sf *ScenarioFilter) FromSampleSubset(subset *SampleSubset) error

FromSampleSubset takes a sample subset and returns a scenario filter for it.

func (*ScenarioFilter) FromScenarioRef

func (sf *ScenarioFilter) FromScenarioRef(ref *pb.Ref_Scenario)

FromScenarioRef takes a reference to a scenario and returns a filter for it.

func (*ScenarioFilter) Proto

func (sf *ScenarioFilter) Proto() *pb.Scenario_Filter

Proto returns the scenario filter as a proto filter.

func (*ScenarioFilter) String

func (sf *ScenarioFilter) String() string

String returns the scenario filter as a string.

type ScenarioFilterOpt

type ScenarioFilterOpt func(*ScenarioFilter) error

ScenarioFilterOpt is a scenario filter constructor functional option.

func WithScenarioFilterDecode

func WithScenarioFilterDecode(filter *pb.Scenario_Filter) ScenarioFilterOpt

WithScenarioFilterDecode decodes a filter from a proto Filter.

func WithScenarioFilterFromSampleSubset

func WithScenarioFilterFromSampleSubset(subset *SampleSubset) ScenarioFilterOpt

WithScenarioFilterFromSampleSubset takes a sample subset and returns a filter for it.

func WithScenarioFilterFromScenarioRef

func WithScenarioFilterFromScenarioRef(ref *pb.Ref_Scenario) ScenarioFilterOpt

WithScenarioFilterFromScenarioRef takes a scenario reference and returns a filter for it.

func WithScenarioFilterMatchingVariants

func WithScenarioFilterMatchingVariants(vec *Vector) ScenarioFilterOpt

WithScenarioFilterMatchingVariants makes the filter select only scenarios with variants that match the given values.

func WithScenarioFilterName

func WithScenarioFilterName(name string) ScenarioFilterOpt

WithScenarioFilterName sets the filter name.

func WithScenarioFilterParse

func WithScenarioFilterParse(args []string) ScenarioFilterOpt

WithScenarioFilterParse parses the given filter.

func WithScenarioFilterSelectAll

func WithScenarioFilterSelectAll() ScenarioFilterOpt

WithScenarioFilterSelectAll makes the filter select all.

type ScenarioOutput

type ScenarioOutput struct {
	Name        string
	Description string
	Sensitive   bool
	Value       cty.Value
}

ScenarioOutput represents an "output" block in a scenario.

func NewScenarioOutput

func NewScenarioOutput() *ScenarioOutput

NewScenarioOutput returns a new Output.

type ScenarioStep

type ScenarioStep struct {
	Name        string
	Description string
	Module      *Module
	Providers   map[string]*Provider
	DependsOn   []string
	Verifies    []*Quality
	Skip        bool
}

ScenarioStep is a step in an Enos scenario.

func NewScenarioStep

func NewScenarioStep() *ScenarioStep

NewScenarioStep returns a new Scenario step.

type SchemalessBlock

type SchemalessBlock struct {
	Type     string               `cty:"type"`
	Labels   []string             `cty:"labels"`
	Attrs    map[string]cty.Value `cty:"attrs"`
	Children []*SchemalessBlock   `cty:"blocks"`
}

SchemalessBlock is our value on HCL block that has no known schema.

func NewSchemalessBlock

func NewSchemalessBlock() *SchemalessBlock

NewSchemalessBlock takes a block type and any labels and returns a new schemaless block.

func (*SchemalessBlock) Decode

func (s *SchemalessBlock) Decode(block *hcl.Block, ctx *hcl.EvalContext) hcl.Diagnostics

Decode takes in an HCL block and eval context and attempts to decode and evaluate it.

func (*SchemalessBlock) FromCtyValue

func (s *SchemalessBlock) FromCtyValue(val cty.Value) error

FromCtyValue takes a cty.Value and unmarshals it onto itself. It expects a valid object created from ToCtyValue().

func (*SchemalessBlock) ToCtyValue

func (s *SchemalessBlock) ToCtyValue() cty.Value

ToCtyValue returns the schemaless block contents as an object cty.Value.

type StepVariable

type StepVariable struct {
	Value     cty.Value
	Traversal hcl.Traversal
}

StepVariable is the type encapsulated in StepVariableType.

func StepVariableFromVal

func StepVariableFromVal(v cty.Value) (*StepVariable, hcl.Diagnostics)

StepVariableFromVal returns the *StepVariable from a given value.

type TerraformCLI

type TerraformCLI struct {
	Name      string            `cty:"name"   hcl:"name"`
	Path      string            `cty:"path"   hcl:"path,optional"`
	Env       map[string]string `cty:"env"    hcl:"env,optional"`
	ConfigVal cty.Value         `cty:"config" hcl:"config,optional"`
}

TerraformCLI is a Terraform CLI configuration.

func DefaultTerraformCLI

func DefaultTerraformCLI() *TerraformCLI

DefaultTerraformCLI returns a "default" Terraform CLI that attempts to resolve terraform from the system PATH.

func NewTerraformCLI

func NewTerraformCLI() *TerraformCLI

NewTerraformCLI returns a new TerraformCLI.

type TerraformSetting

type TerraformSetting struct {
	Name            string
	RequiredVersion cty.Value
	Experiments     cty.Value
	// name, object with source and version
	RequiredProviders map[string]cty.Value
	// name, map of attribute names and values
	ProviderMetas map[string]map[string]cty.Value
	Backend       *TerraformSettingBackend
	Cloud         cty.Value
}

TerraformSetting is a terraform settings configuration.

func NewTerraformSetting

func NewTerraformSetting() *TerraformSetting

NewTerraformSetting returns a new TerraformSetting.

func (*TerraformSetting) FromCtyValue

func (t *TerraformSetting) FromCtyValue(val cty.Value) error

FromCtyValue takes a cty.Value and unmasharls the value onto itself. Any errors that are encountered are returned. It is expected that the cty.Value is the cty.Value in the eval context.

func (*TerraformSetting) ToCtyValue

func (t *TerraformSetting) ToCtyValue() cty.Value

ToCtyValue returns the terraform contents as an object cty.Value. We can then embed this into the Variables section of the eval context to allowed method style expression references.

type TerraformSettingBackend

type TerraformSettingBackend struct {
	Name       string
	Attrs      map[string]cty.Value
	Workspaces cty.Value
}

TerraformSettingBackend is the "backend".

func NewTerraformSettingBackend

func NewTerraformSettingBackend() *TerraformSettingBackend

NewTerraformSettingBackend returns a new TerraformSettingBackend.

type Variable

type Variable struct {
	Name           string
	Description    string
	Sensitive      bool
	Default        cty.Value
	SetValue       cty.Value
	Type           cty.Type
	ConstraintType cty.Type
}

Variable represents a "variable" block in a module or file.

func NewVariable

func NewVariable() *Variable

NewVariable returns a new Variable.

func (*Variable) Value

func (v *Variable) Value() cty.Value

Value returns either the user-supplied value or the default. If no values have been set it will always return a NilVal.

type VariableValue

type VariableValue struct {
	Expr      hcl.Expression
	Range     hcl.Range
	Source    VariableValueSource
	EnvVarRaw string
}

VariableValue is a user supplied variable value.

type VariableValueSource

type VariableValueSource int
const (
	VariableValueSourceUnknown VariableValueSource = iota
	VariableValueSourceVarsFile
	VariableValueSourceEnvVar
)

type Vector

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

Vector is an ordered collection of matrix elements.

func NewVector

func NewVector(elms ...Element) *Vector

NewMatrix takes zero-or-more elements and returns a pointer to a new instance of Vector.

func NewVectorFromProto

func NewVectorFromProto(pbv *pb.Matrix_Vector) *Vector

NewVectorFromProto takes a proto filter vector and returns a new Vector.

func (*Vector) Add

func (v *Vector) Add(e Element)

Add adds an Element to the Vector.

func (*Vector) ContainsUnordered

func (v *Vector) ContainsUnordered(other *Vector) bool

ContainsUnordered takes a Vector and determines whether all Elements in the given Vector are represented in the Vector.

func (*Vector) Copy

func (v *Vector) Copy() *Vector

Copy creates a new Copy of the Vector.

func (*Vector) CtyVal

func (v *Vector) CtyVal() cty.Value

CtyVal returns the vector as a cty.Value. This is lossy as duplicate keys will be overwritten.

func (*Vector) Elements

func (v *Vector) Elements() []Element

Elements returns a list of the Vectors Elements.

func (*Vector) Equal

func (v *Vector) Equal(other *Vector) bool

Equal returns true if both Vectors have Equal values and Equal value ordering.

func (*Vector) EqualUnordered

func (v *Vector) EqualUnordered(other *Vector) bool

EqualUnordered returns true if both Vectors have the same Elements but might not be ordered the same. This is useful for Vectors of pairs that do not enforce ordering.

func (*Vector) Proto

func (v *Vector) Proto() *pb.Matrix_Vector

Proto returns the Vector as a proto message.

func (*Vector) Sort

func (v *Vector) Sort()

Sort sorts the Vector's Elements.

func (*Vector) String

func (v *Vector) String() string

String returns the Vector as a string.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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