config

package
v0.0.0-...-8b8382b Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2019 License: AGPL-3.0 Imports: 31 Imported by: 0

Documentation

Overview

Package config manages persistent configuration data for Chain Core.

Package config is a generated protocol buffer package.

It is generated from these files:

config.proto

It has these top-level messages:

Config
BlockSigner

Index

Constants

View Source
const (
	GrantPrefix = "/core/grant/" // this is also hardcoded in core/authz.go. meh.
)

Variables

View Source
var (
	ErrBadGenerator    = errors.New("generator returned an unsuccessful response")
	ErrBadSignerURL    = errors.New("block signer URL is invalid")
	ErrBadSignerPubkey = errors.New("block signer pubkey is invalid")
	ErrBadQuorum       = errors.New("quorum must be greater than 0 if there are signers")
	ErrNoBlockPub      = errors.New("blockpub cannot be empty in mockhsm disabled build")
	ErrNoBlockHSMURL   = errors.New("block hsm URL cannot be empty in mockhsm disabled build")
	ErrStaleRaftConfig = errors.New("raft core ID doesn't match Postgres core ID")

	Version, BuildCommit, BuildDate string

	// These feature flags are marked as enabled by build tags.
	// See files in $CHAIN/cmd/cored.
	BuildConfig struct {
		LocalhostAuth bool `json:"is_localhost_auth"`
		MockHSM       bool `json:"is_mockhsm"`
		Reset         bool `json:"is_reset"`
		HTTPOk        bool `json:"is_http_ok"`
		InitCluster   bool `json:"is_init_cluster"`
	}
)
View Source
var ErrConfigOp = errors.New("invalid config operation")

Functions

func Configure

func Configure(ctx context.Context, db pg.DB, sdb *sinkdb.DB, httpClient *http.Client, c *Config) error

Configure configures the core by writing to the database. If running in a cored process, the caller must ensure that the new configuration is properly reloaded, for example by restarting the process.

When running a mockhsm enabled server, if c.IsSigner is true and c.BlockPub is empty, Configure generates a new mockhsm keypair for signing blocks, and assigns it to c.BlockPub.

If c.IsGenerator is true, Configure creates an initial block, saves it, and assigns its hash to c.BlockchainId Otherwise, c.IsGenerator is false, and Configure makes a test request to GeneratorUrl to detect simple configuration mistakes.

func HomeDirFromEnvironment

func HomeDirFromEnvironment() string

HomeDirFromEnvironment returns the directory to use for reading config and storing variable data. It returns $CHAIN_CORE_HOME, or, if that is empty, $HOME/.chaincore.

Types

type BlockSigner

type BlockSigner struct {
	AccessToken string `protobuf:"bytes,1,opt,name=access_token,json=accessToken" json:"access_token,omitempty"`
	Pubkey      []byte `protobuf:"bytes,2,opt,name=pubkey,proto3" json:"pubkey,omitempty"`
	Url         string `protobuf:"bytes,3,opt,name=url" json:"url,omitempty"`
}

func (*BlockSigner) Descriptor

func (*BlockSigner) Descriptor() ([]byte, []int)

func (*BlockSigner) GetAccessToken

func (m *BlockSigner) GetAccessToken() string

func (*BlockSigner) GetPubkey

func (m *BlockSigner) GetPubkey() []byte

func (*BlockSigner) GetUrl

func (m *BlockSigner) GetUrl() string

func (*BlockSigner) ProtoMessage

func (*BlockSigner) ProtoMessage()

func (*BlockSigner) Reset

func (m *BlockSigner) Reset()

func (*BlockSigner) String

func (m *BlockSigner) String() string

type CleanFunc

type CleanFunc func(newTuple []string) error

CleanFunc is required when defining a new configuration option. Implementations should validate and canonicalize newTuple in-place.

type Config

type Config struct {
	Id                   string         `protobuf:"bytes,1,opt,name=id" json:"id,omitempty"`
	IsSigner             bool           `protobuf:"varint,2,opt,name=is_signer,json=isSigner" json:"is_signer,omitempty"`
	IsGenerator          bool           `protobuf:"varint,3,opt,name=is_generator,json=isGenerator" json:"is_generator,omitempty"`
	BlockchainId         *bc.Hash       `protobuf:"bytes,4,opt,name=blockchain_id,json=blockchainId" json:"blockchain_id,omitempty"`
	GeneratorUrl         string         `protobuf:"bytes,5,opt,name=generator_url,json=generatorUrl" json:"generator_url,omitempty"`
	GeneratorAccessToken string         `protobuf:"bytes,6,opt,name=generator_access_token,json=generatorAccessToken" json:"generator_access_token,omitempty"`
	BlockHsmUrl          string         `protobuf:"bytes,7,opt,name=block_hsm_url,json=blockHsmUrl" json:"block_hsm_url,omitempty"`
	BlockHsmAccessToken  string         `protobuf:"bytes,8,opt,name=block_hsm_access_token,json=blockHsmAccessToken" json:"block_hsm_access_token,omitempty"`
	ConfiguredAt         uint64         `protobuf:"varint,9,opt,name=configured_at,json=configuredAt" json:"configured_at,omitempty"`
	BlockPub             []byte         `protobuf:"bytes,10,opt,name=block_pub,json=blockPub,proto3" json:"block_pub,omitempty"`
	Signers              []*BlockSigner `protobuf:"bytes,11,rep,name=signers" json:"signers,omitempty"`
	Quorum               uint32         `protobuf:"varint,12,opt,name=quorum" json:"quorum,omitempty"`
	MaxIssuanceWindowMs  uint64         `protobuf:"varint,13,opt,name=max_issuance_window_ms,json=maxIssuanceWindowMs" json:"max_issuance_window_ms,omitempty"`
}

