knowledgebase

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: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DirectionUpstream   Direction = "upstream"
	DirectionDownstream Direction = "downstream"

	SpreadSelectionOperator  SelectionOperator = "spread"
	ClusterSelectionOperator SelectionOperator = "cluster"
	ClosestSelectionOperator SelectionOperator = ""
)

Variables

View Source
var ErrStopWalk = errors.New("stop walk")

Functions

func CreateResource

func CreateResource(kb TemplateKB, id construct.ResourceId) (*construct.Resource, error)

CreateResource creates an empty resource for the given ID, running any sanitization rules on the ID. NOTE: Because of sanitization, once created callers must use the resulting ID for all future operations and not the input ID.

func DependenciesSkipEdgeLayer

func DependenciesSkipEdgeLayer(
	dag construct.Graph,
	kb TemplateKB,
	rid construct.ResourceId,
	layer DependencyLayer,
) func(construct.Edge) bool

DependenciesSkipEdgeLayer returns a function which can be used in calls to construct.DownstreamDependencies and construct.UpstreamDependencies.

func DownstreamFunctional

func DownstreamFunctional(dag construct.Graph, kb TemplateKB, resource construct.ResourceId) ([]construct.ResourceId, error)

func ExecuteDecodeAsResourceId

func ExecuteDecodeAsResourceId(ctx DynamicContext, tmpl string, data DynamicValueData) (construct.ResourceId, error)

func HasConsumedFromResource

func HasConsumedFromResource(consumer, emitter *construct.Resource, ctx DynamicContext) (bool, error)

HasConsumedFromResource returns true if the consumer has consumed from the emitter In order to return true, only one of the emitted values has to be set correctly

func IsCollectionProperty

func IsCollectionProperty(p Property) bool

func IsOperationalResourceSideEffect

func IsOperationalResourceSideEffect(dag construct.Graph, kb TemplateKB, rid, sideEffect construct.ResourceId) (bool, error)

func ReplacePath

func ReplacePath(p Property, original, replacement string)

ReplacePath runs a simple strings.ReplaceAll on the path of the property and all of its sub properties. NOTE: this mutates the property, so make sure to [Property.Clone] it first if you don't want that.

func TemplateArgToRID

func TemplateArgToRID(arg any) (construct.ResourceId, error)

func TransformAllPropertyValues

func TransformAllPropertyValues(ctx DynamicValueContext) error

func TransformToPropertyValue

func TransformToPropertyValue(
	resource construct.ResourceId,
	propertyName string,
	value interface{},
	ctx DynamicContext,
	data DynamicValueData,
) (interface{}, error)

TransformToPropertyValue transforms a value to the correct type for a given property This is used for transforming values from the config template (and any interface value we want to set on a resource) to the correct type for the resource

func UpstreamFunctional

func UpstreamFunctional(dag construct.Graph, kb TemplateKB, resource construct.ResourceId) ([]construct.ResourceId, error)

Types

type AdditionalRule

type AdditionalRule struct {
	If    string            `json:"if" yaml:"if"`
	Steps []OperationalStep `json:"steps" yaml:"steps"`
}

func (AdditionalRule) Hash

func (rule AdditionalRule) Hash() string

type Classification

type Classification struct {
	// Is defines the classifications that the resource belongs to
	Is []string `json:"is" yaml:"is"`
	// Gives defines the attributes that the resource gives to other resources
	Gives []Gives `json:"gives" yaml:"gives"`
}

Classification defines the classification of a resource

type CollectionProperty

type CollectionProperty interface {
	// Item returns the structure of the items within the collection
	Item() Property
}

CollectionProperty is an interface for properties that implement collection structures

type Configuration

type Configuration struct {
	// Field defines a field that should be set on the resource
	Field string `json:"field" yaml:"field"`
	// Value defines the value that should be set on the resource
	Value any `json:"value" yaml:"value"`
}

Configuration defines how to act on any intrinsic values of a resource to make it operational

type ConfigurationRule

type ConfigurationRule struct {
	Resource string        `json:"resource" yaml:"resource"`
	Config   Configuration `json:"configuration" yaml:"configuration"`
}

type Consumption

type Consumption struct {
	Emitted  []ConsumptionObject `json:"emitted" yaml:"emitted"`
	Consumed []ConsumptionObject `json:"consumed" yaml:"consumed"`
}

type ConsumptionObject

