constructs

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: 28 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	BindingDirectionFrom = "from"
	BindingDirectionTo   = "to"
)

Variables

Functions

func GetPropertyFunc

func GetPropertyFunc(ps *PropertySource) func(string) any

func GetTypedProperty

func GetTypedProperty[T any](source *PropertySource, key string) (T, bool)

Types

type Binding

type Binding struct {
	Owner              *Construct
	From               *Construct
	To                 *Construct
	Priority           int
	BindingTemplate    BindingTemplate
	Meta               map[string]any
	Inputs             construct.Properties
	Resources          map[string]*Resource
	Edges              []*Edge
	OutputDeclarations map[string]OutputDeclaration
	Outputs            map[string]any
	InitialGraph       construct.Graph
}

func (*Binding) DeclareOutput

func (b *Binding) DeclareOutput(key string, declaration OutputDeclaration)

func (*Binding) GetEdges

func (b *Binding) GetEdges() []*Edge

func (*Binding) GetInitialGraph

func (b *Binding) GetInitialGraph() construct.Graph

func (*Binding) GetInput

func (b *Binding) GetInput(name string) (val any, ok bool)

func (*Binding) GetInputRules

func (b *Binding) GetInputRules() []InputRuleTemplate

func (*Binding) GetPropertySource

func (b *Binding) GetPropertySource() *PropertySource

func (*Binding) GetResource

func (b *Binding) GetResource(resourceId string) (resource *Resource, ok bool)

func (*Binding) GetResources

func (b *Binding) GetResources() map[string]*Resource

func (*Binding) GetTemplateEdges

func (b *Binding) GetTemplateEdges() []EdgeTemplate

func (*Binding) GetTemplateInputs

func (b *Binding) GetTemplateInputs() map[string]InputTemplate

func (*Binding) GetTemplateOutputs

func (b *Binding) GetTemplateOutputs() map[string]OutputTemplate

func (*Binding) GetTemplateResourcesIterator

func (b *Binding) GetTemplateResourcesIterator() Iterator[string, ResourceTemplate]

func (*Binding) GetURN

func (b *Binding) GetURN() model.URN

func (*Binding) SetEdges

func (b *Binding) SetEdges(edges []*Edge)

func (*Binding) SetResource

func (b *Binding) SetResource(resourceId string, resource *Resource)

func (*Binding) String

func (b *Binding) String() string

type BindingDeclaration

type BindingDeclaration struct {
	From   model.URN
	To     model.URN
	Inputs map[string]model.Input
}

type BindingDirection

type BindingDirection string

type BindingTemplate

type BindingTemplate struct {
	From       ConstructTemplateId         `yaml:"from"`
	To         ConstructTemplateId         `yaml:"to"`
	Priority   int                         `yaml:"priority"`
	Inputs     map[string]InputTemplate    `yaml:"inputs"`
	Outputs    map[string]OutputTemplate   `yaml:"outputs"`
	InputRules []InputRuleTemplate         `yaml:"input_rules"`
	Resources  map[string]ResourceTemplate `yaml:"resources"`
	Edges      []EdgeTemplate              `yaml:"edges"`
	// contains filtered or unexported fields
}

func (*BindingTemplate) ResourcesIterator

func (b *BindingTemplate) ResourcesIterator() Iterator[string, ResourceTemplate]

func (*BindingTemplate) UnmarshalYAML

func (b *BindingTemplate) UnmarshalYAML(value *yaml.Node) error

type ConditionalExpressionTemplate

type ConditionalExpressionTemplate struct {
	Resources map[string]ResourceTemplate `yaml:"resources"`
	Edges     []EdgeTemplate              `yaml:"edges"`
	Outputs   map[string]OutputTemplate   `yaml:"outputs"`
}

type Construct

type Construct struct {
	URN                model.URN
	ConstructTemplate  ConstructTemplate
	Meta               map[string]any
	Inputs             map[string]any
	Resources          map[string]*Resource
	Edges              []*Edge
	OutputDeclarations map[string]OutputDeclaration
	Outputs            map[string]any
	InitialGraph       construct.Graph
	Bindings           []*Binding
	Solution           solution.Solution
}

