construct

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SkipProperty = fmt.Errorf("skip property")
View Source
var StopWalk = errors.New("stop walking")

StopWalk is a special error that can be returned from WalkGraphFunc to stop walking the graph. The resulting error from WalkGraph will be whatever was previously passed into the walk function.

Functions

func CopyEdgeProps

func CopyEdgeProps(p graph.EdgeProperties) func(*graph.EdgeProperties)

func CopyVertexProps

func CopyVertexProps(p graph.VertexProperties) func(*graph.VertexProperties)

func DontSkipEdges

func DontSkipEdges(_ Edge) bool

func GraphToDOT

func GraphToDOT(g Graph, out io.Writer) error

func GraphToSVG

func GraphToSVG(g Graph, prefix string) error

func Hash

func Hash(g Graph) ([]byte, error)

func Neighbors

func Neighbors(g Graph, r ResourceId) (upstream, downstream set.Set[ResourceId], err error)

func PropagateUpdatedId

func PropagateUpdatedId(g Graph, old ResourceId) error

UpdateResourceId is used when a resource's ID changes. It updates the graph in-place, using the resource currently referenced by `old`. No-op if the resource ID hasn't changed. Also updates any property references (as ResourceId or PropertyRef) of the old ID to the new ID in any resource that depends on or is depended on by the resource.

func RemoveResource

func RemoveResource(g Graph, id ResourceId) error

RemoveResource removes all edges from the resource. any property references (as ResourceId or PropertyRef) to the resource, and finally the resource itself.

func ReplaceResource

func ReplaceResource(g Graph, oldId ResourceId, newRes *Resource) error

ReplaceResource replaces the resources identified by `oldId` with `newRes` in the graph and in any property references (as ResourceId or PropertyRef) of the old ID to the new ID in any resource that depends on or is depended on by the resource.

func ResourceIdLess

func ResourceIdLess(a, b ResourceId) bool

func String

func String(g Graph) (string, error)

func WalkGraph

func WalkGraph(g Graph, fn WalkGraphFunc) error

func WalkGraphReverse

func WalkGraphReverse(g Graph, fn WalkGraphFunc) error

Types

type Dependencies

type Dependencies struct {
	Resource ResourceId
	Paths    []Path
	All      set.Set[ResourceId]
}

func DownstreamDependencies

func DownstreamDependencies(g Graph, start ResourceId, skipEdge func(Edge) bool) (*Dependencies, error)

func UpstreamDependencies

func UpstreamDependencies(g Graph, start ResourceId, skipEdge func(Edge) bool) (*Dependencies, error)

func (*Dependencies) Add

func (d *Dependencies) Add(p Path)

type Edge

type Edge = graph.Edge[ResourceId]

func ResourceEdgeToKeyEdge

func ResourceEdgeToKeyEdge(re ResourceEdge) Edge

type EdgeData

type EdgeData struct {
	ConnectionType string `yaml:"connection_type,omitempty" json:"connection_type,omitempty"`
}

func (EdgeData) Equals

func (ed EdgeData) Equals(other any) bool

Equals implements an interface used in graph_addons.MemoryStore to determine whether edges are equal to allow for idempotent edge addition.

type Graph

type Graph = graph.Graph[ResourceId, *Resource]

func NewAcyclicGraph

func NewAcyclicGraph(options ...func(*graph.Traits)) Graph

func NewGraph

func NewGraph(options ...func(*graph.Traits)) Graph

func NewGraphWithOptions

func NewGraphWithOptions(options ...func(*graph.Traits)) Graph

type GraphBatch

type GraphBatch struct {
	Graph
	Err error
	// contains filtered or unexported fields
}

GraphBatch can be used to batch adding vertices and edges to the graph, collecting errors in the [Err] field.

func NewGraphBatch

func NewGraphBatch(g Graph) *GraphBatch

func (*GraphBatch) AddEdges

