clistate

package
v1.0.0-rc5 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2024 License: MPL-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package state exposes common helpers for working with state from the CLI.

This is a separate package so that backends can use this for consistent messaging without creating a circular reference to the command package.

Index

Constants

View Source
const (
	LockThreshold    = 400 * time.Millisecond
	LockErrorMessage = `` /* 272-byte string literal not displayed */

	UnlockErrorMessage = `` /* 719-byte string literal not displayed */

)

Variables

This section is empty.

Functions

This section is empty.

Types

type LocalState

type LocalState struct {
	// Path is the path to read the state from. PathOut is the path to
	// write the state to. If PathOut is not specified, Path will be used.
	// If PathOut already exists, it will be overwritten.
	Path    string
	PathOut string
	// contains filtered or unexported fields
}

LocalState manages a state storage that is local to the filesystem.

func (*LocalState) Lock

func (s *LocalState) Lock(info *statemgr.LockInfo) (string, error)

Lock implements a local filesystem state.Locker.

func (*LocalState) PersistState

func (s *LocalState) PersistState() error

PersistState for LocalState is a no-op since WriteState always persists.

StatePersister impl.

func (*LocalState) RefreshState

func (s *LocalState) RefreshState() error

StateRefresher impl.

func (*LocalState) SetState

func (s *LocalState) SetState(state *tofu.State)

SetState will force a specific state in-memory for this local state.

func (*LocalState) State

func (s *LocalState) State() *tofu.State

StateReader impl.

func (*LocalState) Unlock

func (s *LocalState) Unlock(id string) error

func (*LocalState) WriteState

func (s *LocalState) WriteState(state *tofu.State) error

WriteState for LocalState always persists the state as well. TODO: this should use a more robust method of writing state, by first writing to a temp file on the same filesystem, and renaming the file over the original.

StateWriter impl.

type Locker

type Locker interface {
	// Returns a shallow copy of the locker with its context changed to ctx.
	WithContext(ctx context.Context) Locker

	// Lock the provided state manager, storing the reason string in the LockInfo.
	Lock(s statemgr.Locker, reason string) tfdiags.Diagnostics

	// Unlock the previously locked state.
	Unlock() tfdiags.Diagnostics

	// Timeout returns the configured timeout duration
	Timeout() time.Duration
}

Locker allows for more convenient usage of the lower-level statemgr.Locker implementations. The statemgr.Locker API requires passing in a statemgr.LockInfo struct. Locker implementations are expected to create the required LockInfo struct when Lock is called, populate the Operation field with the "reason" string provided, and pass that on to the underlying statemgr.Locker. Locker implementations are also expected to store any state required to call Unlock, which is at a minimum the LockID string returned by the statemgr.Locker.

func NewLocker

func NewLocker(timeout time.Duration, view views.StateLocker) Locker

Create a new Locker. This Locker uses state.LockWithContext to retry the lock until the provided timeout is reached, or the context is canceled. Lock progress will be be reported to the user through the provided UI.

func NewNoopLocker

func NewNoopLocker() Locker

NewNoopLocker returns a valid Locker that does nothing.

Jump to

Keyboard shortcuts

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