graph

package
v1.4.4 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package graph provides functionality to build a graph of connected nodes with a cfn.Template

Example (Get)
package main

import (
	"fmt"

	"github.com/aws-cloudformation/rain/cft/graph"
)

var g graph.Graph

func main() {
	fmt.Println(g.Get(graph.Node{"Parameters", "Name"}))
	fmt.Println(g.Get(graph.Node{"Resources", "Bucket"}))
	fmt.Println(g.Get(graph.Node{"Outputs", "BucketName"}))
}
Output:

[]
[Parameters/AWS::AccountId Parameters/Name]
[Resources/Bucket]
Example (GetReverse)
package main

import (
	"fmt"

	"github.com/aws-cloudformation/rain/cft/graph"
)

var g graph.Graph

func main() {
	fmt.Println(g.GetReverse(graph.Node{"Parameters", "Name"}))
	fmt.Println(g.GetReverse(graph.Node{"Resources", "Bucket"}))
	fmt.Println(g.GetReverse(graph.Node{"Outputs", "BucketName"}))
}
Output:

[Resources/Bucket]
[Outputs/BucketArn Outputs/BucketName]
[]
Example (Nodes)
package main

import (
	"fmt"

	"github.com/aws-cloudformation/rain/cft/graph"
)

var g graph.Graph

func main() {
	for _, node := range g.Nodes() {
		fmt.Println(node)
	}
}
Output:

Parameters/AWS::AccountId
Parameters/Name
Resources/Bucket
Outputs/BucketArn
Outputs/BucketName

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Graph

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

Graph represents a directed, acyclic graph with ordered nodes

func New

func New(t cft.Template) Graph

New returns a Graph representing the connections between elements in the provided template. The type of each item in the graph is Node

func (Graph) Get

func (g Graph) Get(item Node) []Node

Get returns all nodes that are connected to the item that you pass in.

func (Graph) GetReverse

func (g Graph) GetReverse(item Node) []Node

GetReverse returns all nodes that connect to the item that you pass in.

func (Graph) Nodes

func (g Graph) Nodes() []Node

Nodes returns all nodes of the graph, in order of their dependencies. Nodes with the fewest dependencies are at the beginning of the slice.

func (*Graph) String

func (g *Graph) String() string

type Node

type Node struct {
	// Type is the name of the top-level part of a template
	// that contains this Node (e.g. Resources, Parameters)
	Type string

	// Name is the name of the Node
	Name string
}

Node represents a top-level entry in a CloudFormation template for example a resource, parameter, or output

func (Node) String

func (n Node) String() string

Jump to

Keyboard shortcuts

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