func (b *GraphBatch) AddEdges(es ...Edge)

func (*GraphBatch) AddVertices

func (b *GraphBatch) AddVertices(rs ...*Resource)

type IdResolutionError

type IdResolutionError map[ResourceId]error

func (IdResolutionError) Error

func (e IdResolutionError) Error() string

type Output

type Output struct {
	Ref   PropertyRef `json:"ref,omitempty" yaml:"ref,omitempty"`
	Value any         `json:"value,omitempty" yaml:"value,omitempty"`
}

type Path

func (Path) Contains

func (p Path) Contains(id ResourceId) bool

func (Path) MarshalText

func (p Path) MarshalText() ([]byte, error)

func (*Path) Parse

func (p *Path) Parse(s string) error

func (Path) String

func (p Path) String() string

func (*Path) UnmarshalText

func (p *Path) UnmarshalText(text []byte) error

func (*Path) Validate

func (p *Path) Validate() error

type Properties

type Properties map[string]any

func (Properties) Equals

func (p Properties) Equals(other any) (equal bool)

func (Properties) MarshalYAML

func (p Properties) MarshalYAML() (interface{}, error)

func (Properties) PropertyPath

func (p Properties) PropertyPath(pathStr string) (PropertyPath, error)

PropertyPath interprets a string path to index (potentially deeply) into [Resource.Properties] which can be used to get, set, append, or remove values.

func (Properties) WalkProperties

func (p Properties) WalkProperties(fn WalkPropertiesFunc) error

WalkProperties walks the properties of the resource, calling fn for each property. If fn returns SkipProperty, the property and its decendants (if a map or array type) is skipped. If fn returns StopWalk, the walk is stopped. NOTE: does not walk over the _keys_ of any maps, only values.

type PropertyKVItem

type PropertyKVItem interface {
	Key() PropertyPathItem
}

type PropertyPath

type PropertyPath []PropertyPathItem

PropertyPath represents a path into a resource's properties. See Resource.PropertyPath for more information.

func (PropertyPath) Append

func (i PropertyPath) Append(value any) error

Append appends a value to the item. Only supported on array items.

func (PropertyPath) Get

func (i PropertyPath) Get() any

Get returns the value at this path item.

func (PropertyPath) Last

func (i PropertyPath) Last() PropertyPathItem

func (PropertyPath) Parts

func (i PropertyPath) Parts() []string

func (PropertyPath) Remove

func (i PropertyPath) Remove(value any) error

Remove removes the value at this path item. If value is nil, it is interpreted to remove the item itself. Non-nil value'd remove is only supported on array items, to remove a value from the array.

func (PropertyPath) Set

func (i PropertyPath) Set(value any) error

Set sets the value at this path item.

func (PropertyPath) String

func (i PropertyPath) String() string

type PropertyPathError

type PropertyPathError struct {
	Path  []string
	Cause error
}

func (PropertyPathError) Error

func (e PropertyPathError) Error() string

func (PropertyPathError) Unwrap

func (e PropertyPathError) Unwrap() error

type PropertyPathItem

type PropertyPathItem interface {
	Get() any
	Set(value any) error
	Remove(value any) error
	Append(value any) error
	// contains filtered or unexported methods
}

type PropertyRef

type PropertyRef struct {
	Resource ResourceId
	Property string
}

func (*PropertyRef) Equals

func (v *PropertyRef) Equals(ref interface{}) bool

func (*PropertyRef) IsZero

func (v *PropertyRef) IsZero() bool

func (PropertyRef) MarshalText

func (v PropertyRef) MarshalText() ([]byte, error)

func (*PropertyRef) Parse

func (v *PropertyRef) Parse(s string) error

func (PropertyRef) String

func (v PropertyRef) String() string

func (*PropertyRef) UnmarshalText

func (v *PropertyRef) UnmarshalText(b []byte) error

func (*PropertyRef) Validate

func (v *PropertyRef) Validate() error

