gconf

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2019 License: Apache-2.0 Imports: 4 Imported by: 9

Documentation

Overview

Package gconf provides a toolset for managing an extension configuration.

Extension that defines a configuration object can use gconf package to load initial state from genesis, update configuration state via messages and to retrieve configuration object from the store.

Each extension can declare and store only one configuration object.

To use gconf you must follow a few simple principles.

1. Define your configuration as a protobuf message.

2. Define your configuration update message as a protobuf message. It must have a `patch` field that holds the new configuration state.

3. Zero field values are ignored during the update message processing,

4. use `InitConfig` inside of your extension initializer to copy configuration from the genesis into the database,

5. Use `Load` function to load your configuration state from the database,

See existing extensions for an example of how to use this package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitConfig added in v0.15.0

func InitConfig(db Store, opts weave.Options, pkg string, conf Configuration) error

InitConfig will take opts["conf"][pkg], parse it into the given Configuration object validate it, and store under the proper key in the database Returns an error if anything goes wrong

func Load added in v0.15.0

func Load(db Store, pkg string, dst Unmarshaler) error

func Save added in v0.15.0

func Save(db Store, pkg string, src ValidMarshaler) error

Save will Validate the object, before writing it to a special "configuration" singleton for that package name.

Types

type Configuration added in v0.15.0

type Configuration interface {
	ValidMarshaler
	Unmarshaler
}

type OwnedConfig added in v0.15.0

type OwnedConfig interface {
	Unmarshaler
	ValidMarshaler
	GetOwner() weave.Address
}

OwnedConfig must have an Owner field in protobuf. A configuration update message must be signed by an owner in order to be authorized to apply the change.

type Store

type Store interface {
	Get([]byte) ([]byte, error)
	Set([]byte, []byte) error
}

Store is a subset of weave.KVStore.

type Unmarshaler added in v0.15.0

type Unmarshaler interface {
	Unmarshal([]byte) error
}

Unmarshaler is implemented by object that can load their state from given binary representation. This interface is implemented by all protobuf messages.

type UpdateConfigurationHandler added in v0.15.0

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

func NewUpdateConfigurationHandler added in v0.15.0

func NewUpdateConfigurationHandler(pkg string, config OwnedConfig, auth x.Authenticator) UpdateConfigurationHandler

func (UpdateConfigurationHandler) Check added in v0.15.0

func (UpdateConfigurationHandler) Deliver added in v0.15.0

type ValidMarshaler added in v0.15.0

type ValidMarshaler interface {
	Marshal() ([]byte, error)
	Validate() error
}

ValidMarshaler is implemented by object that can serialize itself to a binary representation. Marshal is implemented by all protobuf messages. You must add your own Validate method

Note duplicate of code in x/persistent.go

Jump to

Keyboard shortcuts

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