func CheckConfigExists

func CheckConfigExists(ctx context.Context, sdb *sinkdb.DB) (*Config, error)

Loads config status from sinkdb to see if other raft nodes have configured so that uncofigured nodes can update.

func Load

func Load(ctx context.Context, db pg.DB, sdb *sinkdb.DB) (*Config, error)

Load loads the stored configuration, if any, from the database. It will first try to load the config from sinkdb; if that fails, it will try Postgres next. If it finds a config in Postgres but not in sinkdb storage, the config will be added to sinkdb.

func (*Config) Descriptor

func (*Config) Descriptor() ([]byte, []int)

func (*Config) GetBlockHsmAccessToken

func (m *Config) GetBlockHsmAccessToken() string

func (*Config) GetBlockHsmUrl

func (m *Config) GetBlockHsmUrl() string

func (*Config) GetBlockPub

func (m *Config) GetBlockPub() []byte

func (*Config) GetBlockchainId

func (m *Config) GetBlockchainId() *bc.Hash

func (*Config) GetConfiguredAt

func (m *Config) GetConfiguredAt() uint64

func (*Config) GetGeneratorAccessToken

func (m *Config) GetGeneratorAccessToken() string

func (*Config) GetGeneratorUrl

func (m *Config) GetGeneratorUrl() string

func (*Config) GetId

func (m *Config) GetId() string

func (*Config) GetIsGenerator

func (m *Config) GetIsGenerator() bool

func (*Config) GetIsSigner

func (m *Config) GetIsSigner() bool

func (*Config) GetMaxIssuanceWindowMs

func (m *Config) GetMaxIssuanceWindowMs() uint64

func (*Config) GetQuorum

func (m *Config) GetQuorum() uint32

func (*Config) GetSigners

func (m *Config) GetSigners() []*BlockSigner

func (*Config) ProtoMessage

func (*Config) ProtoMessage()

func (*Config) Reset

func (m *Config) Reset()

func (*Config) String

func (m *Config) String() string

type EqualFunc

type EqualFunc func(a, b []string) bool

EqualFunc is required when defining a new set configuration option. Both a and b are guaranteed to have already been cleaned by the option's CleanFunc. It is also guaranteed that len(a) == len(b).

type Options

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

Options provides access to Chain Core configuration options. All options should be defined before accessing and modifying any of their values.

func New

func New(sdb *sinkdb.DB) *Options

func (*Options) Add

func (opts *Options) Add(key string, tup []string) sinkdb.Op

Add adds the provided tuple to the configuration option set indicated by key. If the added tuple conflicts with an existing tuple in the set, Add returns an error describing the conflict.

func (*Options) AddOrUpdate

func (opts *Options) AddOrUpdate(key string, tup []string) sinkdb.Op

AddOrUpdate adds the provided tuple to the configuration option set indicated by key. If the added tuple conflicts with an existing tuple in the set, AddOrUpdate updates the conflicting tuple to the provided tuple.

func (*Options) DefineSet

func (opts *Options) DefineSet(key string, tupleSize int, cleanFunc CleanFunc, equalFunc EqualFunc)

DefineSet defines a new configuration option as a set of tuples of size tupleSize. New tuples will be validated and canonicalized by cleanFunc. Equality when adding and removing is determined by equalFunc.

func (*Options) DefineSingle

func (opts *Options) DefineSingle(key string, tupleSize int, cleanFunc CleanFunc)

DefineSingle defines a new configuration option that takes a single tuple value of size tupleSize. New tuples will be validated and canonicalized by cleanFunc.

func (*Options) Err

func (opts *Options) Err() error

Err returns any persistent errors encountered by ListFunc's closures when retrieving configuration values. If there are multiple errors, it'll return an arbitrary one.

func (*Options) GetFunc

func (opts *Options) GetFunc(key string) func() []string

GetFunc returns a closure that returns the tuple value for the provided key.

The configuration option for key must be defined as a single tuple. GetFunc panics if the provided key is undefined or is defined as a set of tuples.

The returned function performs a stale read of the configuration value. If an error occurs while reading the value, the old value is returned, and the error is saved on the Options type to be returned in Err.

func (*Options) List

func (opts *Options) List(ctx context.Context, key string) ([][]string, error)

List returns all of the tuples for the provided configuration option.

func (*Options) ListFunc

func (opts *Options) ListFunc(key string) func() [][]string

ListFunc returns a closure that returns the set of tuples for the provided key.

The configuration option for key must be a set of tuples. ListFunc panics if the provided key is undefined or is defined as a scalar.

The returned function performs a stale read of the configuration value. If an error occurs while reading the value the old value is returned, and the error is saved on the Options type to be returned in Err.

func (*Options) Remove

func (opts *Options) Remove(key string, tup []string) sinkdb.Op

Remove removes the provided tuple from the configuration option indicated by key. If the option indicated by key takes a single value, tup is unused, and the option's value is cleared regardless of its current value.

func (*Options) Set

func (opts *Options) Set(key string, tup []string) sinkdb.Op

Set updates the configuration option indicated by key with the value tup. If the configuration option is already set, Set will overwrite the existing value.

Directories

Path Synopsis
internal
configpb
Package configpb is a generated protocol buffer package.
Package configpb is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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