type ConsumptionObject struct {
	Model        string `json:"model" yaml:"model"`
	Value        any    `json:"value" yaml:"value"`
	Resource     string `json:"resource" yaml:"resource"`
	PropertyPath string `json:"property_path" yaml:"property_path"`
	Converter    string `json:"converter" yaml:"converter"`
}

func (*ConsumptionObject) Consume

func (c *ConsumptionObject) Consume(val any, ctx DynamicContext, resource *construct.Resource) error

func (*ConsumptionObject) Convert

func (c *ConsumptionObject) Convert(value any, res construct.ResourceId, ctx DynamicContext) (any, error)

func (*ConsumptionObject) Emit

func (c *ConsumptionObject) Emit(ctx DynamicContext, resource construct.ResourceId) (any, error)

type DelayedConsumption

type DelayedConsumption struct {
	Value        any
	Resource     construct.ResourceId
	PropertyPath string
}

func ConsumeFromResource

func ConsumeFromResource(consumer, emitter *construct.Resource, ctx DynamicContext) ([]DelayedConsumption, error)

type DeleteContext

type DeleteContext struct {
	// RequiresNoUpstream is a boolean that tells us if deletion relies on there being no upstream resources
	RequiresNoUpstream bool `yaml:"requires_no_upstream" toml:"requires_no_upstream"`
	// RequiresNoDownstream is a boolean that tells us if deletion relies on there being no downstream resources
	RequiresNoDownstream bool `yaml:"requires_no_downstream" toml:"requires_no_downstream"`
	// RequiresNoUpstreamOrDownstream is a boolean that tells us if deletion relies on there being no upstream or downstream resources
	RequiresNoUpstreamOrDownstream bool `yaml:"requires_no_upstream_or_downstream" toml:"requires_no_upstream_or_downstream"`
}

DeleteContext is supposed to tell us when we are able to delete a resource based on its dependencies

type DependencyLayer

type DependencyLayer string

DependencyLayer represents how far away a resource to return for the Upstream/Downstream methods.

  1. ResourceLocalLayer (layer 1) represents any unique resources the target resource needs to be operational, transitively.
  2. ResourceGlueLayer (layer 2) represents all upstream/downstream resources that represent glue. This will not include any other functional resources and will stopsearching paths once a functional resource is reached.
  3. FirstFunctionalLayer (layer 3) represents all upstream/downstream resources that represent glue and the first functional resource in other paths from the target resource.
const (

	// ResourceLocalLayer (layer 1)
	ResourceLocalLayer DependencyLayer = "local"
	// ResourceDirectLayer (layer 2)
	ResourceDirectLayer DependencyLayer = "direct"
	// ResourceGlueLayer (layer 2)
	ResourceGlueLayer DependencyLayer = "glue"
	// FirstFunctionalLayer (layer 3)
	FirstFunctionalLayer DependencyLayer = "first"
	// AllDepsLayer (layer 4)
	AllDepsLayer DependencyLayer = "all"
)

type DeploymentPermissions

type DeploymentPermissions struct {
	// Deploy defines the permissions that are required to deploy the resource
	Deploy []string `json:"deploy" yaml:"deploy"`
	// TearDown defines the permissions that are required to tear down the resource
	TearDown []string `json:"tear_down" yaml:"tear_down"`
	// Update defines the permissions that are required to update the resource
	Update []string `json:"update" yaml:"update"`
}

type Direction

type Direction string

Direction defines the direction of the rule. The direction options are upstream or downstream

func (Direction) Edge

func (d Direction) Edge(resource, dep construct.ResourceId) construct.SimpleEdge

type DynamicContext

type DynamicContext interface {
	DAG() construct.Graph
	KB() TemplateKB
	ExecuteDecode(tmpl string, data DynamicValueData, value interface{}) error
}

type DynamicValueContext

type DynamicValueContext struct {
	Graph         construct.Graph
	KnowledgeBase TemplateKB
	// contains filtered or unexported fields
}

DynamicValueContext is used to scope the Graph into the template functions

func (DynamicValueContext) AllDownstream

func (ctx DynamicValueContext) AllDownstream(selector any, resource construct.ResourceId) (construct.ResourceList, error)

AllDownstream is like Downstream but returns all transitive downstream resources. nolint: lll

func (DynamicValueContext) AllUpstream

func (ctx DynamicValueContext) AllUpstream(selector any, resource construct.ResourceId) (construct.ResourceList, error)

