Documentation
¶
Overview ¶
Package tags provides shared tag/label matching primitives used across Atmos subsystems (auth identities/providers, components, bulk component selection) so every consumer applies the same any/all-match semantics.
Index ¶
- Constants
- func CollectAvailableTags[T any](items map[string]T, getTags func(T) []string) []string
- func MatchesLabels(labels map[string]string, filterLabels map[string]string) bool
- func MatchesTags(tags []string, filterTags []string, mode TagMode) bool
- func ParseLabelsFlag(input string) (map[string]string, error)
- func ParseTagsFlag(input string) []string
- func RequestedLabels(raw any, filter map[string]string, leftDelim string) (map[string]any, bool)
- func ResolveSelectorValue(v any, data map[string]any, leftDelim, rightDelim string) (any, bool)
- func SelectorUnresolved(v any, leftDelim string) bool
- func SortedKeys(m map[string]string) []string
- func SortedValues(m map[string]string) []string
- func TemplateDelims(delims []string) (string, string)
- func ToStringMap(v any) map[string]string
- func ToStringSlice(v any) []string
- func ValidateSelectorValue(field string, v any, leftDelim, rightDelim string) error
- type TagMode
Constants ¶
const ( DefaultLeftDelim = "{{" DefaultRightDelim = "}}" )
DefaultLeftDelim and DefaultRightDelim are the standard Go template delimiters, used when 'templates.settings.delimiters' is not configured.
Variables ¶
This section is empty.
Functions ¶
func CollectAvailableTags ¶
CollectAvailableTags returns the sorted, deduplicated set of tags across all items, using getTags to extract each item's tags. Used to build "available tags" hints for no-match errors (e.g. auth identities/providers).
func MatchesLabels ¶
MatchesLabels reports whether labels contains every key=value pair in filterLabels (AND). An empty filterLabels always matches (no filter applied).
func MatchesTags ¶
MatchesTags reports whether tags satisfies filterTags under mode. An empty filterTags always matches (no filter applied).
func ParseLabelsFlag ¶
ParseLabelsFlag parses a comma-separated key=value (or key:value) list into a map[string]string.
func ParseTagsFlag ¶
ParseTagsFlag parses a comma-separated tags string into a trimmed, non-empty slice.
func RequestedLabels ¶ added in v1.225.0
RequestedLabels keeps only the label values named by the current selector so unrelated (possibly templated) labels cannot affect the scope decision or force full component evaluation.
An ok=false result means the raw value cannot be safely narrowed and the caller must treat the selector as undecidable (fall through to full evaluation): the value is a non-map (e.g. a templated scalar that whole-manifest rendering may re-parse into a map — the gate cannot reproduce that), or one of its KEYS is itself unresolved (a templated key may render to a requested key, so a literal-key lookup would wrongly report a decidable non-match). A nil raw value narrows to an empty map with ok=true — a component without labels genuinely does not match a labels filter.
func ResolveSelectorValue ¶ added in v1.225.0
ResolveSelectorValue best-effort renders the simple Go templates a selector value may contain (the only template form the purity contract allows) against the component's raw section data, so scope decisions on a lightweight (unevaluated) graph can be exact instead of conservatively matching every templated selector. It returns the resolved value and true when every string resolved cleanly; any parse/execute failure, missing key, or still-unresolved marker in the output returns false — callers must then fall back to the conservative match, never exclusion.
func SelectorUnresolved ¶ added in v1.225.0
SelectorUnresolved reports whether a metadata.tags/metadata.labels value still contains an unresolved marker, meaning its real value can only be known after template/YAML-function evaluation:
- a Go template marker (the configured left delimiter, "{{" by default), or
- an unprocessed Atmos YAML function (custom-tagged scalars are stored as plain strings like "!env DEPLOY_TIER" until function processing runs — see getValueWithTag in pkg/utils).
Callers use this to treat such selectors as undecidable and fall through to full evaluation instead of silently misjudging them as out-of-scope. A quoted literal that merely looks like a marker is conservatively treated as unresolved too — the safe direction, since it only forces evaluation.
func SortedKeys ¶
SortedKeys returns the sorted keys of a map[string]string.
func SortedValues ¶
SortedValues returns the values of a map[string]string, ordered by key for deterministic output (map iteration order is randomized in Go).
func TemplateDelims ¶ added in v1.225.0
TemplateDelims returns the effective template delimiters from a raw 'templates.settings.delimiters' config value, falling back to the standard Go delimiters when the setting is absent or malformed (template processing itself reports malformed delimiters; selector validation only needs a best-effort parse).
func ToStringMap ¶
ToStringMap coerces a YAML-decoded value (typically map[string]any) into a map[string]string, skipping any non-string values. Returns an empty (non-nil) map for nil/invalid input so callers always get a rangeable value.
func ToStringSlice ¶
ToStringSlice coerces a YAML-decoded value (typically []any) into a []string, skipping any non-string elements. Returns an empty (non-nil) slice for nil/invalid input so callers always get a rangeable value.
func ValidateSelectorValue ¶ added in v1.225.0
ValidateSelectorValue enforces the selector purity contract on a metadata.tags or metadata.labels value: selectors are evaluated before authentication, templating, and YAML-function processing so Atmos can decide which components are in scope without evaluating out-of-scope ones. By design their values are limited to plain strings, simple Go templates over the stack context, and local functions such as !env, !git.*, and !include. Anything that requires authentication or process execution (for example !terraform.state, !store, !exec, or atmos.Component) is rejected with an error, not silently deferred. The field parameter names the manifest location (e.g. "metadata.tags") for error reporting; leftDelim/rightDelim are the configured template delimiters (empty strings select the defaults).