func NewConstruct

func NewConstruct(constructUrn model.URN, inputs map[string]any) (*Construct, error)

NewConstruct creates a new Construct instance from the given URN and inputs. The URN must be a construct URN. Any inputs that are not provided will be populated with default values from the construct template.

func (*Construct) DeclareOutput

func (c *Construct) DeclareOutput(key string, declaration OutputDeclaration)

func (*Construct) GetEdges

func (c *Construct) GetEdges() []*Edge

func (*Construct) GetInitialGraph

func (c *Construct) GetInitialGraph() construct.Graph

func (*Construct) GetInput

func (c *Construct) GetInput(name string) (value any, ok bool)

func (*Construct) GetInputRules

func (c *Construct) GetInputRules() []InputRuleTemplate

func (*Construct) GetPropertySource

func (c *Construct) GetPropertySource() *PropertySource

func (*Construct) GetResource

func (c *Construct) GetResource(resourceId string) (resource *Resource, ok bool)

func (*Construct) GetResources

func (c *Construct) GetResources() map[string]*Resource

func (*Construct) GetTemplateEdges

func (c *Construct) GetTemplateEdges() []EdgeTemplate

func (*Construct) GetTemplateInputs

func (c *Construct) GetTemplateInputs() map[string]InputTemplate

func (*Construct) GetTemplateOutputs

func (c *Construct) GetTemplateOutputs() map[string]OutputTemplate

func (*Construct) GetTemplateResourcesIterator

func (c *Construct) GetTemplateResourcesIterator() Iterator[string, ResourceTemplate]

func (*Construct) GetURN

func (c *Construct) GetURN() model.URN

func (*Construct) OrderedBindings

func (c *Construct) OrderedBindings() []*Binding

OrderedBindings returns the bindings sorted by priority (lowest to highest). If two bindings have the same priority, their declaration order is preserved.

func (*Construct) SetEdges

func (c *Construct) SetEdges(edges []*Edge)

func (*Construct) SetResource

func (c *Construct) SetResource(resourceId string, resource *Resource)

type ConstructEvaluator

type ConstructEvaluator struct {
	DryRun model.DryRun

	Constructs async.ConcurrentMap[model.URN, *Construct]
	// contains filtered or unexported fields
}

func NewConstructEvaluator

func NewConstructEvaluator(sm *model.StateManager, ssm *stack.StateManager) (*ConstructEvaluator, error)

func (*ConstructEvaluator) AddSolution

func (ce *ConstructEvaluator) AddSolution(urn model.URN, sol solution.Solution)

func (*ConstructEvaluator) Evaluate

func (ce *ConstructEvaluator) Evaluate(constructUrn model.URN, state model.State, ctx context.Context) (engine.SolveRequest, error)

func (*ConstructEvaluator) RegisterOutputValues

func (ce *ConstructEvaluator) RegisterOutputValues(urn model.URN, outputs map[string]any)

func (*ConstructEvaluator) ResolveInput

func (ce *ConstructEvaluator) ResolveInput(k string, v model.Input, t InputTemplate) (any, error)

ResolveInput converts a model.Input to a construct.Input and adds it to the inputs map. If the value of the input is a URN, it resolves the URN to a construct. If the input's status is not "resolved", it returns an error.

type ConstructMarshaller

type ConstructMarshaller struct {
	ConstructEvaluator *ConstructEvaluator
}

ConstructMarshaller is a struct that marshals a Construct into a list of constraints

func (*ConstructMarshaller) Marshal

func (m *ConstructMarshaller) Marshal(constructURN model.URN) (constraints.ConstraintList, error)

Marshal marshals a Construct into a list of constraints

type ConstructTemplate