AllUpstream is like Upstream but returns all transitive upstream resources. nolint: lll

func (DynamicValueContext) ClosestDownstream

func (ctx DynamicValueContext) ClosestDownstream(selector any, resource construct.ResourceId) (construct.ResourceId, error)

func (DynamicValueContext) DAG

func (DynamicValueContext) Downstream

func (ctx DynamicValueContext) Downstream(selector any, resource construct.ResourceId) (construct.ResourceId, error)

Downstream returns the first resource that matches `selector` which is downstream of `resource` nolint: lll

func (DynamicValueContext) ExecuteDecode

func (ctx DynamicValueContext) ExecuteDecode(tmpl string, data DynamicValueData, value interface{}) error

func (DynamicValueContext) ExecuteTemplateDecode

func (ctx DynamicValueContext) ExecuteTemplateDecode(
	t *template.Template,
	data DynamicValueData,
	value interface{},
) error

ExecuteDecode executes the template `tmpl` using `data` and decodes the value into `value`

func (DynamicValueContext) FieldRef

func (ctx DynamicValueContext) FieldRef(field string, resource any) (construct.PropertyRef, error)

FieldRef returns a reference to `field` on `resource` (as a PropertyRef)

func (DynamicValueContext) FieldValue

func (ctx DynamicValueContext) FieldValue(field string, resource any) (any, error)

FieldValue returns the value of `field` on `resource` in json

func (DynamicValueContext) HasDownstream

func (ctx DynamicValueContext) HasDownstream(selector any, resource construct.ResourceId) (bool, error)

Downstream returns the first resource that matches `selector` which is downstream of `resource`

func (DynamicValueContext) HasField

func (ctx DynamicValueContext) HasField(field string, resource any) (bool, error)

func (DynamicValueContext) HasUpstream

func (ctx DynamicValueContext) HasUpstream(selector any, resource construct.ResourceId) (bool, error)

Upstream returns the first resource that matches `selector` which is upstream of `resource`

func (DynamicValueContext) KB

func (DynamicValueContext) LayeredDownstream

func (ctx DynamicValueContext) LayeredDownstream(
	selector any,
	resource construct.ResourceId,
	layer string,
) (construct.ResourceId, error)

LayeredUpstream returns the first resource that matches `selector` which is upstream of `resource` for the specified layer

func (DynamicValueContext) LayeredUpstream

func (ctx DynamicValueContext) LayeredUpstream(
	selector any,
	resource construct.ResourceId,
	layer string,
) (construct.ResourceId, error)

LayeredUpstream returns the first resource that matches `selector` which is upstream of `resource` for the specified layer

func (DynamicValueContext) Parse

func (ctx DynamicValueContext) Parse(tmpl string) (*template.Template, error)

func (DynamicValueContext) PathAncestor

func (ctx DynamicValueContext) PathAncestor(path construct.PropertyPath, depth int) (string, error)

func (DynamicValueContext) PathAncestorExists

func (ctx DynamicValueContext) PathAncestorExists(path construct.PropertyPath, depth int) bool

func (DynamicValueContext) ResolveConfig

func (ctx DynamicValueContext) ResolveConfig(config Configuration, data DynamicValueData) (Configuration, error)

func (DynamicValueContext) ShortestPath

func (ctx DynamicValueContext) ShortestPath(source, destination any) (construct.ResourceList, error)

ShortestPath returns all the resource IDs on the shortest path from source to destination

func (DynamicValueContext) TemplateFunctions

func (ctx DynamicValueContext) TemplateFunctions() template.FuncMap

func (DynamicValueContext) Upstream

func (ctx DynamicValueContext) Upstream(selector any, resource construct.ResourceId) (construct.ResourceId, error)

Upstream returns the first resource that matches `selector` which is upstream of `resource`

type DynamicValueData

type DynamicValueData struct {
	Resource  construct.ResourceId
	Edge      *construct.Edge
	Path      construct.PropertyPath
	GlobalTag string
}

DynamicValueData provides the resource or edge to the templates as `{{ .Self }}` for resources `{{ .Source }}` and `{{ .Target }}` for edges `{{ .Tag }}` for the global tag `{{ .EdgeData }}` for the edge data (see construct.EdgeData)

func (DynamicValueData) EdgeData

func (data DynamicValueData) EdgeData() *construct.EdgeData

func (DynamicValueData) Log

func (data DynamicValueData) Log(level string, message string, args ...interface{}) string

