config

package
v0.0.2-alpha3 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2018 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ErrConfigBootstrap used as default error type
	ErrConfigBootstrap = errors.Error("error when bootstrapping config")

	// ErrConfigFileBootstrapNotFound used when config file is not found
	ErrConfigFileBootstrapNotFound = errors.Error("config file hasn't been provided")
)
View Source
const (
	BootstrappedConfigFile string = "BootstrappedConfigFile"
)

Bootstrap constants are keys to the value mappings in context bootstrap.

Variables

This section is empty.

Functions

func CreateConfigFile

func CreateConfigFile(args map[string]interface{}) (*viper.Viper, error)

CreateConfigFile creates minimum config file with arguments

Types

type AccountConfig

type AccountConfig struct {
	Address  string
	Key      string
	Password string
}

AccountConfig holds the account details.

type Bootstrapper

type Bootstrapper struct{}

Bootstrapper implements bootstrap.Bootstrapper to initialise config package.

func (*Bootstrapper) Bootstrap

func (*Bootstrapper) Bootstrap(context map[string]interface{}) error

Bootstrap takes the passed in config file, loads the config and puts the config back into context.

type Configuration

type Configuration interface {
	// generic methods
	IsSet(key string) bool
	Set(key string, value interface{})
	SetDefault(key string, value interface{})
	Get(key string) interface{}
	GetString(key string) string
	GetBool(key string) bool
	GetInt(key string) int
	GetDuration(key string) time.Duration

	GetStoragePath() string
	GetConfigStoragePath() string
	GetP2PPort() int
	GetP2PExternalIP() string
	GetP2PConnectionTimeout() time.Duration
	GetServerPort() int
	GetServerAddress() string
	GetNumWorkers() int
	GetWorkerWaitTimeMS() int
	GetEthereumNodeURL() string
	GetEthereumContextReadWaitTimeout() time.Duration
	GetEthereumContextWaitTimeout() time.Duration
	GetEthereumIntervalRetry() time.Duration
	GetEthereumMaxRetries() int
	GetEthereumGasPrice() *big.Int
	GetEthereumGasLimit() uint64
	GetTxPoolAccessEnabled() bool
	GetNetworkString() string
	GetNetworkKey(k string) string
	GetContractAddressString(address string) string
	GetContractAddress(address string) common.Address
	GetBootstrapPeers() []string
	GetNetworkID() uint32

	// CentID specific configs (eg: for multi tenancy)
	GetEthereumAccount(accountName string) (account *AccountConfig, err error)
	GetEthereumDefaultAccountName() string
	GetReceiveEventNotificationEndpoint() string
	GetIdentityID() ([]byte, error)
	GetSigningKeyPair() (pub, priv string)
	GetEthAuthKeyPair() (pub, priv string)

	// debug specific methods
	IsPProfEnabled() bool
}

Configuration defines the methods that a config type should implement.

func LoadConfiguration

func LoadConfiguration(configFile string) Configuration

LoadConfiguration loads the configuration from the given file.

type KeyPair

type KeyPair struct {
	Pub, Priv string
}

KeyPair represents a key pair config

func NewKeyPair

func NewKeyPair(pub, priv string) KeyPair

NewKeyPair creates a KeyPair

type Model

type Model interface {
	// Get the ID of the document represented by this model
	ID() ([]byte, error)

	//Returns the underlying type of the Model
	Type() reflect.Type

	// JSON return the json representation of the model
	JSON() ([]byte, error)

	// FromJSON initialize the model with a json
	FromJSON(json []byte) error
}

Model is an interface for both tenant and node config models

type NodeConfig

