plan

package
v0.4.0-beta.4 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusAvailable = "available"
	StatusApplying  = "applying"
	StatusApplied   = "applied"
	StatusFailed    = "failed"
	StatusObsolete  = "obsolete"
	StatusExpired   = "expired"
)
View Source
const (
	ActionCreate = "create"
	ActionUpdate = "update"
	ActionDelete = "delete"
	ActionNoOp   = "no-op"
)
View Source
const FormatVersion = 1
View Source
const RedactedPlaceholder = "[redacted]"

Variables

View Source
var ErrNotFound = fmt.Errorf("plan not found")

Functions

func SnapshotFiles

func SnapshotFiles(base string, paths ...string) map[string]string

SnapshotFiles hashes the given paths. Relative paths are resolved against base and stored relative; absolute paths are stored as-is. Missing files hash to the literal "absent" so creation is detectable.

func StrPtr

func StrPtr(s string) *string

func VerifySnapshot

func VerifySnapshot(base string, snapshot map[string]string) error

VerifySnapshot re-hashes every snapshotted file and returns a *DriftError listing the paths whose content changed since plan time.

Types

type Actor

type Actor struct {
	ID   string `json:"id"`
	Name string `json:"name"`
	Type string `json:"type"`
}

type Change

type Change struct {
	Type      string   `json:"type"`
	ID        string   `json:"id"`
	Actions   []string `json:"actions"`
	Reason    string   `json:"reason"`
	Before    *string  `json:"before"`
	After     *string  `json:"after"`
	Sensitive bool     `json:"sensitive"`
}

type DriftError

type DriftError struct {
	Paths []string
}

func (*DriftError) Error

func (e *DriftError) Error() string

type ListFilter

type ListFilter struct {
	ResourceType string
	ResourceID   string
	Status       string
}

type Plan

type Plan struct {
	FormatVersion int             `json:"format_version"`
	ID            string          `json:"id"`
	Action        string          `json:"action"`
	Status        string          `json:"status"`
	Resource      Resource        `json:"resource"`
	CreatedAt     time.Time       `json:"created_at"`
	ExpiresAt     time.Time       `json:"expires_at"`
	CreatedBy     Actor           `json:"created_by"`
	AppliedAt     *time.Time      `json:"applied_at,omitempty"`
	AppliedBy     *Actor          `json:"applied_by,omitempty"`
	ApplyError    string          `json:"apply_error,omitempty"`
	Request       RequestEnvelope `json:"request"`
	Snapshot      Snapshot        `json:"snapshot"`
	Changes       []Change        `json:"changes"`
	Summary       Summary         `json:"summary"`
}

func New

func New(action string, resource Resource, actor Actor, ttl time.Duration) *Plan

func (*Plan) Expired

func (p *Plan) Expired(now time.Time) bool

func (*Plan) Redacted

func (p *Plan) Redacted() *Plan

Redacted returns a copy safe for API responses: sensitive change contents are masked. The on-disk plan keeps full values (0600, same trust domain as .env.flatrun).

func (*Plan) Summarize

func (p *Plan) Summarize()

Summarize recomputes Summary from Changes. An ordered action pair (delete+create or create+delete) counts as one replace.

type RequestEnvelope

type RequestEnvelope struct {
	Method string            `json:"method"`
	Path   string            `json:"path"`
	Params map[string]string `json:"params,omitempty"`
	Query  map[string]string `json:"query,omitempty"`
	Body   json.RawMessage   `json:"body,omitempty"`
}

type Resource

type Resource struct {
	Type string `json:"type"`
	ID   string `json:"id"`
}

type Snapshot

type Snapshot struct {
	Files map[string]string `json:"files"`
}

type Store

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

func NewStore

func NewStore(deploymentsPath string) *Store

func (*Store) Delete

func (s *Store) Delete(id string) error

func (*Store) Get

func (s *Store) Get(id string) (*Plan, error)

func (*Store) List

func (s *Store) List(filter ListFilter) ([]*Plan, error)

func (*Store) LockResource

func (s *Store) LockResource(r Resource) func()

LockResource serializes applies on the same resource. Returns the unlock function.

func (*Store) PruneOnce

func (s *Store) PruneOnce(now time.Time, retention time.Duration) int

PruneOnce expires available plans past their TTL, deletes applied and failed plans older than retention, and deletes expired and obsolete plans older than a week. Returns how many files were touched.

func (*Store) Root

func (s *Store) Root() string

func (*Store) Save

func (s *Store) Save(p *Plan) error

Save writes the plan atomically (tmp file + rename, fsynced) so a crash never leaves a torn plan file behind.

func (*Store) StartPruneLoop

func (s *Store) StartPruneLoop(ctx context.Context, interval, retention time.Duration)

type Summary

type Summary struct {
	Create  int `json:"create"`
	Update  int `json:"update"`
	Replace int `json:"replace"`
	Delete  int `json:"delete"`
	NoOp    int `json:"no-op"`
}

Jump to

Keyboard shortcuts

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