constraints

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ApplicationConstraintScope ConstraintScope = "application"
	ConstructConstraintScope   ConstraintScope = "construct"
	EdgeConstraintScope        ConstraintScope = "edge"
	ResourceConstraintScope    ConstraintScope = "resource"
	OutputConstraintScope      ConstraintScope = "output"

	MustExistConstraintOperator    ConstraintOperator = "must_exist"
	MustNotExistConstraintOperator ConstraintOperator = "must_not_exist"
	AddConstraintOperator          ConstraintOperator = "add"
	ImportConstraintOperator       ConstraintOperator = "import"
	RemoveConstraintOperator       ConstraintOperator = "remove"
	ReplaceConstraintOperator      ConstraintOperator = "replace"
	EqualsConstraintOperator       ConstraintOperator = "equals"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ApplicationConstraint

type ApplicationConstraint struct {
	Operator        ConstraintOperator   `yaml:"operator" json:"operator"`
	Node            construct.ResourceId `yaml:"node" json:"node"`
	ReplacementNode construct.ResourceId `yaml:"replacement_node,omitempty" json:"replacement_node,omitempty"`
}

ApplicationConstraint is a struct that represents constraints that can be applied on the entire resource graph

Example

To specify a constraint detailing application level intents in yaml

  • scope: application operator: add node: klotho:execution_unit:my_compute

The end result of this should be that the execution unit construct is added to the construct graph for processing

func (*ApplicationConstraint) IsSatisfied

func (constraint *ApplicationConstraint) IsSatisfied(ctx ConstraintGraph) bool

func (*ApplicationConstraint) Scope

func (constraint *ApplicationConstraint) Scope() ConstraintScope

func (*ApplicationConstraint) String

func (constraint *ApplicationConstraint) String() string

func (*ApplicationConstraint) Validate

func (constraint *ApplicationConstraint) Validate() error

type BaseConstraint

type BaseConstraint struct {
	Scope ConstraintScope `yaml:"scope"`
}

BaseConstraint is the base struct for all constraints BaseConstraint is used in our parsing to determine the Scope of the constraint and what go struct it corresponds to

type Constraint

type Constraint interface {
	// Scope returns where on the resource graph the constraint is applied
	Scope() ConstraintScope
	// IsSatisfied returns whether or not the constraint is satisfied based on the resource graph
	// For a resource graph to be valid all constraints must be satisfied
	IsSatisfied(ctx ConstraintGraph) bool
	// Validate returns whether or not the constraint is valid
	Validate() error

	String() string
}

Constraint is an interface detailing different intents that can be applied to a resource graph

type ConstraintGraph

type ConstraintGraph interface {
	GetConstructsResource(construct.ResourceId) *construct.Resource
	GetResource(construct.ResourceId) (*construct.Resource, error)
	AllPaths(src, dst construct.ResourceId) ([][]*construct.Resource, error)
	GetClassification(construct.ResourceId) knowledgebase.Classification
	GetOutput(string) construct.Output
}

type ConstraintList

type ConstraintList []Constraint

func (ConstraintList) MarshalJSON

func (cs ConstraintList) MarshalJSON() ([]byte, error)

func (ConstraintList) MarshalYAML

func (cs ConstraintList) MarshalYAML() (interface{}, error)

func (ConstraintList) NaturalSort

func (list ConstraintList) NaturalSort(i, j int) bool

func (ConstraintList) ToConstraints

func (list ConstraintList) ToConstraints() (Constraints, error)

func (*ConstraintList) UnmarshalYAML

func (cs *ConstraintList) UnmarshalYAML(node *yaml.Node) error

type ConstraintOperator

type ConstraintOperator string

ConstraintOperator is an enum that represents the different operators that can be applied to a constraint

type ConstraintScope

type ConstraintScope string

ConstraintScope is an enum that represents the different scopes that a constraint can be applied to

type Constraints

type Constraints struct {
	Application []ApplicationConstraint
	Construct   []ConstructConstraint
	Resources   []ResourceConstraint
	Edges       []EdgeConstraint
	Outputs     []OutputConstraint
}

func LoadConstraintsFromFile

func LoadConstraintsFromFile(path string) (Constraints, error)

func ParseConstraintsFromFile

func ParseConstraintsFromFile(bytes []byte) (Constraints, error)

ParseConstraintsFromFile parses a yaml file into a map of constraints

Future spec may include ordering of the application of constraints, but for now we assume that the order of the constraints is based on the yaml file and they cannot be grouped outside of scope

func (*Constraints) Append