Log is primarily used for debugging templates and shouldn't actually appear in any. Allows for outputting any intermediate values (such as `$integration := downstream "aws:api_integration" .Self`)

func (DynamicValueData) Self

func (data DynamicValueData) Self() (construct.ResourceId, error)

func (DynamicValueData) Source

func (data DynamicValueData) Source() (construct.ResourceId, error)

func (DynamicValueData) Tag

func (data DynamicValueData) Tag() string

func (DynamicValueData) Target

func (data DynamicValueData) Target() (construct.ResourceId, error)

type EdgeOperationalStep

type EdgeOperationalStep struct {
	Resource string `json:"resource" yaml:"resource"`
	OperationalStep
}

type EdgePathSatisfaction

type EdgePathSatisfaction struct {
	// Signals if the classification is derived from the target or not
	// we need this to know how to construct the edge we are going to run expansion on if we have resource values in the classification
	Classification string
	Source         PathSatisfactionRoute
	Target         PathSatisfactionRoute
}

type EdgeRule

type EdgeRule struct {
	If                 string                `json:"if" yaml:"if"`
	Steps              []EdgeOperationalStep `json:"steps" yaml:"steps"`
	ConfigurationRules []ConfigurationRule   `json:"configuration_rules" yaml:"configuration_rules"`
}

type EdgeTemplate

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

	// AlwaysProcess signals that the edge should always be processed even if the source and target exist in the input graph
	// currently we dont check edges for operational rules if they previously existed and this flag is set to false
	AlwaysProcess bool `yaml:"always_process"`

	// DirectEdgeOnly signals that the edge cannot be used within constructing other paths
	// and can only be used as a direct edge
	DirectEdgeOnly bool `yaml:"direct_edge_only"`

	// DeploymentOrderReversed is specified when the edge is in the opposite direction of the deployment order
	DeploymentOrderReversed bool `yaml:"deployment_order_reversed"`

	// DeletetionDependent is used to specify edges which should not influence the deletion criteria of a resource
	// a true value specifies the target being deleted is dependent on the source and do not need to depend on
	// satisfication of the deletion criteria to attempt to delete the true source of the edge.
	DeletionDependent bool `yaml:"deletion_dependent"`

	// Unique see type [Unique]
	Unique Unique `yaml:"unique"`

	OperationalRules []OperationalRule `yaml:"operational_rules"`

	EdgeWeightMultiplier float32 `yaml:"edge_weight_multiplier"`

	Classification []string `yaml:"classification"`

	NoIac bool `json:"no_iac" yaml:"no_iac"`
}

func EdgeTemplatesFromMulti

func EdgeTemplatesFromMulti(multi MultiEdgeTemplate) []EdgeTemplate

type Functionality

type Functionality string
const (
	ErrRequiredProperty = "required property %s is not set on resource %s"

	Compute   Functionality = "compute"
	Cluster   Functionality = "cluster"
	Storage   Functionality = "storage"
	Api       Functionality = "api"
	Messaging Functionality = "messaging"
	Unknown   Functionality = "Unknown"
)

func GetFunctionality

func GetFunctionality(kb TemplateKB, id construct.ResourceId) Functionality

type Gives

type Gives struct {
	// Attribute is the attribute that is given
	Attribute string
	// Functionality is the list of functionalities that the attribute is given to
	Functionality []string
}

Gives defines an attribute that can be provided to other functionalities for the resource it belongs to

func (*Gives) UnmarshalJSON

func (g *Gives) UnmarshalJSON(content []byte) error

func (*Gives) UnmarshalYAML

func (g *Gives) UnmarshalYAML(n *yaml.Node) error

type Graph

type KnowledgeBase

type KnowledgeBase struct {
	Models map[string]*Model
	// contains filtered or unexported fields
}

KnowledgeBase is a struct that represents the object which contains the knowledge of how to make resources operational

func NewKB

func NewKB() *KnowledgeBase

func (*KnowledgeBase) AddEdgeTemplate

func (kb *KnowledgeBase) AddEdgeTemplate(template *EdgeTemplate) error

func (*KnowledgeBase) AddResourceTemplate

func (kb *KnowledgeBase) AddResourceTemplate(template *ResourceTemplate) error

func (*KnowledgeBase) AllPaths

func (kb *KnowledgeBase) AllPaths(from, to construct.ResourceId) ([][]*ResourceTemplate, error)

func (*KnowledgeBase) Edges

