version

package
v0.7.6 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package version provides shared version specification parsing logic for SSM Parameter Store and Secrets Manager version specifiers.

Version specification grammar:

<name><absolute>?<shift>*

Where:

  • <name> is the parameter/secret name (required)
  • <absolute> is a type-specific absolute version specifier (optional)
  • <shift> is ~ or ~N for relative version shift (optional, repeatable)

Examples:

  • SSM Parameter Store: /my/param, /my/param#3, /my/param~1, /my/param#5~2
  • Secrets Manager: my-secret, my-secret#abc123, my-secret:AWSCURRENT, my-secret~1

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptySpec            = errors.New("empty specification")
	ErrEmptyName            = errors.New("empty name")
	ErrAmbiguousTilde       = errors.New("ambiguous tilde")
	ErrMultipleAbsoluteSpec = errors.New("multiple absolute version specifiers")
)

Common errors for version parsing.

Functions

This section is empty.

Types

type AbsoluteParser

type AbsoluteParser[A any] struct {
	// Parsers is the list of specifier parsers to try, in order.
	Parsers []SpecifierParser[A]

	// Zero returns the zero/default value of A.
	// Called when no absolute specifier is present in the input.
	Zero func() A
}

AbsoluteParser holds the configuration for parsing absolute specifiers. Each service (SSM Parameter Store/Secrets Manager) creates its own AbsoluteParser instance.

type Spec

type Spec[A any] struct {
	Name     string // Parameter/secret name (e.g., "/my/param", "my-secret")
	Absolute A      // Absolute version specifier (type-specific, zero value if not specified)
	Shift    int    // Relative shift amount (0 means no shift, positive means go back N versions)
}

Spec represents a parsed version specification. The type parameter A holds service-specific absolute version info (e.g., version number for SSM Parameter Store, version ID or label for Secrets Manager).

func Parse

func Parse[A any](input string, parser AbsoluteParser[A]) (*Spec[A], error)

Parse parses a version specification string into a Spec.

The parsing proceeds in three steps:

  1. Find where the name ends (where specifiers begin)
  2. Parse absolute specifier(s) if present
  3. Parse shift specifier(s) if present

Returns error if:

  • Input is empty or whitespace only
  • Name is empty (specifier at start)
  • Invalid specifier syntax (e.g., "#" at end, ambiguous "~")
  • Conflicting specifiers (e.g., both #id and :label)

func (*Spec[A]) HasShift

func (s *Spec[A]) HasShift() bool

HasShift returns true if a relative shift is specified (Shift > 0).

type SpecifierParser

type SpecifierParser[A any] struct {
	// PrefixChar is the character that starts this specifier (e.g., '#', ':').
	PrefixChar byte

	// IsChar returns true if the byte is valid within this specifier's value.
	// Used to determine where the specifier value ends.
	// Example: for "#123", IsChar would return true for '1', '2', '3'.
	IsChar func(byte) bool

	// Error is returned when PrefixChar is found but not followed by a valid char.
	// If nil, the PrefixChar is treated as part of the name instead of an error.
	// Example: "#" at end of input, or "#" followed by invalid char.
	Error error

	// Duplicated returns true if this specifier type is already set in abs.
	// Used to detect conflicting specifiers (e.g., both #id and :label in Secrets Manager).
	// Can be nil if duplicate checking is not needed.
	Duplicated func(abs A) bool

	// Apply assigns the parsed value to abs and returns the updated abs.
	// The value parameter is the string after PrefixChar (e.g., "123" for "#123").
	// Should only do assignment; validation errors (like overflow) are wrapped by caller.
	Apply func(value string, abs A) (A, error)
}

SpecifierParser defines how to parse a single type of absolute specifier. Each service (SSM Parameter Store/Secrets Manager) defines its own set of SpecifierParsers.

For example, SSM Parameter Store has one parser for "#" (version number), while Secrets Manager has two parsers for "#" (version ID) and ":" (label).

Directories

Path Synopsis
Package internal provides shared utilities for version parsing.
Package internal provides shared utilities for version parsing.
Package paramversion provides version resolution for AWS Systems Manager Parameter Store.
Package paramversion provides version resolution for AWS Systems Manager Parameter Store.
Package secretversion provides version resolution for AWS Secrets Manager.
Package secretversion provides version resolution for AWS Secrets Manager.

Jump to

Keyboard shortcuts

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