rollback

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: May 24, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package rollback provides automatic and manual rollback functionality for rotation operations.

Index

Constants

View Source
const (
	// DefaultTimeout is the default timeout for rollback operations.
	DefaultTimeout = 30 * time.Second

	// DefaultMaxRetries is the default number of retry attempts for failed rollbacks.
	DefaultMaxRetries = 2
)

Variables

ValidTransitions defines allowed state transitions.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Automatic enables automatic rollback on verification failure.
	Automatic bool

	// OnVerificationFailure triggers rollback when verification fails.
	OnVerificationFailure bool

	// OnHealthCheckFailure triggers rollback when health checks fail.
	OnHealthCheckFailure bool

	// Timeout is the maximum time for rollback operation.
	Timeout time.Duration

	// MaxRetries is the number of times to retry rollback if it fails.
	MaxRetries int

	// Notifications lists notification channels for rollback events.
	Notifications []string
}

Config holds configuration for rollback behavior.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a Config with default values.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager orchestrates rollback operations for rotation failures.

func NewManager

func NewManager(config Config, notifier *notifications.Manager) *Manager

NewManager creates a new rollback manager with the given configuration.

func (*Manager) GetState

func (m *Manager) GetState(service, environment string) *StateInfo

GetState returns the current rollback state for a service/environment.

func (*Manager) ManualRollback

func (m *Manager) ManualRollback(ctx context.Context, req RollbackRequest) (*RollbackResult, error)

ManualRollback initiates a manual rollback operation. This bypasses the automatic rollback check.

func (*Manager) Reset

func (m *Manager) Reset(service, environment string)

Reset clears the rollback state for a service/environment. This should be called after a successful rotation.

func (*Manager) TriggerRollback

func (m *Manager) TriggerRollback(ctx context.Context, req RollbackRequest) (*RollbackResult, error)

TriggerRollback initiates an automatic rollback operation. This is called when verification fails after rotation.

type RollbackRequest

type RollbackRequest struct {
	// Service is the service to rollback.
	Service string

	// Environment is the environment.
	Environment string

	// Reason explains why rollback was triggered.
	Reason string

	// PreviousVersion is the version to rollback to.
	PreviousVersion string

	// FailedVersion is the version that failed.
	FailedVersion string

	// RestoreFunc is the function that restores the previous secret.
	// It should return nil on success or an error on failure.
	RestoreFunc func(ctx context.Context) error

	// VerifyFunc is the function that verifies the restored secret works.
	// It should return nil on success or an error on failure.
	VerifyFunc func(ctx context.Context) error

	// InitiatedBy indicates who or what initiated the rollback.
	InitiatedBy string
}

RollbackRequest contains information needed to perform a rollback.

type RollbackResult

type RollbackResult struct {
	// Success indicates whether the rollback succeeded.
	Success bool

	// State is the final rollback state.
	State State

	// Duration is how long the rollback took.
	Duration time.Duration

	// Attempts is the number of attempts made.
	Attempts int

	// Error is the error if rollback failed.
	Error error
}

RollbackResult contains the outcome of a rollback operation.

type State

type State string

State represents the current state of a rollback operation.

const (
	// StateIdle indicates no rollback is in progress.
	StateIdle State = "idle"

	// StateTriggered indicates a rollback has been triggered but not yet started.
	StateTriggered State = "triggered"

	// StateInProgress indicates rollback is currently executing.
	StateInProgress State = "in_progress"

	// StateVerifying indicates rollback is verifying the restored secret.
	StateVerifying State = "verifying"

	// StateCompleted indicates rollback completed successfully.
	StateCompleted State = "completed"

	// StateFailed indicates rollback failed.
	StateFailed State = "failed"
)

func (State) CanTransitionTo

func (s State) CanTransitionTo(newState State) bool

CanTransitionTo checks if a transition from current state to new state is valid.

func (State) IsTerminal

func (s State) IsTerminal() bool

IsTerminal returns true if this is a terminal state (completed or failed).

func (State) String

func (s State) String() string

String returns the string representation of the state.

type StateInfo

type StateInfo struct {

	// Current is the current state.
	Current State

	// Service is the service being rolled back.
	Service string

	// Environment is the environment.
	Environment string

	// StartedAt is when the rollback was triggered.
	StartedAt time.Time

	// CompletedAt is when the rollback completed (success or failure).
	CompletedAt time.Time

	// Reason is why the rollback was triggered.
	Reason string

	// Error is the error if rollback failed.
	Error error

	// PreviousVersion is the version being rolled back to.
	PreviousVersion string

	// FailedVersion is the version that failed.
	FailedVersion string

	// Transitions is the history of state transitions.
	Transitions []Transition

	// Attempts is the number of rollback attempts.
	Attempts int
	// contains filtered or unexported fields
}

StateInfo holds information about the current rollback state.

func NewStateInfo

func NewStateInfo(service, environment string) *StateInfo

NewStateInfo creates a new StateInfo with initial values.

func (*StateInfo) Duration

func (si *StateInfo) Duration() time.Duration

Duration returns the duration of the rollback operation. Returns 0 if the rollback has not completed.

func (*StateInfo) GetAttempts

func (si *StateInfo) GetAttempts() int

GetAttempts returns the number of attempts (thread-safe).

func (*StateInfo) GetCurrent

func (si *StateInfo) GetCurrent() State

GetCurrent returns the current state (thread-safe).

func (*StateInfo) SetVersionInfo

func (si *StateInfo) SetVersionInfo(reason, previousVersion, failedVersion string)

SetVersionInfo sets version-related fields (thread-safe).

func (*StateInfo) TransitionTo

func (si *StateInfo) TransitionTo(newState State, reason string, err error) error

TransitionTo attempts to transition to a new state. Returns an error if the transition is not allowed.

type Transition

type Transition struct {
	FromState State
	ToState   State
	Reason    string
	Error     error
	Timestamp time.Time
}

Transition represents a state transition with metadata.

Jump to

Keyboard shortcuts

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