func (kb *KnowledgeBase) Edges() ([]graph.Edge[*ResourceTemplate], error)

func (*KnowledgeBase) GetAllowedNamespacedResourceIds

func (kb *KnowledgeBase) GetAllowedNamespacedResourceIds(ctx DynamicValueContext, resourceId construct.ResourceId) ([]construct.ResourceId, error)

func (*KnowledgeBase) GetClassification

func (kb *KnowledgeBase) GetClassification(id construct.ResourceId) Classification

func (*KnowledgeBase) GetEdgeTemplate

func (kb *KnowledgeBase) GetEdgeTemplate(from, to construct.ResourceId) *EdgeTemplate

func (*KnowledgeBase) GetModel

func (kb *KnowledgeBase) GetModel(model string) *Model

func (*KnowledgeBase) GetPathSatisfactionsFromEdge

func (kb *KnowledgeBase) GetPathSatisfactionsFromEdge(source, target construct.ResourceId) ([]EdgePathSatisfaction, error)

func (*KnowledgeBase) GetResourcePropertyType

func (kb *KnowledgeBase) GetResourcePropertyType(resource construct.ResourceId, propertyName string) string

func (*KnowledgeBase) GetResourceTemplate

func (kb *KnowledgeBase) GetResourceTemplate(id construct.ResourceId) (*ResourceTemplate, error)

func (*KnowledgeBase) GetResourcesNamespaceResource

func (kb *KnowledgeBase) GetResourcesNamespaceResource(resource *construct.Resource) (construct.ResourceId, error)

func (*KnowledgeBase) Graph

func (kb *KnowledgeBase) Graph() Graph

func (*KnowledgeBase) HasDirectPath

func (kb *KnowledgeBase) HasDirectPath(from, to construct.ResourceId) bool

func (*KnowledgeBase) HasFunctionalPath

func (kb *KnowledgeBase) HasFunctionalPath(from, to construct.ResourceId) bool

func (*KnowledgeBase) ListResources

func (kb *KnowledgeBase) ListResources() []*ResourceTemplate

ListResources returns a list of all resources in the knowledge base The returned list of resource templates will be sorted by the templates fully qualified type name

type MapProperty

type MapProperty interface {
	// Key returns the property representing the keys of the map
	Key() Property
	// Value returns the property representing the values of the map
	Value() Property
}

MapProperty is an interface for properties that implement map structures

type Model

type Model struct {
	Name       string     `json:"name" yaml:"name"`
	Properties Properties `json:"properties" yaml:"properties"`
	Property   Property   `json:"property" yaml:"property"`
}

func (*Model) GetObjectValue

func (m *Model) GetObjectValue(val any, ctx DynamicContext, data DynamicValueData) (any, error)

GetObjectValue returns the value of the object as the model type

type MultiEdgeTemplate

type MultiEdgeTemplate struct {
	Resource construct.ResourceId   `yaml:"resource"`
	Sources  []construct.ResourceId `yaml:"sources"`
	Targets  []construct.ResourceId `yaml:"targets"`

	// DirectEdgeOnly signals that the edge cannot be used within constructing other paths
	// and can only be used as a direct edge
	DirectEdgeOnly bool `yaml:"direct_edge_only"`

	// DeploymentOrderReversed is specified when the edge is in the opposite direction of the deployment order
	DeploymentOrderReversed bool `yaml:"deployment_order_reversed"`

	// DeletetionDependent is used to specify edges which should not influence the deletion criteria of a resource
	// a true value specifies the target being deleted is dependent on the source and do not need to depend on
	// satisfication of the deletion criteria to attempt to delete the true source of the edge.
	DeletionDependent bool `yaml:"deletion_dependent"`

	// Unique see type [Unique]
	Unique Unique `yaml:"unique"`

	OperationalRules []OperationalRule `yaml:"operational_rules"`

	EdgeWeightMultiplier float32 `yaml:"edge_weight_multiplier"`

	Classification []string `yaml:"classification"`

	NoIac bool `json:"no_iac" yaml:"no_iac"`
}

type OperationalRule

type OperationalRule struct {
	If                 string              `json:"if" yaml:"if"`
	Steps              []OperationalStep   `json:"steps" yaml:"steps"`
	ConfigurationRules []ConfigurationRule `json:"configuration_rules" yaml:"configuration_rules"`
}

func (OperationalRule) Hash

func (rule OperationalRule) Hash() string