type ConstructTemplate struct {
	Id          ConstructTemplateId         `yaml:"id"`
	Version     string                      `yaml:"version"`
	Description string                      `yaml:"description"`
	Resources   map[string]ResourceTemplate `yaml:"resources"`
	Edges       []EdgeTemplate              `yaml:"edges"`
	Inputs      map[string]InputTemplate    `yaml:"inputs"`
	Outputs     map[string]OutputTemplate   `yaml:"outputs"`
	InputRules  []InputRuleTemplate         `yaml:"input_rules"`
	// contains filtered or unexported fields
}

func (*ConstructTemplate) GetBindingTemplate

func (c *ConstructTemplate) GetBindingTemplate(direction BindingDirection, other ConstructTemplateId) (BindingTemplate, error)

func (*ConstructTemplate) ResourcesIterator

func (c *ConstructTemplate) ResourcesIterator() Iterator[string, ResourceTemplate]

func (*ConstructTemplate) UnmarshalYAML

func (c *ConstructTemplate) UnmarshalYAML(value *yaml.Node) error

type ConstructTemplateId

type ConstructTemplateId struct {
	Package string `yaml:"package"`
	Name    string `yaml:"name"`
}

func ParseConstructTemplateId

func ParseConstructTemplateId(id string) (ConstructTemplateId, error)

func (*ConstructTemplateId) FromURN

func (c *ConstructTemplateId) FromURN(urn model.URN) error

func (*ConstructTemplateId) String

func (c *ConstructTemplateId) String() string

func (*ConstructTemplateId) UnmarshalYAML

func (c *ConstructTemplateId) UnmarshalYAML(value *yaml.Node) error

type Edge

type Edge struct {
	From ResourceRef
	To   ResourceRef
	Data construct.EdgeData
}

func (*Edge) PrettyPrint

func (e *Edge) PrettyPrint() string

func (*Edge) String

func (e *Edge) String() string

type EdgeOwner

type EdgeOwner interface {
	GetTemplateEdges() []EdgeTemplate
	GetEdges() []*Edge
	SetEdges(edges []*Edge)
	InterpolationSource
}

type EdgeTemplate

type EdgeTemplate struct {
	From ResourceRef        `yaml:"from"`
	To   ResourceRef        `yaml:"to"`
	Data construct.EdgeData `yaml:"data"`
}

func (*EdgeTemplate) UnmarshalYAML

func (e *EdgeTemplate) UnmarshalYAML(value *yaml.Node) error

type InfraOwner

type InfraOwner interface {
	GetURN() model.URN
	GetInputRules() []InputRuleTemplate
	ResourceOwner
	EdgeOwner
	GetTemplateOutputs() map[string]OutputTemplate
	DeclareOutput(key string, declaration OutputDeclaration)
	GetTemplateInputs() map[string]InputTemplate
	GetInput(name string) (value any, ok bool)
	GetInitialGraph() construct.Graph
}

type InputRuleTemplate

type InputRuleTemplate struct {
	If   string                        `yaml:"if"`
	Then ConditionalExpressionTemplate `yaml:"then"`
	Else ConditionalExpressionTemplate `yaml:"else"`
}

type InputTemplate

type InputTemplate struct {
	Name          string             `yaml:"name"`
	Type          string             `yaml:"type"`
	Description   string             `yaml:"description"`
	Default       any                `yaml:"default"`
	Secret        bool               `yaml:"secret"`
	PulumiKey     string             `yaml:"pulumi_key"`
	Validation    ValidationTemplate `yaml:"validation"`
	Configuration map[string]any     `yaml:"configuration"`
}

type InterpolationContext

type InterpolationContext struct {
	AllowedKeys []InterpolationSourceKey
	Construct   *Construct
}

func NewInterpolationContext

func NewInterpolationContext(c *Construct, keys []InterpolationSourceKey) InterpolationContext

type InterpolationSource

type InterpolationSource interface {
	GetPropertySource() *PropertySource
}

type InterpolationSourceKey

