confdbstate

package
v0.0.0-...-bc60ea4 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get(st *state.State, account, confdbName, viewName string, fields []string) (interface{}, error)

Get finds the view identified by the account, confdb and view names and uses it to get the values for the specified fields. The results are returned in a map of fields to their values, unless there are no fields in which case case all views are returned.

func GetTransactionToModify

func GetTransactionToModify(ctx *hookstate.Context, st *state.State, view *confdb.View) (*Transaction, CommitTxFunc, error)

GetTransactionToModify retrieves or creates a transaction to change the view's confdb. The state must be locked by the caller. Takes a hookstate.Context if invoked in a hook. If a new transaction was created, also returns a CommitTxFunc to be called to start committing (which in turn returns a change ID and a wait channel that will be closed on the commit is done). If a transaction already existed, changes to it will be saved on ctx.Done().

func GetViaView

func GetViaView(bag confdb.DataBag, view *confdb.View, fields []string) (interface{}, error)

GetViaView uses the view to get values for the fields from the databag in the transaction.

func GetView

func GetView(st *state.State, account, confdbName, viewName string) (*confdb.View, error)

GetView returns the view identified by the account, confdb and view name.

func IsConfdbHook

func IsConfdbHook(ctx *hookstate.Context) bool

IsConfdbHook returns whether the hook context belongs to a confdb hook.

func Set

func Set(st *state.State, account, confdbName, viewName string, requests map[string]interface{}) error

Set finds the view identified by the account, confdb and view names and sets the request fields to their respective values.

func SetViaView

func SetViaView(bag confdb.DataBag, view *confdb.View, requests map[string]interface{}) error

SetViaView uses the view to set the requests in the transaction's databag.

Types

type CommitTxFunc

type CommitTxFunc func() (changeID string, waitChan <-chan struct{}, err error)

type ConfdbManager

type ConfdbManager struct{}

func Manager

func Manager(st *state.State, hookMgr *hookstate.HookManager, runner *state.TaskRunner) *ConfdbManager

func (*ConfdbManager) Ensure

func (m *ConfdbManager) Ensure() error

type Transaction

type Transaction struct {
	ConfdbAccount string
	ConfdbName    string
	// contains filtered or unexported fields
}

Transaction performs read and writes to a databag in an atomic way.

func GetStoredTransaction

func GetStoredTransaction(t *state.Task) (tx *Transaction, saveTxChanges func(), err error)

GetStoredTransaction returns the transaction associated with the task (even if indirectly) and a callback to persist changes made to it.

func NewTransaction

func NewTransaction(st *state.State, account, confdbName string) (*Transaction, error)

NewTransaction takes a getter and setter to read and write the databag.

func (*Transaction) Abort

func (t *Transaction) Abort(abortingSnap, reason string)

Abort prevents any further writes or reads to the transaction. It takes a snap and reason that can be used to surface information to the user.

func (*Transaction) AbortInfo

func (t *Transaction) AbortInfo() (snap, reason string)

func (*Transaction) AlteredPaths

func (t *Transaction) AlteredPaths() []string

func (*Transaction) Clear

func (t *Transaction) Clear(st *state.State) error

func (*Transaction) Commit

func (t *Transaction) Commit(st *state.State, schema confdb.Schema) error

Commit applies the previous writes and validates the final databag. If any error occurs, the original databag is kept.

func (*Transaction) Data

func (t *Transaction) Data() ([]byte, error)

Data returns the transaction's committed data.

func (*Transaction) Get

func (t *Transaction) Get(path string) (interface{}, error)

Get reads a value from the transaction's databag including uncommitted changes.

func (*Transaction) MarshalJSON

func (t *Transaction) MarshalJSON() ([]byte, error)

func (*Transaction) Pristine

func (t *Transaction) Pristine() confdb.DataBag

func (*Transaction) Set

func (t *Transaction) Set(path string, value interface{}) error

Set sets a value in the transaction's databag. The change isn't persisted until Commit returns without errors.

func (*Transaction) UnmarshalJSON

func (t *Transaction) UnmarshalJSON(data []byte) error

func (*Transaction) Unset

func (t *Transaction) Unset(path string) error

Unset unsets a value in the transaction's databag. The change isn't persisted until Commit returns without errors.

Jump to

Keyboard shortcuts

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