attributepath

package
v0.27.2 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2024 License: MPL-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package attributepath provides a way to match paths for replace and sensitive attributes

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, error)
}

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(paths []interface{}, propagate bool) (Matcher, error)

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 tjson 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, error)

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, messages []json.RawMessage) (*PathMatcher, error)

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, error)

GetChildWithIndex returns a new matcher with the child index if it's found

func (*PathMatcher) GetChildWithKey

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

GetChildWithKey returns a new matcher with the child key if it's found

func (*PathMatcher) Matches

func (p *PathMatcher) Matches() bool

Matches returns true if there is a match

func (*PathMatcher) MatchesPartial

func (p *PathMatcher) MatchesPartial() bool

MatchesPartial returns true if there is a partial match

Jump to

Keyboard shortcuts

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