staging

package
v1.9.2 Latest Latest
Warning

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

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

Documentation

Overview

Package staging provides use cases for staging operations.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNothingToExport is returned when there are no staged changes to export.
	ErrNothingToExport = errors.New("no staged changes to export")
)
View Source
var (
	// ErrNothingToImport is returned when the source holds no staged changes.
	ErrNothingToImport = errors.New("no staged changes to import")
)
View Source
var ErrValueNotUTF8 = errors.New("value is not valid UTF-8: binary values cannot be staged")

ErrValueNotUTF8 is returned when a value to be staged is not valid UTF-8. The staging state stores values as UTF-8 strings (mirroring jsonutil, which refuses to format invalid UTF-8 to avoid U+FFFD coercion), so binary values cannot be staged. This covers every ingestion path: positional argv, the $EDITOR fallback, and provider prefill.

Functions

This section is empty.

Types

type AddInput

type AddInput struct {
	Key         staging.EntryKey
	Value       string
	Description string
	// ValueType is the provider-neutral value type for the staged create. It is
	// only meaningful on the AWS SSM Parameter Store axis (String / SecureString /
	// StringList); other providers leave it empty. An empty value applies as
	// plaintext, so callers that do not set it keep the prior behavior.
	ValueType domain.ValueType
}

AddInput holds input for the add use case. Key identifies the item by name and (Azure App Configuration) namespace; the namespace is empty for the null/default namespace and every other provider.

type AddOutput

type AddOutput struct {
	Name string
}

AddOutput holds the result of the add use case.

type AddUseCase

type AddUseCase struct {
	Strategy staging.EditStrategy
	Store    store.ReadWriteOperator
}

AddUseCase executes add operations.

func (*AddUseCase) Draft

func (u *AddUseCase) Draft(ctx context.Context, input DraftInput) (*DraftOutput, error)

Draft returns the currently staged create value (draft) for re-editing.

func (*AddUseCase) Execute

func (u *AddUseCase) Execute(ctx context.Context, input AddInput) (*AddOutput, error)

Execute runs the add use case.

type ApplyEntryResult added in v0.3.0

type ApplyEntryResult struct {
	Name string
	// Namespace is the App Configuration namespace the entry was applied under
	// (empty for the null/default namespace and every other provider).
	Namespace string
	Status    ApplyResultStatus
	Error     error
	// UnstageError is set when the cloud apply succeeded but clearing the entry
	// from the staging store afterwards failed. The entry is still staged, so a
	// later apply would re-run it; callers must surface this rather than ignore it.
	UnstageError error
}

ApplyEntryResult represents the result of applying a single entry.

type ApplyInput

type ApplyInput struct {
	Name            string // Optional: apply only this item
	IgnoreConflicts bool   // Skip conflict detection
}

ApplyInput holds input for the apply use case.

type ApplyOutput

type ApplyOutput struct {
	ServiceName string
	ItemName    string
	// Entry results
	EntryResults   []ApplyEntryResult
	EntrySucceeded int
	EntryFailed    int
	// Tag results
	TagResults   []ApplyTagResult
	TagSucceeded int
	TagFailed    int
	// Conflicts carries the full EntryKey (name + namespace) of each conflicting
	// entry so callers can render the namespace badge; empty namespace renders as
	// the bare name.
	Conflicts []staging.EntryKey
}

ApplyOutput holds the result of the apply use case.

type ApplyResultStatus

type ApplyResultStatus int

ApplyResultStatus represents the status of an apply operation.

const (
	ApplyResultCreated ApplyResultStatus = iota
	ApplyResultUpdated
	ApplyResultDeleted
	ApplyResultFailed
)

ApplyResultStatus constants representing the outcome of applying a staged entry.

type ApplyTagResult added in v0.3.0

type ApplyTagResult struct {
	Name string
	// Namespace is the App Configuration namespace the tags were applied under
	// (empty for the null/default namespace and every other provider).
	Namespace string
	AddTags   map[string]string   // Tags that were added/updated
	RemoveTag maputil.Set[string] // Tag keys that were removed
	Error     error
	// UnstageError is set when the cloud tag apply succeeded but clearing the
	// staged tag afterwards failed (see ApplyEntryResult.UnstageError).
	UnstageError error
}

ApplyTagResult represents the result of applying tag changes.

type ApplyUseCase