type OperationalStep

type OperationalStep struct {
	Resource string `json:"resource" yaml:"resource"`
	// Direction defines the direction of the rule. The direction options are upstream or downstream
	Direction Direction `json:"direction" yaml:"direction"`
	// Resources defines the resource types that the rule should be enforced on. Resource types must be specified if classifications is not specified
	Resources []ResourceSelector `json:"resources" yaml:"resources"`
	// NumNeeded defines the number of resources that must satisfy the rule
	NumNeeded int `json:"num_needed" yaml:"num_needed"`
	// FailIfMissing fails if the step is not satisfied when being evaluated. If this flag is set, the step cannot create dependencies
	FailIfMissing bool `json:"fail_if_missing" yaml:"fail_if_missing"`
	// Unique defines if the resource that is created should be unique
	Unique bool `json:"unique" yaml:"unique"`
	// UseRef defines if the rule should set the field to the property reference instead of the resource itself
	UsePropertyRef string `json:"use_property_ref" yaml:"use_property_ref"`
	// SelectionOperator defines how the rule should select a resource if one does not exist
	SelectionOperator SelectionOperator `json:"selection_operator" yaml:"selection_operator"`
}

OperationalRule defines a rule that must pass checks and actions which must be carried out to make a resource operational

type PathSatisfaction

type PathSatisfaction struct {
	AsTarget []PathSatisfactionRoute `json:"as_target" yaml:"as_target"`
	AsSource []PathSatisfactionRoute `json:"as_source" yaml:"as_source"`
	// DenyClassifications is a list of classifications that the resource cannot be included in paths during expansion
	DenyClassifications []string `yaml:"deny_classifications"`
}

type PathSatisfactionRoute

type PathSatisfactionRoute struct {
	Classification    string                            `json:"classification" yaml:"classification"`
	PropertyReference string                            `json:"property_reference" yaml:"property_reference"`
	Validity          PathSatisfactionValidityOperation `json:"validity" yaml:"validity"`
	Script            string                            `json:"script" yaml:"script"`
}

func (PathSatisfactionRoute) PropertyReferenceChangesBoundary

func (v PathSatisfactionRoute) PropertyReferenceChangesBoundary() bool

func (*PathSatisfactionRoute) UnmarshalYAML

func (p *PathSatisfactionRoute) UnmarshalYAML(n *yaml.Node) error

type PathSatisfactionValidityOperation

type PathSatisfactionValidityOperation string
const (
	DownstreamOperation PathSatisfactionValidityOperation = "downstream"
)

type Properties

type Properties map[string]Property

Properties is a map of properties

func (*Properties) Clone

func (p *Properties) Clone() Properties

type Property

type Property interface {
	// SetProperty sets the value of the property on the resource
	SetProperty(resource *construct.Resource, value any) error
	// AppendProperty appends the value to the property on the resource
	AppendProperty(resource *construct.Resource, value any) error
	// RemoveProperty removes the value from the property on the resource
	RemoveProperty(resource *construct.Resource, value any) error
	// Details returns the property details for the property
	Details() *PropertyDetails
	// Clone returns a clone of the property
	Clone() Property
	// Type returns the string representation of the type of the property, as it should appear in the resource template
	Type() string
	// GetDefaultValue returns the default value for the property,
	// pertaining to the specific data being passed in for execution
	GetDefaultValue(ctx DynamicContext, data DynamicValueData) (any, error)
	// Validate ensures the value is valid for the property to `Set` (not `Append` for collection types)
	// and returns an error if it is not
	Validate(resource *construct.Resource, value any, ctx DynamicContext) error
	// SubProperties returns the sub properties of the property, if any.
	// This is used for properties that are complex structures, such as lists, sets, or maps
	SubProperties() Properties
	// Parse parses a given value to ensure it is the correct type for the property.
	// If the given value cannot be converted to the respective property type an error is returned.
	// The returned value will always be the correct type for the property
	Parse(value any, ctx DynamicContext, data DynamicValueData) (any, error)
	// ZeroValue returns the zero value for the property type
	ZeroValue() any
	// Contains returns true if the value contains the given value
	Contains(value any, contains any) bool
}

Property is an interface used to define a property that exists on a resource Properties are used to define the structure of a resource and how it is configured Each property implementation refers to a specific type of property, such as a string or a list, etc

type PropertyDetails