type Resource

type Resource struct {
	ID         ResourceId
	Properties Properties
	Imported   bool
}

func ResolveIds

func ResolveIds(g Graph, ids []ResourceId) ([]*Resource, error)

func (*Resource) AppendProperty

func (r *Resource) AppendProperty(pathStr string, value any) error

AppendProperty is a wrapper around PropertyPath.Append for convenience.

func (Resource) Equals

func (r Resource) Equals(other any) bool

func (*Resource) GetProperty

func (r *Resource) GetProperty(pathStr string) (any, error)

GetProperty is a wrapper around PropertyPath.Get for convenience.

func (*Resource) PropertyPath

func (r *Resource) PropertyPath(pathStr string) (PropertyPath, error)

func (*Resource) RemoveProperty

func (r *Resource) RemoveProperty(pathStr string, value any) error

RemoveProperty is a wrapper around PropertyPath.Remove for convenience.

func (*Resource) SetProperty

func (r *Resource) SetProperty(pathStr string, value any) error

SetProperty is a wrapper around PropertyPath.Set for convenience.

func (*Resource) WalkProperties

func (r *Resource) WalkProperties(fn WalkPropertiesFunc) error

type ResourceEdge

type ResourceEdge = graph.Edge[*Resource]

type ResourceId

type ResourceId struct {
	Provider string `yaml:"provider" toml:"provider"`
	Type     string `yaml:"type" toml:"type"`
	// Namespace is optional and is used to disambiguate resources that might have
	// the same name. It can also be used to associate an imported resource with
	// a specific namespace such as a subnet to a VPC.
	Namespace string `yaml:"namespace" toml:"namespace"`
	Name      string `yaml:"name" toml:"name"`
}

func AllDownstreamDependencies

func AllDownstreamDependencies(g Graph, r ResourceId) ([]ResourceId, error)

AllDownstreamDependencies returns all downstream dependencies of the given resource. Downstream means that for A -> B -> C -> D the downstream dependencies of B are [C, D].

func AllUpstreamDependencies

func AllUpstreamDependencies(g Graph, r ResourceId) ([]ResourceId, error)

AllUpstreamDependencies returns all upstream dependencies of the given resource. Upstream means that for A -> B -> C -> D the upstream dependencies of C are [B, A] (in that order).

func DirectDownstreamDependencies

func DirectDownstreamDependencies(g Graph, r ResourceId) ([]ResourceId, error)

DirectDownstreamDependencies returns the direct downstream dependencies of the given resource. Direct means that for A -> B -> C -> D the direct downstream dependencies of B are [C].

func DirectUpstreamDependencies

func DirectUpstreamDependencies(g Graph, r ResourceId) ([]ResourceId, error)

DirectUpstreamDependencies returns the direct upstream dependencies of the given resource. Direct means that for A -> B -> C -> D the direct upstream dependencies of C are [B].

func ResourceHasher

func ResourceHasher(r *Resource) ResourceId

func ReverseTopologicalSort

func ReverseTopologicalSort[T any](g graph.Graph[ResourceId, T]) ([]ResourceId, error)

ReverseTopologicalSort is like TopologicalSort, but returns the reverse order. This is primarily useful for IaC graphs to determine the order in which resources should be created.

func SelectIds

func SelectIds(ids []ResourceId, selector ResourceId) []ResourceId

func TopologicalSort

func TopologicalSort[T any](g graph.Graph[ResourceId, T]) ([]ResourceId, error)

TopologicalSort provides a stable topological ordering of resource IDs. This is a modified implementation of graph.StableTopologicalSort with the primary difference being any uses of the internal function `enqueueArbitrary`.

func (ResourceId) IsAbstractResource

func (id ResourceId) IsAbstractResource() bool

IsAbstractResource returns true if the resource is an abstract resource

func (ResourceId) IsZero

func (id ResourceId) IsZero() bool

func (ResourceId) MarshalTOML

