Documentation
¶
Overview ¶
yamlkit is a package for parsing, traversing, and updating lists of configuration elements, called resources, represented as yaml doc lists.
Index ¶
- Constants
- Variables
- func AttributeDetailsEqual(details1, details2 *api.AttributeDetails, compareFunctions bool) bool
- func ComputeMutations(previousParsedData, modifiedParsedData gaby.Container, functionIndex int64, ...) (api.ResourceMutationList, error)
- func ComputeMutationsForDocs(rootPath string, previousDoc *gaby.YamlDoc, modifiedDoc *gaby.YamlDoc, ...)
- func DeletePaths(parsedData gaby.Container, ...) error
- func DiffPatch(original, modified, targetData []byte, resourceProvider ResourceProvider) ([]byte, bool, error)
- func DiffPatchWithOptions(original, modified, targetData []byte, resourceProvider ResourceProvider, ...) ([]byte, bool, error)
- func EscapeDotsInPathSegment(segment string) string
- func EvalYQExpression(expr string, yamlString string) (string, error)
- func FindYAMLPathsByValue(parsedData gaby.Container, resourceProvider ResourceProvider, searchValue any) api.AttributeValueList
- func FunctionInvocationsEqual(fi1, fi2 *api.FunctionInvocation) bool
- func GetNeededPaths[T api.Scalar](parsedData gaby.Container, ...) (api.AttributeValueList, error)
- func GetNeededStringPaths(parsedData gaby.Container, ...) (api.AttributeValueList, error)
- func GetPathRegistryForAttributeName(resourceProvider ResourceProvider, attributeName api.AttributeName) api.ResourceTypeToPathToVisitorInfoType
- func GetPathVisitorInfo(resourceProvider ResourceProvider, resourceType api.ResourceType, ...) *api.PathVisitorInfo
- func GetPaths[T api.Scalar](parsedData gaby.Container, ...) (api.AttributeValueList, error)
- func GetPathsAnyType(parsedData gaby.Container, ...) (api.AttributeValueList, error)
- func GetRegisteredNeededStringPaths(parsedData gaby.Container, resourceProvider ResourceProvider) (api.AttributeValueList, error)
- func GetRegisteredProvidedStringPaths(parsedData gaby.Container, resourceProvider ResourceProvider) (api.AttributeValueList, error)
- func GetResourceCategoryTypeName(doc *gaby.YamlDoc, resourceProvider ResourceProvider) (api.ResourceCategory, api.ResourceType, api.ResourceName, error)
- func GetResourceInfo(doc *gaby.YamlDoc, resourceProvider ResourceProvider) (*api.ResourceInfo, error)
- func GetStringPaths(parsedData gaby.Container, ...) (api.AttributeValueList, error)
- func IsNumber(s string) bool
- func IsNumeric(c rune) bool
- func JoinPathSegments(segments []string) string
- func LowerFirst(s string) string
- func PatchMutations(parsedData gaby.Container, ...) (gaby.Container, error)
- func PathIsResolved(path string, includeAt bool) bool
- func RegisterNeededPaths(resourceProvider ResourceProvider, resourceType api.ResourceType, ...)
- func RegisterPathsByAttributeName(resourceProvider ResourceProvider, attributeName api.AttributeName, ...)
- func RegisterProvidedPaths(resourceProvider ResourceProvider, resourceType api.ResourceType, ...)
- func Reset(parsedData gaby.Container, mutationsPredicates api.ResourceMutationList, ...) error
- func ResourceAndCategoryTypeMaps(parsedData gaby.Container, resourceProvider ResourceProvider) (resourceMap ResourceNameToCategoryTypesMap, ...)
- func ResourceTypesForAttribute(attributeName api.AttributeName, resourceProvider ResourceProvider) []api.ResourceType
- func ResourceTypesForPathMap(pathMap map[api.ResourceType][]string) []api.ResourceType
- func StripComments(yamlData []byte) ([]byte, error)
- func UpdatePathsFunction[T api.Scalar](parsedData gaby.Container, ...) error
- func UpdatePathsFunctionDoc(parsedData gaby.Container, ...) error
- func UpdatePathsValue[T api.Scalar](parsedData gaby.Container, ...) error
- func UpdateStringPaths(parsedData gaby.Container, ...) error
- func UpdateStringPathsFunction(parsedData gaby.Container, ...) error
- func VisitPaths[T api.Scalar](parsedData gaby.Container, ...) (any, error)
- func VisitPathsAnyType(parsedData gaby.Container, ...) (any, error)
- func VisitPathsDoc(parsedData gaby.Container, ...) (any, error)
- func VisitResources(parsedData gaby.Container, output any, resourceProvider ResourceProvider, ...) (any, error)
- func VisitorInfoEqual(pathVisitorInfo1, pathVisitorInfo2 *api.PathVisitorInfo, compareFunctions bool) bool
- func YamlSafePathGetDoc(doc *gaby.YamlDoc, resolvedPath api.ResolvedPath, notFoundOk bool) (*gaby.YamlDoc, bool, error)
- func YamlSafePathGetValue[T api.Scalar](doc *gaby.YamlDoc, resolvedPath api.ResolvedPath, notFoundOk bool) (T, bool, error)
- func YamlSafePathGetValueAnyType(doc *gaby.YamlDoc, resolvedPath api.ResolvedPath, notFoundOk bool) (any, bool, error)
- type EmbeddedAccessor
- type RegexpAccessor
- func (ra *RegexpAccessor) Data(scalarYamlDoc *gaby.YamlDoc, path string) (any, error)
- func (ra *RegexpAccessor) ExistsP(scalarYamlDoc *gaby.YamlDoc, path string) bool
- func (ra *RegexpAccessor) Extract(currentFieldValue, path string) (any, error)
- func (ra *RegexpAccessor) Replace(currentFieldValue string, value any, path string) (string, error)
- func (ra *RegexpAccessor) SetP(scalarYamlDoc *gaby.YamlDoc, value any, path string) error
- type ResolvedPathInfo
- type ResourceCategoryTypeToNamesMap
- type ResourceInfoToDocMap
- type ResourceNameToCategoryTypesMap
- type ResourceProvider
- type ResourceTypeToPathPrefixSetType
- type ResourceVisitorFunc
- type VisitorContext
- type VisitorFunc
- type VisitorFuncAnyType
- type VisitorFuncDoc
Constants ¶
const ( PlaceHolderBlockApplyString = "confighubplaceholder" PlaceHolderBlockApplyInt = 999999999 )
PlaceHolderBlockApply We will need placeholders for different data types and that fit with different validation rules The string value is all lowercase to comply with DNS label requirements.
const OriginalNameAnnotation = "confighub.com/OriginalName"
FIXME: Remove this once all existing clones are converted to Aliases/AliasesWithoutScopes.
Variables ¶
var EmbeddedPathNotFound = errors.New("embedded path not found")
var NoSubexpressions = errors.New("no capturing subexpressions")
var UnsupportedAccessorType = errors.New("accessor type not supported")
var UnsupportedValueType = errors.New("only string values supported currently")
Functions ¶
func AttributeDetailsEqual ¶
func AttributeDetailsEqual(details1, details2 *api.AttributeDetails, compareFunctions bool) bool
AttributeDetailsEqual reports whether two sets of attribute details, optionally including getter and setter invocations, match.
func ComputeMutations ¶
func ComputeMutations(previousParsedData, modifiedParsedData gaby.Container, functionIndex int64, resourceProvider ResourceProvider) (api.ResourceMutationList, error)
ComputeMutations performs a kind of diff between two configuration Units where it determines what modifications were made at the resource/element level and at the path level. They are recorded in a way that can be accumulated and updated over subsequent edits and transformations.
func ComputeMutationsForDocs ¶
func ComputeMutationsForDocs(rootPath string, previousDoc *gaby.YamlDoc, modifiedDoc *gaby.YamlDoc, functionIndex int64, pathMutationMap api.MutationMap)
ComputeMutationsForDocs determines the edits that have been performed to transform the previousDoc into modifiedDoc. The resulting mutations are associated with the provided functionIndex. The pathMutationMap is modified in place.
func DeletePaths ¶
func DeletePaths( parsedData gaby.Container, resourceTypeToPaths api.ResourceTypeToPathToVisitorInfoType, keys []any, resourceProvider ResourceProvider, ) error
func DiffPatch ¶
func DiffPatch(original, modified, targetData []byte, resourceProvider ResourceProvider) ([]byte, bool, error)
DiffPatch compares original and modified YAML content, generates a patch, and applies it to target data
func DiffPatchWithOptions ¶
func DiffPatchWithOptions(original, modified, targetData []byte, resourceProvider ResourceProvider, omitAdditions bool) ([]byte, bool, error)
DiffPatchWithOptions compares original and modified YAML content, generates a patch, and applies it to target data If omitAdditions is true, mutations of type MutationTypeAdd are filtered out before applying the patch
func EscapeDotsInPathSegment ¶
EscapeDotsInPathSegment escapes any dots in a path segment for use in whole-path searches because path segments are separated by dots. TODO: Escape more special characters?
func FindYAMLPathsByValue ¶
func FindYAMLPathsByValue(parsedData gaby.Container, resourceProvider ResourceProvider, searchValue any) api.AttributeValueList
FindYAMLPathsByValue searches for all paths that match a specified value in a YAML structure and returns an api.AttributeValueList.
func FunctionInvocationsEqual ¶
func FunctionInvocationsEqual(fi1, fi2 *api.FunctionInvocation) bool
FunctionInvocationsEqual reports whether two function invocations match.
func GetNeededPaths ¶
func GetNeededPaths[T api.Scalar]( parsedData gaby.Container, resourceTypeToPaths api.ResourceTypeToPathToVisitorInfoType, keys []any, resourceProvider ResourceProvider, ) (api.AttributeValueList, error)
GetNeededPaths traverses the specified path patterns of the specified resource types and returns an api.AttributeValueList containing the values and registered information about all of the found attributes matching the path patterns that Need values. Currently "Need" is determined using placeholder values, 999999999 (9 9s) for integers. Use only for ints. Bools have no placeholder value. Use GetNeededStringPaths for strings.
func GetNeededStringPaths ¶
func GetNeededStringPaths( parsedData gaby.Container, resourceTypeToPaths api.ResourceTypeToPathToVisitorInfoType, keys []any, resourceProvider ResourceProvider, ) (api.AttributeValueList, error)
GetNeededStringPaths traverses the specified path patterns of the specified resource types and returns an api.AttributeValueList containing the values and registered information about all of the found string attributes matching the path patterns that Need values. Currently "Need" is determined using placeholder values, "confighubplaceholder" for strings. It can also extract fields embedded in strings using registered embedded accessors.
func GetPathRegistryForAttributeName ¶
func GetPathRegistryForAttributeName( resourceProvider ResourceProvider, attributeName api.AttributeName, ) api.ResourceTypeToPathToVisitorInfoType
GetPathRegistryForAttributeName returns the registry for the specified attribute to pass to a visitor function.
func GetPathVisitorInfo ¶
func GetPathVisitorInfo(resourceProvider ResourceProvider, resourceType api.ResourceType, path api.UnresolvedPath) *api.PathVisitorInfo
GetPathVisitorInfo returns the path visitor specification for the specified path within the specified resource type to pass to a visitor function.
func GetPaths ¶
func GetPaths[T api.Scalar]( parsedData gaby.Container, resourceTypeToPaths api.ResourceTypeToPathToVisitorInfoType, keys []any, resourceProvider ResourceProvider, ) (api.AttributeValueList, error)
GetPaths traverses the specified path patterns of the specified resource types and returns an api.AttributeValueList containing the values and registered information about all of the found attributes matching the path patterns. Use only for int and bool attributes. Use GetStringPaths for string attributes.
func GetPathsAnyType ¶
func GetPathsAnyType( parsedData gaby.Container, resourceTypeToPaths api.ResourceTypeToPathToVisitorInfoType, keys []any, resourceProvider ResourceProvider, dataType api.DataType, neededValuesOnly bool, ) (api.AttributeValueList, error)
GetPathsAnyType traverses the specified path patterns of the specified resource types and returns an api.AttributeValueList containing the values and registered information about all of the found attributes matching the path patterns.
func GetRegisteredNeededStringPaths ¶
func GetRegisteredNeededStringPaths( parsedData gaby.Container, resourceProvider ResourceProvider, ) (api.AttributeValueList, error)
GetRegisteredNeededStringPaths retrieves Needed values specifically registered under api.AttributeNameNeededValue.
func GetRegisteredProvidedStringPaths ¶
func GetRegisteredProvidedStringPaths( parsedData gaby.Container, resourceProvider ResourceProvider, ) (api.AttributeValueList, error)
GetRegisteredProvidedStringPaths retrieves Provided values registered under api.AttributeNameProvidedValue.
func GetResourceCategoryTypeName ¶
func GetResourceCategoryTypeName(doc *gaby.YamlDoc, resourceProvider ResourceProvider) (api.ResourceCategory, api.ResourceType, api.ResourceName, error)
func GetResourceInfo ¶
func GetResourceInfo(doc *gaby.YamlDoc, resourceProvider ResourceProvider) (*api.ResourceInfo, error)
func GetStringPaths ¶
func GetStringPaths( parsedData gaby.Container, resourceTypeToPaths api.ResourceTypeToPathToVisitorInfoType, keys []any, resourceProvider ResourceProvider, ) (api.AttributeValueList, error)
GetStringPaths traverses the specified path patterns of the specified resource types and returns an api.AttributeValueList containing the values and registered information about all of the found string attributes matching the path patterns. It can also extract fields embedded in strings using registered embedded accessors.
func JoinPathSegments ¶
JoinPathSegments escapes any dots in path segments and joins them for use in whole-path searches.
func LowerFirst ¶
LowerFirst lowercases the first character, which is useful for converting PascalCase to camelCase
func PatchMutations ¶
func PatchMutations(parsedData gaby.Container, mutationsPredicates, mutationsPatch api.ResourceMutationList, resourceProvider ResourceProvider) (gaby.Container, error)
PatchMutations applies a set of mutations to configuration data, effectively "replaying" recorded changes onto a YAML document. It's the inverse of ComputeMutations - where ComputeMutations determines what changed, PatchMutations applies those changes.
mutationsPatch is sometimes generated from other configuration units, such as in the canonical case of upgrade from upstream. Or may be generated from past revisions or even live state. So it may not match the provided configuration data in some ways, such as resource names and whole resources. By default all resources and paths are patchable. Predicates are used to preserve existing changes. mutationsPredicates is expected to have been generated from the mutations corresponding to the configuration data being patched. So it is expected to match the contents of parsedData. It is acceptable for mutationsPredicates to be nil.
Algorithm:
1. Process Each Document
For each document in parsedData:
Resource Matching:
- Tries to find matching patch by current resource name
- Falls back to originalName annotation (for cloned resources)
- Falls back to AliasesWithoutScopes from predicates
Predicate Filtering (Resource Level):
- If predicate exists and Predicate == false, skip the entire resource
Resource-Level Mutations:
| MutationType | Action | |------------------|--------------------------------------------------| | Add / Replace | Replace entire document with the mutation's Value| | Delete | Set document to nil (filtered on serialization) | | None | Skip (no changes) | | Update | Process path-level mutations |
2. Path-Level Mutations
For Update mutations, process each path in PathMutationMap:
Sort paths: Process parent paths before children (lexicographic sort)
Predicate filtering: Check path and all parent paths for Predicate == false
Apply by type:
| MutationType | Action | |------------------|-------------------------------------------| | Add / Replace | Set value at path (overwrites) | | Update | Merge value at path (preserves comments) | | Delete | Remove the path from document |
Key Behaviors:
- Alias awareness: Matches resources even when names differ between patch and target
- Predicate filtering: Allows selective application of changes
- Comment preservation: Update mutations try to preserve YAML comments
- Parent-first ordering: Ensures parent paths are applied before children
- Graceful handling: Logs errors but continues processing other mutations
func PathIsResolved ¶
func RegisterNeededPaths ¶
func RegisterNeededPaths( resourceProvider ResourceProvider, resourceType api.ResourceType, pathInfos api.PathToVisitorInfoType, setterFunctionInvocation *api.FunctionInvocation, )
RegisterNeededPaths registers paths in the api.AttributeNameNeededValue path registry. These are paths of attributes that generally need to be set based on values extracted from other resources or configuration Objects, as opposed to values that would be set by default in a configuration object sample, set automatically based on default conventions, set by other registered mutation functions, set by other automated processes, or set imperatively via functions, UI, other tool, or just by editing the configuration data manually.
func RegisterPathsByAttributeName ¶
func RegisterPathsByAttributeName( resourceProvider ResourceProvider, attributeName api.AttributeName, resourceType api.ResourceType, pathInfos api.PathToVisitorInfoType, getterFunctionInvocation *api.FunctionInvocation, setterFunctionInvocation *api.FunctionInvocation, normalizePaths bool, )
RegisterPathsByAttributeName registers the specified path visitor specifications under the designated attribute name and resource type, and adds the provided getter and setter invocations, merging with existing registrations at the same paths, if any. If requested, the registered paths will be normalized so that associative lookups and array indices will be converted to wildcards, which is desired when matching all paths to the attribute. api.AttributeNameGeneral is used for registrations for general attributes of significance. api.AttributeNameNeededValue is used for needed values. api.AttributeNameProvidedValue is used for provided values. AttributeNameResourceName is used for references to resource names. Other attribute names are used for specific setters and/or getters, especially for attributes that appear in multiple resource types and/or locations. Provided values are special in that they represent sources of values for attributes of the specified attribute name, though they are logically distinct kinds of attributes.
func RegisterProvidedPaths ¶
func RegisterProvidedPaths( resourceProvider ResourceProvider, resourceType api.ResourceType, pathInfos api.PathToVisitorInfoType, getterFunctionInvocation *api.FunctionInvocation, )
RegisterProvidedPaths registers paths in the api.AttributeNameProvidedValue path registry. These are paths of attributes that may provide values that could satisfy needed values within or across configuration Objects. Provided values are matched with Needed values when they have attribute names in common and matching getter (for the Provided value) and setter (for the Needed value) function invocation argument values, as disambiguators. The getter and setter function names do not need to match, since the provided attributes are expected to be of a different kind (different attribute name), from a different resource type.
func Reset ¶
func Reset(parsedData gaby.Container, mutationsPredicates api.ResourceMutationList, resourceProvider ResourceProvider) error
func ResourceAndCategoryTypeMaps ¶
func ResourceAndCategoryTypeMaps(parsedData gaby.Container, resourceProvider ResourceProvider) ( resourceMap ResourceNameToCategoryTypesMap, categoryTypeMap ResourceCategoryTypeToNamesMap, err error, )
ResourceAndCategoryTypeMaps returns maps of all resources in the provided list of parsed YAML documents, from from names to categories+types and categories+types to names.
func ResourceTypesForAttribute ¶
func ResourceTypesForAttribute(attributeName api.AttributeName, resourceProvider ResourceProvider) []api.ResourceType
ResourceTypesForAttribute returns a list of resource types associated with the specified attribute.
func ResourceTypesForPathMap ¶
func ResourceTypesForPathMap(pathMap map[api.ResourceType][]string) []api.ResourceType
ResourceTypesForPathMap returns a list of resource types from a path map.
func StripComments ¶
StripComments removes all comments from YAML data while preserving the structure and values. This is useful when comparing YAML documents where comments should be ignored.
func UpdatePathsFunction ¶
func UpdatePathsFunction[T api.Scalar]( parsedData gaby.Container, resourceTypeToPaths api.ResourceTypeToPathToVisitorInfoType, keys []any, resourceProvider ResourceProvider, updater func(T) T, upsert bool, ) error
UpdatePathsFunction traverses the specified path patterns of the specified resource types. The updater function simply needs to return the new attribute value, which must be of the type of the generic type parameter.
func UpdatePathsFunctionDoc ¶
func UpdatePathsFunctionDoc( parsedData gaby.Container, resourceTypeToPaths api.ResourceTypeToPathToVisitorInfoType, keys []any, resourceProvider ResourceProvider, updater func(*gaby.YamlDoc) *gaby.YamlDoc, upsert bool, ) error
UpdatePathsFunctionDoc traverses the specified path patterns of the specified resource types. The updater function simply needs to return the new attribute value, which must be a YamlDoc.
func UpdatePathsValue ¶
func UpdatePathsValue[T api.Scalar]( parsedData gaby.Container, resourceTypeToPaths api.ResourceTypeToPathToVisitorInfoType, keys []any, resourceProvider ResourceProvider, newValue T, upsert bool, ) error
UpdatePathsValue traverses the specified path patterns of the specified resource types and updates the attributes with the provided value.
func UpdateStringPaths ¶
func UpdateStringPaths( parsedData gaby.Container, resourceTypeToPaths api.ResourceTypeToPathToVisitorInfoType, keys []any, resourceProvider ResourceProvider, newValue string, upsert bool, ) error
UpdateStringPaths traverses the specified path patterns of the specified resource types and updates the attributes with the provided value. It can also inject fields embedded in strings using registered embedded accessors.
func UpdateStringPathsFunction ¶
func UpdateStringPathsFunction( parsedData gaby.Container, resourceTypeToPaths api.ResourceTypeToPathToVisitorInfoType, keys []any, resourceProvider ResourceProvider, updater func(string) string, upsert bool, ) error
UpdateStringPathsFunction traverses the specified path patterns of the specified resource types. The updater function simply needs to return the new attribute value. It can also inject fields embedded in strings using registered embedded accessors.
func VisitPaths ¶
func VisitPaths[T api.Scalar]( parsedData gaby.Container, resourceTypeToPaths api.ResourceTypeToPathToVisitorInfoType, keys []any, output any, resourceProvider ResourceProvider, visitor VisitorFunc[T], upsert bool, ) (any, error)
VisitPaths is a simple wrapper of the base visitor function. It traverses the specified path patterns of the specified resource types within the parsed configuration YAML document list.
func VisitPathsAnyType ¶
func VisitPathsAnyType( parsedData gaby.Container, resourceTypeToPaths api.ResourceTypeToPathToVisitorInfoType, keys []any, output any, resourceProvider ResourceProvider, visitor VisitorFuncAnyType, upsert bool, ) (any, error)
VisitPathsAnyType is a simple wrapper of the base visitor function. It traverses the specified path patterns of the specified resource types within the parsed configuration YAML document list.
func VisitPathsDoc ¶
func VisitPathsDoc( parsedData gaby.Container, resourceTypeToPaths api.ResourceTypeToPathToVisitorInfoType, keys []any, output any, resourceProvider ResourceProvider, visitor VisitorFuncDoc, upsert bool, ) (any, error)
VisitPathsDoc is the base visitor function. It traverses the specified path patterns of the specified resource types within the parsed configuration YAML document list.
func VisitResources ¶
func VisitResources(parsedData gaby.Container, output any, resourceProvider ResourceProvider, visitor ResourceVisitorFunc) (any, error)
VisitResources iterates over all of the resources/elements in a configuration unit and passes metadata about the resource as well as the document itself to a visitor function.
func VisitorInfoEqual ¶
func VisitorInfoEqual(pathVisitorInfo1, pathVisitorInfo2 *api.PathVisitorInfo, compareFunctions bool) bool
VisitorInfoEqual reports whether two path visitor specifications, optionally including getter and setter invocations, match.
func YamlSafePathGetDoc ¶
func YamlSafePathGetDoc( doc *gaby.YamlDoc, resolvedPath api.ResolvedPath, notFoundOk bool, ) (*gaby.YamlDoc, bool, error)
YamlSafePathGetDoc returns a document node at a fully resolved path and whether it was found. An error indicates a parsing error. An error is also returned if the path is expected to exist.
func YamlSafePathGetValue ¶
func YamlSafePathGetValue[T api.Scalar]( doc *gaby.YamlDoc, resolvedPath api.ResolvedPath, notFoundOk bool, ) (T, bool, error)
YamlSafePathGetValue returns a value at a fully resolved path and whether it was found. An error indicates a parsing error or that the value was not of the expected type.
func YamlSafePathGetValueAnyType ¶
func YamlSafePathGetValueAnyType( doc *gaby.YamlDoc, resolvedPath api.ResolvedPath, notFoundOk bool, ) (any, bool, error)
YamlSafePathGetValueAnyType returns a value at a fully resolved path and whether it was found. An error indicates a parsing error.
Types ¶
type EmbeddedAccessor ¶
type EmbeddedAccessor interface {
// ExistsP reports whether the specified attribute or subpart exists within
// the string at the specified YAML document node.
ExistsP(scalarYamlDoc *gaby.YamlDoc, path string) bool
// SetP sets the specified attribute or subpart within the string at the
// specified YAML document node.
SetP(scalarYamlDoc *gaby.YamlDoc, value any, path string) error
// Data returns the value of the specified attribute or subpart embedded
// within the string at the specified YAML document node.
Data(scalarYamlDoc *gaby.YamlDoc, path string) (any, error)
// Replace replaces the value of the specified attribute or subpart within
// the provided string.
Replace(currentFieldValue string, value any, path string) (string, error)
// Extract returns the value of the specified attribute or subpart within the
// provided string.
Extract(currentFieldValue, path string) (any, error)
}
EmbeddedAccessor is used to access attributes embedded in data formats encoded within string values within a YAML document. For instance, YAML might be encoded within a YAML value. Or it could be as simple as a structured string with distinct sections and separators, such as a container image or URL.
func GetEmbeddedAccessor ¶
func GetEmbeddedAccessor(embeddedAccessorType api.EmbeddedAccessorType, config string) (EmbeddedAccessor, error)
type RegexpAccessor ¶
RegexpAccessor is an EmbeddedAccessor that uses regular expressions to extract and insert subparts of a structured string value.
func (*RegexpAccessor) ExistsP ¶
func (ra *RegexpAccessor) ExistsP(scalarYamlDoc *gaby.YamlDoc, path string) bool
func (*RegexpAccessor) Extract ¶
func (ra *RegexpAccessor) Extract(currentFieldValue, path string) (any, error)
type ResolvedPathInfo ¶
type ResolvedPathInfo struct {
Path api.ResolvedPath
PathArguments []api.FunctionArgument
}
ResolvedPathInfo contains a fully resolved path and any named path parameters specified in the unresolved path expression (using ?, *?, or *@).
func ResolveAssociativePaths ¶
func ResolveAssociativePaths( doc *gaby.YamlDoc, unresolvedPath api.UnresolvedPath, resolvedPath api.ResolvedPath, upsert bool, ) ([]ResolvedPathInfo, error)
ResolveAssociativePaths resolves an associative path with associative lookups (?) and wildcards (*, *?, *@) into specific resolved paths and discovered path parameters. See the documentation for api.UnresolvedPath for more details.
type ResourceCategoryTypeToNamesMap ¶
type ResourceCategoryTypeToNamesMap map[api.ResourceCategoryType][]api.ResourceName
type ResourceInfoToDocMap ¶
type ResourceInfoToDocMap map[api.ResourceInfo]int
func ResourceToDocMap ¶
func ResourceToDocMap(parsedData gaby.Container, resourceProvider ResourceProvider) (resourceMap ResourceInfoToDocMap, err error)
ResourceToDocMap returns a map of all resources in the provided list of parsed YAML documents to their document index.
type ResourceNameToCategoryTypesMap ¶
type ResourceNameToCategoryTypesMap map[api.ResourceName][]api.ResourceCategoryType
type ResourceProvider ¶
type ResourceProvider interface {
DefaultResourceCategory() api.ResourceCategory
ResourceCategoryGetter(doc *gaby.YamlDoc) (api.ResourceCategory, error)
ResourceTypeGetter(doc *gaby.YamlDoc) (api.ResourceType, error)
ResourceNameGetter(doc *gaby.YamlDoc) (api.ResourceName, error)
RemoveScopeFromResourceName(resourceName api.ResourceName) api.ResourceName
ScopelessResourceNamePath() api.ResolvedPath
SetResourceName(doc *gaby.YamlDoc, name string) error
ResourceTypesAreSimilar(resourceTypeA, resourceTypeB api.ResourceType) bool
TypeDescription() string
NormalizeName(name string) string
NameSeparator() string
ContextPath(contextField string) string
GetPathRegistry() api.AttributeNameToResourceTypeToPathToVisitorInfoType
}
The ResourceProvider interface is used to perform toolchain-specific operations.
type ResourceTypeToPathPrefixSetType ¶
type ResourceTypeToPathPrefixSetType map[api.ResourceType]map[string]struct{}
type ResourceVisitorFunc ¶
type ResourceVisitorFunc func(doc *gaby.YamlDoc, output any, index int, resourceInfo *api.ResourceInfo) (any, []error)
ResourceVisitorFunc defines the signature of functions invoked by the resource visitor function.
type VisitorContext ¶
type VisitorContext struct {
api.AttributeInfo // includes Path and Info
Arguments []api.FunctionArgument
EmbeddedPath string
Accessor EmbeddedAccessor
}
VisitorContext contains information passed to visitor functions for each path traversed.
type VisitorFunc ¶
type VisitorFunc[T api.Scalar] func(doc *gaby.YamlDoc, output any, context VisitorContext, currentValue T) (any, error)
VisitorFunc defines the signature of functions invoked by the visitor functions.
type VisitorFuncAnyType ¶
type VisitorFuncAnyType func(doc *gaby.YamlDoc, output any, context VisitorContext, currentValue any) (any, error)
VisitorFuncAnyType defines the signature of functions invoked by the visitor functions.
type VisitorFuncDoc ¶
type VisitorFuncDoc func(doc *gaby.YamlDoc, output any, context VisitorContext, currentDoc *gaby.YamlDoc) (any, error)
VisitorFuncDoc defines the signature of functions invoked by the visitor function.