type PropertyDetails struct {
	Name string `json:"name" yaml:"name"`
	// DefaultValue has to be any because it may be a template and it may be a value of the correct type
	Namespace bool `yaml:"namespace"`
	// Required defines if the property is required
	Required bool `json:"required" yaml:"required"`
	// ConfigurationDisabled defines if the property is allowed to be configured by the user
	ConfigurationDisabled bool `json:"configuration_disabled" yaml:"configuration_disabled"`
	// DeployTime defines if the property is only available at deploy time
	DeployTime bool `json:"deploy_time" yaml:"deploy_time"`
	// OperationalRule defines a rule that is executed at runtime to determine the value of the property
	OperationalRule *PropertyRule `json:"operational_rule" yaml:"operational_rule"`
	// Description is a description of the property. This is not used in the engine solving,
	// but is metadata returned by the `ListResourceTypes` CLI command.
	Description string `json:"description" yaml:"description"`
	// Path is the path to the property in the resource
	Path string `json:"-" yaml:"-"`

	// IsImportant is a flag to denote what properties are subjectively important to show in the InfracopilotUI via
	// the `ListResourceTypes` CLI command. This field is not & should not be used in the engine.
	IsImportant bool
}

PropertyDetails defines the common details of a property

type PropertyRule

type PropertyRule struct {
	If    string          `json:"if" yaml:"if"`
	Step  OperationalStep `json:"step" yaml:"step"`
	Value any             `json:"value" yaml:"value"`
}

type ResourceSelector

type ResourceSelector struct {
	Selector   string         `json:"selector" yaml:"selector"`
	Properties map[string]any `json:"properties" yaml:"properties"`
	// NumPreferred defines the amount of resources that should be preferred to satisfy the selector.
	// This number is only used if num needed on the step is not met
	NumPreferred int `json:"num_preferred" yaml:"num_preferred"`
	// Classifications defines the classifications that the rule should be enforced on. Classifications must be specified if resource types is not specified
	Classifications []string `json:"classifications" yaml:"classifications"`
}

func (ResourceSelector) CanUse

CanUse checks if the `res` can be used to satisfy the resource selector. This differs from [IsMatch] because it will also consider unset properties to be able to be used. This is primarily used for when empty resources are created during path expansion, other resources' selectors can be used to configure those empty resources.

func (ResourceSelector) ExtractResourceIds

func (p ResourceSelector) ExtractResourceIds(ctx DynamicValueContext, data DynamicValueData) (ids construct.ResourceList, errs error)

func (ResourceSelector) IsMatch

IsMatch checks if the resource selector is a match for the given resource

func (*ResourceSelector) UnmarshalYAML

func (p *ResourceSelector) UnmarshalYAML(n *yaml.Node) error

type ResourceTemplate

type ResourceTemplate struct {
	// QualifiedTypeName is the qualified type name of the resource
	QualifiedTypeName string `json:"qualified_type_name" yaml:"qualified_type_name"`

	// DisplayName is the common name that refers to the resource
	DisplayName string `json:"display_name" yaml:"display_name"`

	// Properties defines the properties that the resource has
	Properties Properties `json:"properties" yaml:"properties"`

	AdditionalRules []AdditionalRule `json:"additional_rules" yaml:"additional_rules"`

	// Classification defines the classification of the resource
	Classification Classification `json:"classification" yaml:"classification"`

	// PathSatisfaction defines what paths must exist for the resource must be connected to and from
	PathSatisfaction PathSatisfaction `json:"path_satisfaction" yaml:"path_satisfaction"`

	// Consumption defines properties the resource may emit or consume from other resources it is connected to or expanded from
	Consumption Consumption `json:"consumption" yaml:"consumption"`

	// DeleteContext defines the context in which a resource can be deleted
	DeleteContext DeleteContext `json:"delete_context" yaml:"delete_context"`
	// Views defines the views that the resource should be added to as a distinct node
	Views map[string]string `json:"views" yaml:"views"`

	// NoIac defines if the resource should be ignored by the IaC engine
	NoIac bool `json:"no_iac" yaml:"no_iac"`

	// DeploymentPermissions defines the permissions that are required to deploy and tear down the resource
	DeploymentPermissions DeploymentPermissions `json:"deployment_permissions" yaml:"deployment_permissions"`

	// SanitizeNameTmpl defines a template that is used to sanitize the name of the resource
	SanitizeNameTmpl *SanitizeTmpl `yaml:"sanitize_name"`
}