func (c *Constraints) Append(other Constraints)

func (Constraints) MarshalYAML

func (c Constraints) MarshalYAML() (interface{}, error)

func (Constraints) ToList

func (c Constraints) ToList() ConstraintList

func (*Constraints) UnmarshalYAML

func (c *Constraints) UnmarshalYAML(node *yaml.Node) error

type ConstructConstraint

type ConstructConstraint struct {
	Operator   ConstraintOperator   `yaml:"operator" json:"operator"`
	Target     construct.ResourceId `yaml:"target" json:"target"`
	Type       string               `yaml:"type" json:"type"`
	Attributes map[string]any       `yaml:"attributes" json:"attributes"`
}

ConstructConstraint is a struct that represents constraints that can be applied on a specific construct in the resource graph

Example

To specify a constraint detailing construct expansion and configuration in yaml

- scope: construct operator: equals target: klotho:orm:my_orm type: rds_instance

The end result of this should be that the orm construct is expanded into an rds instance + necessary resources

func (*ConstructConstraint) IsSatisfied

func (constraint *ConstructConstraint) IsSatisfied(ctx ConstraintGraph) bool

func (*ConstructConstraint) Scope

func (constraint *ConstructConstraint) Scope() ConstraintScope

func (*ConstructConstraint) String

func (constraint *ConstructConstraint) String() string

func (*ConstructConstraint) Validate

func (constraint *ConstructConstraint) Validate() error

type Edge

type Edge struct {
	Source construct.ResourceId `yaml:"source"`
	Target construct.ResourceId `yaml:"target"`
}

Edge is a struct that represents how we take in data about an edge in the resource graph

type EdgeConstraint

type EdgeConstraint struct {
	Operator ConstraintOperator `yaml:"operator" json:"operator"`
	Target   Edge               `yaml:"target" json:"target"`
	Data     construct.EdgeData `yaml:"data" json:"data"`
}

func (*EdgeConstraint) IsSatisfied

func (constraint *EdgeConstraint) IsSatisfied(ctx ConstraintGraph) bool

func (*EdgeConstraint) Scope

func (constraint *EdgeConstraint) Scope() ConstraintScope

func (*EdgeConstraint) String

func (constraint *EdgeConstraint) String() string

func (*EdgeConstraint) Validate

func (constraint *EdgeConstraint) Validate() error

type OutputConstraint

type OutputConstraint struct {
	Operator ConstraintOperator    `yaml:"operator" json:"operator"`
	Ref      construct.PropertyRef `yaml:"ref" json:"ref"`
	Name     string                `yaml:"name" json:"name"`
	Value    any                   `yaml:"value" json:"value"`
}

OutputConstraint is a struct that represents a constraint exports some output from the resource graph

Example

To specify a constraint detailing application level intents in yaml

  • scope: output operator: add ref: aws:ec2:instance:my_instance#public_ip name: my_instance_public_ip

The end result of this should be that the execution unit construct is added to the construct graph for processing

func (*OutputConstraint) IsSatisfied

func (constraint *OutputConstraint) IsSatisfied(ctx ConstraintGraph) bool

func (*OutputConstraint) Scope

func (constraint *OutputConstraint) Scope() ConstraintScope

func (*OutputConstraint) String

func (constraint *OutputConstraint) String() string

func (*OutputConstraint) Validate

func (constraint *OutputConstraint) Validate() error

type ResourceConstraint

type ResourceConstraint struct {
	Operator ConstraintOperator   `yaml:"operator" json:"operator"`
	Target   construct.ResourceId `yaml:"target" json:"target"`
	Property string               `yaml:"property" json:"property"`
	Value    any                  `yaml:"value" json:"value"`
}

ResourceConstraint is a struct that represents constraints that can be applied on a specific node in the resource graph. ResourceConstraints are used to control intrinsic properties of a resource in the resource graph

Example

To specify a constraint detailing a property of a resource in yaml

- scope: resource operator: equals target: aws:rds_instance:my_instance property: InstanceClass value: db.t3.micro

The end result of this should be that the the rds instance's InstanceClass property should be set to db.t3.micro

func (*ResourceConstraint) IsSatisfied

func (constraint *ResourceConstraint) IsSatisfied(ctx ConstraintGraph) bool

func (*ResourceConstraint) Scope

func (constraint *ResourceConstraint) Scope() ConstraintScope

func (*ResourceConstraint) String

func (constraint *ResourceConstraint) String() string

func (*ResourceConstraint) Validate

func (constraint *ResourceConstraint) Validate() error

Jump to

Keyboard shortcuts

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