attribute_path

package
v1.4.3 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2023 License: MPL-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Matcher

type Matcher interface {
	// Matches returns true if we have reached the end of a path and found an
	// exact match.
	Matches() bool

	// MatchesPartial returns true if the current attribute is part of a path
	// but not necessarily at the end of the path.
	MatchesPartial() bool

	GetChildWithKey(key string) Matcher
	GetChildWithIndex(index int) Matcher
}

Matcher provides an interface for stepping through changes following an attribute path.

GetChildWithKey and GetChildWithIndex will check if any of the internal paths match the provided key or index, and return a new Matcher that will match that children or potentially it's children.

The caller of the above functions is required to know whether the next value in the path is a list type or an object type and call the relevant function, otherwise these functions will crash/panic.

The Matches function returns true if the paths you have traversed until now ends.

func AlwaysMatcher

func AlwaysMatcher() Matcher

AlwaysMatcher returns a matcher that will always match all paths.

func Parse

func Parse(message json.RawMessage, propagate bool) Matcher

Parse accepts a json.RawMessage and outputs a formatted Matcher object.

Parse expects the message to be a JSON array of JSON arrays containing strings and floats. This function happily accepts a null input representing none of the changes in this resource are causing a replacement. The propagate argument tells the matcher to propagate any matches to the matched attributes children.

In general, this function is designed to accept messages that have been produced by the lossy cty.Paths conversion functions within the jsonplan package. There is nothing particularly special about that conversion process though, it just produces the nested JSON arrays described above.

type PathMatcher

type PathMatcher struct {
	// We represent our internal paths as a [][]interface{} as the cty.Paths
	// conversion process is lossy. Since the type information is lost there
	// is no (easy) way to reproduce the original cty.Paths object. Instead,
	// we simply rely on the external callers to know the type information and
	// call the correct GetChild function.
	Paths [][]interface{}

	// Propagate tells the matcher that it should propagate any matches it finds
	// onto the children of that match.
	Propagate bool
}

PathMatcher contains a slice of paths that represent paths through the values to relevant/tracked attributes.

func Append

func Append(matcher *PathMatcher, message json.RawMessage) *PathMatcher

Append accepts an existing PathMatcher and returns a new one that attaches all the paths from message with the existing paths.

The new PathMatcher is created fresh, and the existing one is unchanged.

func AppendSingle

func AppendSingle(matcher *PathMatcher, message json.RawMessage) *PathMatcher

AppendSingle accepts an existing PathMatcher and returns a new one that attaches the single path from message with the existing paths.

The new PathMatcher is created fresh, and the existing one is unchanged.

func Empty

func Empty(propagate bool) *PathMatcher

Empty returns an empty PathMatcher that will by default match nothing.

We give direct access to the PathMatcher struct so a matcher can be built in parts with the Append and AppendSingle functions.

func (*PathMatcher) GetChildWithIndex

func (p *PathMatcher) GetChildWithIndex(index int) Matcher

func (*PathMatcher) GetChildWithKey

func (p *PathMatcher) GetChildWithKey(key string) Matcher

func (*PathMatcher) Matches

func (p *PathMatcher) Matches() bool

func (*PathMatcher) MatchesPartial

func (p *PathMatcher) MatchesPartial() bool

Jump to

Keyboard shortcuts

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