func (id ResourceId) MarshalTOML() ([]byte, error)

func (ResourceId) MarshalText

func (id ResourceId) MarshalText() ([]byte, error)

func (ResourceId) Matches

func (id ResourceId) Matches(other ResourceId) bool

Matches uses `id` (the receiver) as a filter for `other` (the argument) and returns true if all the non-empty fields from `id` match the corresponding fields in `other`.

func (*ResourceId) Parse

func (id *ResourceId) Parse(s string) error

func (ResourceId) QualifiedTypeName

func (id ResourceId) QualifiedTypeName() string

func (ResourceId) String

func (id ResourceId) String() string

func (*ResourceId) UnmarshalTOML

func (id *ResourceId) UnmarshalTOML(data []byte) error

func (*ResourceId) UnmarshalText

func (id *ResourceId) UnmarshalText(data []byte) error

func (*ResourceId) Validate

func (id *ResourceId) Validate() error

type ResourceIdChangeResults

type ResourceIdChangeResults map[ResourceId]ResourceId

ResourceIdChangeResults is a map of old ResourceIds to new ResourceIds

func (*ResourceIdChangeResults) Merge

func (ResourceIdChangeResults) RemoveNoop

func (m ResourceIdChangeResults) RemoveNoop()

type ResourceList

type ResourceList []ResourceId

func (ResourceList) MatchesAny

func (l ResourceList) MatchesAny(id ResourceId) bool

func (ResourceList) String

func (l ResourceList) String() string

func (*ResourceList) UnmarshalText

func (l *ResourceList) UnmarshalText(b []byte) error

type ShortestPather

type ShortestPather interface {
	ShortestPath(target ResourceId) (Path, error)
}

func ShortestPaths

func ShortestPaths(
	g Graph,
	source ResourceId,
	skipEdge func(Edge) bool,
) (ShortestPather, error)

type SimpleEdge

type SimpleEdge struct {
	Source ResourceId
	Target ResourceId
}

func EdgeKeys

func EdgeKeys[V any](m map[SimpleEdge]V) []SimpleEdge

func ToSimpleEdge

func ToSimpleEdge(e Edge) SimpleEdge

func (SimpleEdge) Less

func (e SimpleEdge) Less(other SimpleEdge) bool

func (SimpleEdge) MarshalText

func (e SimpleEdge) MarshalText() (string, error)

func (*SimpleEdge) Parse

func (e *SimpleEdge) Parse(s string) error

func (SimpleEdge) String

func (e SimpleEdge) String() string

func (SimpleEdge) ToEdge

func (e SimpleEdge) ToEdge() Edge

func (*SimpleEdge) UnmarshalText

func (e *SimpleEdge) UnmarshalText(data []byte) error

func (*SimpleEdge) Validate

func (e *SimpleEdge) Validate() error

type SortedIds

type SortedIds []ResourceId

SortedIds is a helper type for sorting ResourceIds by purely their content, for use when deterministic ordering is desired (when no other sources of ordering are available).

func (SortedIds) Len

func (s SortedIds) Len() int

func (SortedIds) Less

func (s SortedIds) Less(i, j int) bool

func (SortedIds) Swap

func (s SortedIds) Swap(i, j int)

type WalkGraphFunc

type WalkGraphFunc func(id ResourceId, resource *Resource, nerr error) error

WalkGraphFunc is much like `fs.WalkDirFunc` and is used in `WalkGraph` and `WalkGraphReverse` for the callback during graph traversal. Return `StopWalk` to end the walk.

type WalkPropertiesFunc

type WalkPropertiesFunc func(path PropertyPath, err error) error

type YamlGraph

type YamlGraph struct {
	Graph   Graph
	Outputs map[string]Output
}

func (YamlGraph) MarshalYAML

func (g YamlGraph) MarshalYAML() (interface{}, error)

func (*YamlGraph) UnmarshalYAML

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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