type ApplyUseCase struct {
	Strategy staging.ApplyStrategy
	Store    store.ReadWriteOperator
	// StrategyFor, when set, resolves the ApplyStrategy for a given namespace so
	// each staged entry is applied through a provider store scoped to its own
	// namespace (Azure App Configuration, whose settings share one staging store
	// across namespaces). When nil, Strategy applies every entry — the case for
	// namespace-agnostic providers (AWS, Google Cloud, Key Vault).
	StrategyFor func(namespace string) (staging.ApplyStrategy, error)
}

ApplyUseCase executes apply operations.

func (*ApplyUseCase) Execute

func (u *ApplyUseCase) Execute(ctx context.Context, input ApplyInput) (*ApplyOutput, error)

Execute runs the apply use case.

type BaselineInput

type BaselineInput struct {
	Key staging.EntryKey
}

BaselineInput holds input for getting baseline value.

type BaselineOutput

type BaselineOutput struct {
	Value        string
	IsStagedEdit bool // True if the baseline is from a staged edit (not AWS)
}

BaselineOutput holds the baseline value for editing.

type DeleteInput

type DeleteInput struct {
	Key            staging.EntryKey
	Force          bool // For Secrets Manager: force immediate deletion
	RecoveryWindow int  // For Secrets Manager: days before permanent deletion (7-30)
}

DeleteInput holds input for the delete use case. Key identifies the item by name and (Azure App Configuration) namespace; the namespace is empty for the null/default namespace and every other provider.

type DeleteOutput

type DeleteOutput struct {
	Name              string
	Unstaged          bool // True if a staged CREATE was removed instead of staging DELETE
	ShowDeleteOptions bool // True if delete options (Force/RecoveryWindow) should be shown
	Force             bool
	RecoveryWindow    int
}

DeleteOutput holds the result of the delete use case.

type DeleteUseCase

type DeleteUseCase struct {
	Strategy staging.DeleteStrategy
	Store    store.ReadWriteOperator
}

DeleteUseCase executes delete staging operations.

func (*DeleteUseCase) Execute

func (u *DeleteUseCase) Execute(ctx context.Context, input DeleteInput) (*DeleteOutput, error)

Execute runs the delete use case.

type DiffEntry

type DiffEntry struct {
	Name string
	// Namespace is the App Configuration namespace of the entry (empty for the
	// null/default namespace and every other provider).
	Namespace     string
	Type          DiffEntryType
	Operation     staging.Operation
	AWSValue      string
	AWSIdentifier string
	StagedValue   string
	Description   *string
	Warning       string // For warnings like "already deleted in AWS"
	// Secret reports whether the entry's values are secret material (a secret
	// service, or a SecureString param), so a consumer masks both the remote and
	// staged values in the review. Keyed off the value type, not the service, so
	// a SecureString param is masked too (#677).
	Secret bool
}

DiffEntry represents a single diff result for entries.

type DiffEntryType

type DiffEntryType int

DiffEntryType represents the type of diff entry.

const (
	DiffEntryNormal DiffEntryType = iota
	DiffEntryCreate
	DiffEntryAutoUnstaged
	DiffEntryWarning
)

DiffEntryType constants representing the type of diff result.

type DiffInput

type DiffInput struct {
	Name string // Optional: diff only this item
}

DiffInput holds input for the diff use case.

type DiffOutput

type DiffOutput struct {
	ItemName   string
	Entries    []DiffEntry
	TagEntries []DiffTagEntry
}

DiffOutput holds the result of the diff use case.

type DiffTagEntry added in v0.3.0

type DiffTagEntry struct {
	Name string
	// Namespace is the App Configuration namespace of the tagged item (empty for
	// the null/default namespace and every other provider).
	Namespace string
	Add       map[string]string // Tags to add or update
	Remove    map[string]string // Tags to remove (key=current value from AWS)
}

DiffTagEntry represents a single diff result for tag changes.

type DiffUseCase

type DiffUseCase struct {
	Strategy staging.DiffStrategy
	Store    store.ReadWriteOperator
	// StrategyFor, when set, resolves the DiffStrategy for a given namespace so
	// each staged entry is diffed against a provider store scoped to its own
	// namespace (Azure App Configuration). When nil, Strategy handles every
	// entry (namespace-agnostic providers).
	StrategyFor func(namespace string) (staging.DiffStrategy, error)
}

