config

package
v0.0.0-...-f6d5d5b Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2021 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteSnapConfig

func DeleteSnapConfig(st *state.State, snapName string) error

DeleteSnapConfig removed configuration of given snap from the state.

func DiscardRevisionConfig

func DiscardRevisionConfig(st *state.State, snapName string, rev snap.Revision) error

DiscardRevisionConfig removes configuration snapshot of given snap/revision. If no configuration exists for given revision it does nothing (no error). The caller is responsible for locking the state.

func GetSnapConfig

func GetSnapConfig(st *state.State, snapName string) (*json.RawMessage, error)

GetSnapConfig retrieves the raw configuration of a given snap.

func IsNoOption

func IsNoOption(err error) bool

IsNoOption returns whether the provided error is a *NoOptionError.

func ParseKey

func ParseKey(key string) (subkeys []string, err error)

func Patch

func Patch(cfg Conf, snapName string, patch map[string]interface{}) error

Patch sets values in cfg for the provided snap's configuration based on patch. patch keys can be dotted as the key argument to Set. The patch is applied according to the order of its keys sorted by depth, with top keys sorted first.

func PatchConfig

func PatchConfig(snapName string, subkeys []string, pos int, config interface{}, value *json.RawMessage) (interface{}, error)

func RestoreRevisionConfig

func RestoreRevisionConfig(st *state.State, snapName string, rev snap.Revision) error

RestoreRevisionConfig restores a given revision of snap configuration into config -> snapName. If no configuration exists for given revision it does nothing (no error). The caller is responsible for locking the state.

func SaveRevisionConfig

func SaveRevisionConfig(st *state.State, snapName string, rev snap.Revision) error

SaveRevisionConfig makes a copy of config -> snapSnape configuration into the versioned config. It doesn't do anything if there is no configuration for given snap in the state. The caller is responsible for locking the state.

func SetSnapConfig

func SetSnapConfig(st *state.State, snapName string, snapcfg *json.RawMessage) error

SetSnapConfig replaces the configuration of a given snap.

Types

type Conf

type Conf interface {
	Get(snapName, key string, result interface{}) error
	GetMaybe(snapName, key string, result interface{}) error
	GetPristine(snapName, key string, result interface{}) error
	Set(snapName, key string, value interface{}) error
	Changes() []string
	State() *state.State
}

Conf is an interface describing both state and transaction.

type ConfGetter

type ConfGetter interface {
	Get(snapName, key string, result interface{}) error
	GetMaybe(snapName, key string, result interface{}) error
	GetPristine(snapName, key string, result interface{}) error
}

ConfGetter is an interface for reading of config values.

type NoOptionError

type NoOptionError struct {
	SnapName string
	Key      string
}

NoOptionError indicates that a config option is not set.

func (*NoOptionError) Error

func (e *NoOptionError) Error() string

type Transaction

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

Transaction holds a copy of the configuration originally present in the provided state which can be queried and mutated in isolation from concurrent logic. All changes performed into it are persisted back into the state at once when Commit is called.

Transactions are safe to access and modify concurrently.

func NewTransaction

func NewTransaction(st *state.State) *Transaction

NewTransaction creates a new configuration transaction initialized with the given state.

The provided state must be locked by the caller.

func (*Transaction) Changes

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

Changes returns the changing keys associated with this transaction

func (*Transaction) Commit

func (t *Transaction) Commit()

Commit applies to the state the configuration changes made in the transaction and updates the observed configuration to the result of the operation.

The state associated with the transaction must be locked by the caller.

func (*Transaction) Get

func (t *Transaction) Get(snapName, key string, result interface{}) error

Get unmarshals into result the cached value of the provided snap's configuration key. If the key does not exist, an error of type *NoOptionError is returned. The provided key may be formed as a dotted key path through nested maps. For example, the "a.b.c" key describes the {a: {b: {c: value}}} map.

Transactions do not see updates from the current state or from other transactions.

func (*Transaction) GetMaybe

func (t *Transaction) GetMaybe(instanceName, key string, result interface{}) error

GetMaybe unmarshals into result the cached value of the provided snap's configuration key. If the key does not exist, no error is returned.

Transactions do not see updates from the current state or from other transactions.

func (*Transaction) GetPristine

func (t *Transaction) GetPristine(snapName, key string, result interface{}) error

GetPristine unmarshals the cached pristine (before applying any changes) value of the provided snap's configuration key into result.

If the key does not exist, an error of type *NoOptionError is returned.

func (*Transaction) GetPristineMaybe

func (t *Transaction) GetPristineMaybe(instanceName, key string, result interface{}) error

GetPristineMaybe unmarshals the cached pristine (before applying any changes) value of the provided snap's configuration key into result.

If the key does not exist, no error is returned.

func (*Transaction) Set

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

Set sets the provided snap's configuration key to the given value. The provided key may be formed as a dotted key path through nested maps. For example, the "a.b.c" key describes the {a: {b: {c: value}}} map. When the key is provided in that form, intermediate maps are mutated rather than replaced, and created when necessary.

The provided value must marshal properly by encoding/json. Changes are not persisted until Commit is called.

func (*Transaction) State

func (t *Transaction) State() *state.State

State returns the system State

Jump to

Keyboard shortcuts

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