tags

package
v1.225.0 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

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

View Source
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

func CollectAvailableTags[T any](items map[string]T, getTags func(T) []string) []string

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

func MatchesLabels(labels map[string]string, filterLabels map[string]string) bool

MatchesLabels reports whether labels contains every key=value pair in filterLabels (AND). An empty filterLabels always matches (no filter applied).

func MatchesTags

func MatchesTags(tags []string, filterTags []string, mode TagMode) bool

MatchesTags reports whether tags satisfies filterTags under mode. An empty filterTags always matches (no filter applied).

func ParseLabelsFlag

func ParseLabelsFlag(input string) (map[string]string, error)

ParseLabelsFlag parses a comma-separated key=value (or key:value) list into a map[string]string.

func ParseTagsFlag

func ParseTagsFlag(input string) []string

ParseTagsFlag parses a comma-separated tags string into a trimmed, non-empty slice.

func RequestedLabels added in v1.225.0

func RequestedLabels(raw any, filter map[string]string, leftDelim string) (map[string]any, bool)

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

func ResolveSelectorValue(v any, data map[string]any, leftDelim, rightDelim string) (any, bool)

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

func SelectorUnresolved(v any, leftDelim string) bool

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

func SortedKeys(m map[string]string) []string

SortedKeys returns the sorted keys of a map[string]string.

func SortedValues

func SortedValues(m map[string]string) []string

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

func TemplateDelims(delims []string) (string, string)

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

func ToStringMap(v any) map[string]string

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

func ToStringSlice(v any) []string

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

func ValidateSelectorValue(field string, v any, leftDelim, rightDelim string) error

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).

Types

type TagMode

type TagMode string

TagMode defines how multiple filter tags combine when matching against an entity's tags.

const (
	// TagModeAny matches if the entity has at least one of the filter tags (OR).
	TagModeAny TagMode = "any"
	// TagModeAll matches only if the entity has every filter tag (AND).
	TagModeAll TagMode = "all"
)

Jump to

Keyboard shortcuts

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