DiffUseCase executes diff operations.

func (*DiffUseCase) Execute

func (u *DiffUseCase) Execute(ctx context.Context, input DiffInput) (*DiffOutput, error)

Execute runs the diff use case.

type DraftInput

type DraftInput struct {
	Key staging.EntryKey
}

DraftInput holds input for getting draft (staged create) value.

type DraftOutput

type DraftOutput struct {
	Value    string
	IsStaged bool
}

DraftOutput holds the draft value if any.

type EditInput

type EditInput struct {
	Key         staging.EntryKey
	Value       string
	Description string
	// ValueType is the provider-neutral value type for the staged update. It is
	// only meaningful on the AWS SSM Parameter Store axis (String / SecureString /
	// StringList); other providers leave it empty. An empty value preserves the
	// existing (staged or cloud) type, so callers that do not set it keep the
	// prior type-preserving behavior.
	ValueType domain.ValueType
}

EditInput holds input for the edit use case. Key identifies the item by name and (Azure App Configuration) namespace; the namespace is empty for the null/default namespace and every other provider.

type EditOutput

type EditOutput struct {
	Name     string
	Skipped  bool // True if the edit was skipped because value matches AWS
	Unstaged bool // True if the entry was auto-unstaged
}

EditOutput holds the result of the edit use case.

type EditUseCase

type EditUseCase struct {
	Strategy staging.EditStrategy
	Store    store.ReadWriteOperator
}

EditUseCase executes edit operations.

func (*EditUseCase) Baseline

func (u *EditUseCase) Baseline(ctx context.Context, input BaselineInput) (*BaselineOutput, error)

Baseline returns the baseline value for editing (staged value if exists, otherwise from AWS).

func (*EditUseCase) Execute

func (u *EditUseCase) Execute(ctx context.Context, input EditInput) (*EditOutput, error)

Execute runs the edit use case.

type EnvelopeReader added in v1.7.0

type EnvelopeReader interface {
	// ReadState returns the decoded state for svc.
	ReadState(ctx context.Context, svc staging.Service) (*staging.State, error)
}

EnvelopeReader reads a single service's staged state from an import source (typically a per-service envelope file). Adapters bind the source path, scope validation, and passphrase; the use case only supplies the service. For a missing file in the directory/global case the adapter returns an empty state with a nil error (an absent service is skipped, not an error).

type EnvelopeWriter added in v1.7.0

type EnvelopeWriter interface {
	// WriteEnvelope serializes state (scoped to svc) to the export target.
	WriteEnvelope(ctx context.Context, svc staging.Service, state *staging.State) error
}

EnvelopeWriter writes a single service's staged state to an export target (typically a per-service envelope file). Adapters bind the destination path, scope, and passphrase; the use case only supplies the service and its state.

type ExportError added in v1.7.0

type ExportError struct {
	Op       ExportOp
	Err      error
	NonFatal bool // If true, the error is non-fatal (state was already written)
}

ExportError represents an error during an export operation.

func (*ExportError) Error added in v1.7.0

func (e *ExportError) Error() string

func (*ExportError) Unwrap added in v1.7.0

func (e *ExportError) Unwrap() error

type ExportInput added in v1.7.0

type ExportInput struct {
	// Service filters the export to a specific service. Empty means all services
	// that have staged changes.
	Service staging.Service
	// Keep preserves the working staging area after exporting.
	Keep bool
}

ExportInput holds input for the export use case.

type ExportOp added in v1.7.0

type ExportOp string

ExportOp identifies the stage of an export operation that failed.

const (
	ExportOpLoad  ExportOp = "load"
	ExportOpWrite ExportOp = "write"
	ExportOpClear ExportOp = "clear"
)

Export error Op codes.

type ExportOutput added in v1.7.0

type ExportOutput struct {
	// EntryCount is the number of entries exported.
	EntryCount int
	// TagCount is the number of tag entries exported.
	TagCount int
}

ExportOutput holds the result of the export use case.

type ExportUseCase added in v1.7.0

type ExportUseCase struct {
	// Working is the working staging area (param.json/secret.json).
	Working store.WorkingStore
	// Target receives the exported per-service state.
	Target EnvelopeWriter
}

ExportUseCase writes the working staging area out to an export target wholesale. Unlike the former stash push, export never merges with existing destination data: writing state out is a serialization of the current working area, not a reconciliation with whatever a file previously held.