type InterpolationSourceKey string
const (
	// InputsInterpolation is an interpolation source used to interpolate values from the construct's inputs
	InputsInterpolation InterpolationSourceKey = "inputs"
	// ResourcesInterpolation is an interpolation source used to interpolate values from the construct's resources
	ResourcesInterpolation InterpolationSourceKey = "resources"
	// EdgesInterpolation is an interpolation source used to interpolate values from the construct's edges
	EdgesInterpolation InterpolationSourceKey = "edges"
	// MetaInterpolation is an interpolation source used to interpolate values from the construct's metadata
	// (i.e., non-properties fields)
	MetaInterpolation InterpolationSourceKey = "meta"
	// BindingInterpolation is an interpolation source used to interpolate values
	// from a binding's from/to constructs using the "from" and "to" interpolation prefixes respectively.
	FromInterpolation InterpolationSourceKey = "from"
	ToInterpolation   InterpolationSourceKey = "to"
)

type IterFunc

type IterFunc[K comparable, V any] func(K, V) error

type Iterator

type Iterator[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func (*Iterator[K, V]) ForEach

func (r *Iterator[K, V]) ForEach(f IterFunc[K, V])

func (*Iterator[K, V]) Next

func (r *Iterator[K, V]) Next() (K, V, bool)

func (*Iterator[K, V]) Reset

func (r *Iterator[K, V]) Reset()

type OutputDeclaration

type OutputDeclaration struct {
	Name  string
	Ref   construct.PropertyRef
	Value any
}

type OutputTemplate

type OutputTemplate struct {
	Name        string `yaml:"name"`
	Description string `yaml:"description"`
	Value       any    `yaml:"value"`
}

type PropertySource

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

func NewPropertySource

func NewPropertySource(source any) *PropertySource

func (*PropertySource) GetProperty

func (p *PropertySource) GetProperty(key string) (value any, ok bool)

type Resource

type Resource struct {
	Id         construct.ResourceId
	Properties construct.Properties
}

type ResourceOwner

type ResourceOwner interface {
	GetResource(resourceId string) (resource *Resource, ok bool)
	SetResource(resourceId string, resource *Resource)
	GetResources() map[string]*Resource
	GetTemplateResourcesIterator() Iterator[string, ResourceTemplate]
	InterpolationSource
}

type ResourceRef

type ResourceRef struct {
	ConstructURN model.URN
	ResourceKey  string
	Property     string
	Type         ResourceRefType
}

func (*ResourceRef) String

func (r *ResourceRef) String() string

type ResourceRefType

type ResourceRefType string
const (
	// ResourceRefTypeTemplate is a reference to a resource template and will be fully resolved prior to constraint generation
	// e.g., ${resources:resourceName.property} or ${resources:resourceName}
	ResourceRefTypeTemplate ResourceRefType = "template"
	// ResourceRefTypeIaC is a reference to an infrastructure as code resource that will be resolved by the engine
	// e.g., ${resources:resourceName#property}
	ResourceRefTypeIaC ResourceRefType = "iac"
	// ResourceRefTypeInterpolated is an initial interpolation reference to a resource.
	// An interpolated value will be evaluated during initial processing and will be converted to one of the other types.
	ResourceRefTypeInterpolated ResourceRefType = "interpolated"
)

type ResourceTemplate

type ResourceTemplate struct {
	Type       string         `yaml:"type"`
	Name       string         `yaml:"name"`
	Namespace  string         `yaml:"namespace"`
	Properties map[string]any `yaml:"properties"`
}

type TemplateFuncSupplier

type TemplateFuncSupplier interface {
	GetTemplateFuncs() template.FuncMap
}

type ValidationTemplate

type ValidationTemplate struct {
	Required     bool     `yaml:"required"`
	MinLength    int      `yaml:"min_length"`
	MaxLength    int      `yaml:"max_length"`
	MinValue     int      `yaml:"min_value"`
	MaxValue     int      `yaml:"max_value"`
	Pattern      string   `yaml:"pattern"`
	Enum         []string `yaml:"enum"`
	UniqueValues bool     `yaml:"unique_values"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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