ResourceTemplate defines how rules are handled by the engine in terms of making sure they are functional in the graph

func (ResourceTemplate) GetFunctionality

func (template ResourceTemplate) GetFunctionality() Functionality

func (ResourceTemplate) GetNamespacedProperty

func (template ResourceTemplate) GetNamespacedProperty() Property

func (ResourceTemplate) GetProperty

func (template ResourceTemplate) GetProperty(path string) Property

func (ResourceTemplate) GivesAttributeForFunctionality

func (template ResourceTemplate) GivesAttributeForFunctionality(attribute string, functionality Functionality) bool

func (ResourceTemplate) Id

func (template ResourceTemplate) Id() construct.ResourceId

func (ResourceTemplate) LoopProperties

func (tmpl ResourceTemplate) LoopProperties(res *construct.Resource, addProp func(Property) error) error

func (ResourceTemplate) ResourceContainsClassifications

func (template ResourceTemplate) ResourceContainsClassifications(needs []string) bool

func (ResourceTemplate) SanitizeName

func (rt ResourceTemplate) SanitizeName(name string) (string, error)

type SanitizeError

type SanitizeError struct {
	Input     any
	Sanitized any
}

SanitizeError is returned when a value is sanitized if the input is not valid. The Sanitized field is always the same type as the Input field.

func (SanitizeError) Error

func (err SanitizeError) Error() string

type SanitizeTmpl

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

func NewSanitizationTmpl

func NewSanitizationTmpl(name string, tmpl string) (*SanitizeTmpl, error)

func (SanitizeTmpl) Check

func (t SanitizeTmpl) Check(value string) error

func (SanitizeTmpl) Execute

func (t SanitizeTmpl) Execute(value string) (string, error)

type SelectionOperator

type SelectionOperator string

type TemplateKB

type TemplateKB interface {
	ListResources() []*ResourceTemplate
	GetModel(model string) *Model
	Edges() ([]graph.Edge[*ResourceTemplate], error)
	AddResourceTemplate(template *ResourceTemplate) error
	AddEdgeTemplate(template *EdgeTemplate) error
	GetResourceTemplate(id construct.ResourceId) (*ResourceTemplate, error)
	GetEdgeTemplate(from, to construct.ResourceId) *EdgeTemplate
	HasDirectPath(from, to construct.ResourceId) bool
	HasFunctionalPath(from, to construct.ResourceId) bool
	AllPaths(from, to construct.ResourceId) ([][]*ResourceTemplate, error)
	GetAllowedNamespacedResourceIds(ctx DynamicValueContext, resourceId construct.ResourceId) ([]construct.ResourceId, error)
	GetClassification(id construct.ResourceId) Classification
	GetResourcesNamespaceResource(resource *construct.Resource) (construct.ResourceId, error)
	GetResourcePropertyType(resource construct.ResourceId, propertyName string) string
	GetPathSatisfactionsFromEdge(source, target construct.ResourceId) ([]EdgePathSatisfaction, error)
}

type Unique

type Unique struct {
	// Source indicates whether the source must only have a single edge of this type.
	Source bool `yaml:"source"`
	// Target indicates whether the target must only have a single edge of this type.
	Target bool `yaml:"target"`
}

Unique is used to specify whether the source or target of an edge must only have a single edge of this type

  • Source=false & Target=false (default) indicates that S->T is a many-to-many relationship (for examples, Lambda -> DynamoDB)
  • Source=true & Target=false indicates that S->T is a one-to-many relationship (for examples, SQS -> Event Source Mapping)
  • Source=false & Target=true indicates that S->T is a many-to-one relationship (for examples, Event Source Mapping -> Lambda)
  • Source=true & Target=true indicates that S->T is a one-to-one relationship (for examples, RDS Proxy -> Proxy Target Group)

func (Unique) CanAdd

func (u Unique) CanAdd(edges []construct.Edge, source, target construct.ResourceId) bool

CanAdd returns whether the edge source -> target can be added based on the uniqueness rules. - "many-to-many" always returns true - "one-to-many" returns true if the target does not have any edges that match the source type - "many-to-one" returns true if the source does not have any edges that match the target type - "one-to-one" returns true if neither the source nor the target have any edges that match the other type

func (*Unique) UnmarshalYAML

func (u *Unique) UnmarshalYAML(n *yaml.Node) error

type ValueOrTemplate

type ValueOrTemplate struct {
	Value    any
	Template *template.Template
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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