func (*ExportUseCase) Execute added in v1.7.0

func (u *ExportUseCase) Execute(ctx context.Context, input ExportInput) (*ExportOutput, error)

Execute runs the export use case.

type ImportError added in v1.7.0

type ImportError struct {
	Op  ImportOp
	Err error
}

ImportError represents an error during an import operation.

func (*ImportError) Error added in v1.7.0

func (e *ImportError) Error() string

func (*ImportError) Unwrap added in v1.7.0

func (e *ImportError) Unwrap() error

type ImportInput added in v1.7.0

type ImportInput struct {
	// Service filters the import to a specific service. Empty means all services.
	Service staging.Service
	// Mode determines how to reconcile with an existing working staging area.
	// ImportModeMerge combines the imported state with the working area.
	// ImportModeOverwrite replaces the working area with the imported state.
	Mode ImportMode
	// ReAnchor requests re-basing each staged item's BaseModifiedAt against the
	// target scope's current LastModified. It is set for a cross-scope import
	// (CLI --allow-scope-mismatch / GUI force), where the envelope's
	// BaseModifiedAt belongs to a foreign scope's timeline and would make apply's
	// conflict detection meaningless. It is a no-op unless the use case also has
	// a ReAnchor resolver configured.
	ReAnchor bool
}

ImportInput holds input for the import use case.

type ImportMode added in v1.7.0

type ImportMode int

ImportMode determines how to reconcile imported state with the existing working staging area.

const (
	// ImportModeMerge combines the imported state with the existing working
	// staging area. Later entries win on key conflicts.
	ImportModeMerge ImportMode = iota
	// ImportModeOverwrite replaces the existing working staging area with the
	// imported state.
	ImportModeOverwrite
)

type ImportOp added in v1.7.0

type ImportOp string

ImportOp identifies the stage of an import operation that failed.

const (
	ImportOpLoad        ImportOp = "load"
	ImportOpWrite       ImportOp = "write"
	ImportOpReadWorking ImportOp = "read-working"
)

Import error Op codes.

type ImportOutput added in v1.7.0

type ImportOutput struct {
	// Merged indicates whether the imported state was merged with pre-existing
	// working state.
	Merged bool
	// EntryCount is the number of entries in the final working state.
	EntryCount int
	// TagCount is the number of tag entries in the final working state.
	TagCount int
	// Warnings holds non-fatal diagnostics produced during import, e.g. an item
	// left unanchored because its LastModified could not be fetched from the
	// target scope during a cross-scope re-anchor.
	Warnings []string
}

ImportOutput holds the result of the import use case.

type ImportUseCase added in v1.7.0

type ImportUseCase struct {
	// Source provides the imported per-service state.
	Source EnvelopeReader
	// Working is the working staging area (param.json/secret.json).
	Working store.WorkingStore
	// ReAnchor, when set, resolves a strategy that fetches the target scope's
	// current LastModified so a cross-scope import (ImportInput.ReAnchor) re-bases
	// each staged item's conflict-detection timestamp. Nil disables re-anchoring
	// even when ImportInput.ReAnchor is set (same-scope import needs none).
	ReAnchor ReAnchorResolver
}

ImportUseCase reads an export source into the working staging area. It keeps the merge/overwrite reconciliation of the former stash pop for the working area (a legitimate conflict), but is read-only on the source: nothing is consumed or deleted, so there is no Keep concept.

func (*ImportUseCase) Execute added in v1.7.0

func (u *ImportUseCase) Execute(ctx context.Context, input ImportInput) (*ImportOutput, error)

Execute runs the import use case.

type ReAnchorResolver added in v1.8.1

type ReAnchorResolver func(svc staging.Service, namespace string) (staging.ApplyStrategy, error)

ReAnchorResolver resolves the ApplyStrategy that can fetch a resource's current LastModified in the TARGET (current) scope, for a service and namespace. It mirrors the apply/conflict resolver so a cross-scope import can re-base each staged item's conflict-detection timestamp against the scope it is imported INTO rather than the foreign scope it was exported FROM. For namespace-agnostic providers the namespace is always empty.

type ResetInput

type ResetInput struct {
	Spec string // Name with optional version spec
	All  bool   // Reset all staged items for this service
	// Namespace is the Azure App Configuration namespace of the entry to reset;
	// empty is the null/default namespace and the only value for every other
	// provider. Ignored when All is set (UnstageAll clears every namespace).
	Namespace string
}