type NodeConfig struct {
	StoragePath                    string
	P2PPort                        int
	P2PExternalIP                  string
	P2PConnectionTimeout           time.Duration
	ServerPort                     int
	ServerAddress                  string
	NumWorkers                     int
	WorkerWaitTimeMS               int
	EthereumNodeURL                string
	EthereumContextReadWaitTimeout time.Duration
	EthereumContextWaitTimeout     time.Duration
	EthereumIntervalRetry          time.Duration
	EthereumMaxRetries             int
	EthereumGasPrice               *big.Int
	EthereumGasLimit               uint64
	TxPoolAccessEnabled            bool
	NetworkString                  string
	BootstrapPeers                 []string
	NetworkID                      uint32
}

NodeConfig exposes configs specific to the node

func NewNodeConfig

func NewNodeConfig(config Configuration) *NodeConfig

NewNodeConfig creates a new NodeConfig instance with configs

func (*NodeConfig) FromJSON

func (nc *NodeConfig) FromJSON(data []byte) error

FromJSON initialize the model with a json

func (*NodeConfig) ID

func (nc *NodeConfig) ID() ([]byte, error)

ID Gets the ID of the document represented by this model

func (*NodeConfig) JSON

func (nc *NodeConfig) JSON() ([]byte, error)

JSON return the json representation of the model

func (*NodeConfig) Type

func (nc *NodeConfig) Type() reflect.Type

Type Returns the underlying type of the Model

type Repository

type Repository interface {
	// Get returns the tenant config Model associated with tenant ID
	GetTenant(id []byte) (Model, error)

	// GetConfig returns the node config model
	GetConfig() (Model, error)

	// GetAllTenants returns a list of all tenant models in the config DB
	GetAllTenants() ([]Model, error)

	// Create creates the tenant config model if not present in the DB.
	// should error out if the config exists.
	CreateTenant(id []byte, model Model) error

	// Create creates the node config model if not present in the DB.
	// should error out if the config exists.
	CreateConfig(model Model) error

	// Update strictly updates the tenant config model.
	// Will error out when the config model doesn't exist in the DB.
	UpdateTenant(id []byte, model Model) error

	// Update strictly updates the node config model.
	// Will error out when the config model doesn't exist in the DB.
	UpdateConfig(model Model) error

	// Delete deletes tenant config
	// Will not error out when config model doesn't exists in DB
	DeleteTenant(id []byte) error

	// Delete deletes node config
	// Will not error out when config model doesn't exists in DB
	DeleteConfig() error

	// Register registers the model so that the DB can return the config without knowing the type
	Register(model Model)
}

Repository defines the required methods for the config repository.

func NewLevelDBRepository

func NewLevelDBRepository(db *leveldb.DB) Repository

NewLevelDBRepository returns levelDb implementation of Repository

type SmartContractAddresses

type SmartContractAddresses struct {
	IdentityFactoryAddr, IdentityRegistryAddr, AnchorRepositoryAddr, PaymentObligationAddr string
}

SmartContractAddresses encapsulates the smart contract addresses ne

type TenantConfig

type TenantConfig struct {
	EthereumAccount                  *AccountConfig
	EthereumDefaultAccountName       string
	ReceiveEventNotificationEndpoint string
	IdentityID                       []byte
	SigningKeyPair                   KeyPair
	EthAuthKeyPair                   KeyPair
}

TenantConfig exposes configs specific to a tenant in the node

func NewTenantConfig

func NewTenantConfig(ethAccountName string, config Configuration) (*TenantConfig, error)

NewTenantConfig creates a new TenantConfig instance with configs

func (*TenantConfig) FromJSON

func (tc *TenantConfig) FromJSON(data []byte) error

FromJSON initialize the model with a json

func (*TenantConfig) ID

func (tc *TenantConfig) ID() ([]byte, error)

ID Get the ID of the document represented by this model

func (*TenantConfig) JSON

func (tc *TenantConfig) JSON() ([]byte, error)

JSON return the json representation of the model

func (*TenantConfig) Type

func (tc *TenantConfig) Type() reflect.Type

Type Returns the underlying type of the Model

Jump to

Keyboard shortcuts

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