ResetInput holds input for the reset use case.

type ResetOutput

type ResetOutput struct {
	Type         ResetResultType
	Name         string
	VersionLabel string
	Count        int // Number of items unstaged (for UnstagedAll)
	ServiceName  string
	ItemName     string
}

ResetOutput holds the result of the reset use case.

type ResetResultType

type ResetResultType int

ResetResultType represents the type of reset result.

const (
	ResetResultUnstaged ResetResultType = iota
	ResetResultUnstagedAll
	ResetResultRestored
	ResetResultNotStaged
	ResetResultNothingStaged
	ResetResultSkipped     // Restore was skipped because value matches current AWS
	ResetResultUnstagedTag // Only staged tag changes were unstaged (entry itself not staged)
)

ResetResultType constants representing the outcome of a reset operation.

type ResetUseCase

type ResetUseCase struct {
	Parser  staging.Parser
	Fetcher staging.ResetStrategy
	Store   store.ReadWriteOperator
}

ResetUseCase executes reset operations.

func (*ResetUseCase) Execute

func (u *ResetUseCase) Execute(ctx context.Context, input ResetInput) (*ResetOutput, error)

Execute runs the reset use case.

type StatusEntry

type StatusEntry struct {
	Name string
	// Namespace is the App Configuration namespace of the entry (empty for the
	// null/default namespace and every other provider).
	Namespace         string
	Operation         staging.Operation
	Value             *string
	Description       *string
	DeleteOptions     *staging.DeleteOptions
	StagedAt          time.Time
	ShowDeleteOptions bool
}

StatusEntry represents a single staged entry (create/update/delete).

type StatusInput

type StatusInput struct {
	Name string // Optional: if set, show only this item
}

StatusInput holds input for the status use case.

type StatusOutput

type StatusOutput struct {
	Service     staging.Service
	ServiceName string
	ItemName    string
	Entries     []StatusEntry
	TagEntries  []StatusTagEntry
}

StatusOutput holds the result of the status use case.

type StatusTagEntry added in v0.3.0

type StatusTagEntry struct {
	Name string
	// Namespace is the App Configuration namespace of the tagged item (empty for
	// the null/default namespace and every other provider).
	Namespace string
	Add       map[string]string   // Tags to add or update
	Remove    maputil.Set[string] // Tag keys to remove
	StagedAt  time.Time
}

StatusTagEntry represents staged tag changes for an entity.

type StatusUseCase

type StatusUseCase struct {
	Strategy staging.ServiceStrategy
	Store    store.ReadOperator
}

StatusUseCase executes status operations.

func (*StatusUseCase) Execute

func (u *StatusUseCase) Execute(ctx context.Context, input StatusInput) (*StatusOutput, error)

Execute runs the status use case.

type TagInput added in v0.2.0

type TagInput struct {
	Key  staging.EntryKey
	Tags map[string]string
}

TagInput holds input for the tag staging use case. Key identifies the resource by name and (Azure App Configuration) namespace; staged tags are keyed by (name, namespace) so the same name under two namespaces holds independent tag changes. The namespace is empty for the null/default namespace and every other provider.

type TagOutput added in v0.2.0

type TagOutput struct {
	Name string
}

TagOutput holds the result of the tag staging use case.

type TagUseCase added in v0.2.0

type TagUseCase struct {
	Strategy staging.EditStrategy
	Store    store.ReadWriteOperator
}

TagUseCase executes tag staging operations.

func (*TagUseCase) Tag added in v0.4.5

func (u *TagUseCase) Tag(ctx context.Context, input TagInput) (*TagOutput, error)

Tag adds or updates tags on a staged resource.

func (*TagUseCase) Untag added in v0.4.5

func (u *TagUseCase) Untag(ctx context.Context, input UntagInput) (*UntagOutput, error)

Untag removes tags from a staged resource.

type UntagInput added in v0.4.5

type UntagInput struct {
	Key     staging.EntryKey
	TagKeys maputil.Set[string]
}

UntagInput holds input for the untag staging use case. Key identifies the resource by name and (Azure App Configuration) namespace.

type UntagOutput added in v0.4.5

type UntagOutput struct {
	Name string
}

UntagOutput holds the result of the untag staging use case.

Jump to

Keyboard shortcuts

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