ipfs-cluster: github.com/ipfs/ipfs-cluster/config Index | Files

package config

import "github.com/ipfs/ipfs-cluster/config"

Package config provides interfaces and utilities for different Cluster components to register, read, write and validate configuration sections stored in a central configuration file.

Index

Package Files

config.go identity.go util.go

Constants

const (
    DefaultConfigCrypto    = crypto.Ed25519
    DefaultConfigKeyLength = -1
)

Identity defaults

Variables

var ConfigSaveInterval = time.Second

ConfigSaveInterval specifies how often to save the configuration file if it needs saving.

func DefaultJSONMarshal Uses

func DefaultJSONMarshal(v interface{}) ([]byte, error)

DefaultJSONMarshal produces pretty JSON with 2-space indentation

func DisplayJSON Uses

func DisplayJSON(cfg interface{}) ([]byte, error)

DisplayJSON takes pointer to a JSON-friendly configuration struct and returns the JSON-encoded representation of it filtering out any struct fields marked with the tag `hidden:"true"`, but keeping fields marked with `"json:omitempty"`.

func GetClusterConfig Uses

func GetClusterConfig(configPath string) ([]byte, error)

GetClusterConfig extracts cluster config from the configuration file and returns bytes of it

func IsErrFetchingSource Uses

func IsErrFetchingSource(err error) bool

IsErrFetchingSource reports whether this error happened when trying to fetch a remote configuration source (as opposed to an error parsing the config).

func ParseDurations Uses

func ParseDurations(component string, args ...*DurationOpt) error

ParseDurations takes a time.Duration src and saves it to the given dst.

func SetIfNotDefault Uses

func SetIfNotDefault(src interface{}, dest interface{})

SetIfNotDefault sets dest to the value of src if src is not the default value of the type. dest must be a pointer.

type ComponentConfig Uses

type ComponentConfig interface {
    // Returns a string identifying the section name for this configuration
    ConfigKey() string
    // Parses a JSON representation of this configuration
    LoadJSON([]byte) error
    // Provides a JSON representation of this configuration
    ToJSON() ([]byte, error)
    // Sets default working values
    Default() error
    // Sets values from environment variables
    ApplyEnvVars() error
    // Allows this component to work under a subfolder
    SetBaseDir(string)
    // Checks that the configuration is valid
    Validate() error
    // Provides a channel to signal the Manager that the configuration
    // should be persisted.
    SaveCh() <-chan struct{}
    // ToDisplayJSON returns a string representing the config excluding hidden fields.
    ToDisplayJSON() ([]byte, error)
}

The ComponentConfig interface allows components to define configurations which can be managed as part of the ipfs-cluster configuration file by the Manager.

type DurationOpt Uses

type DurationOpt struct {
    // The duration we need to parse
    Duration string
    // Where to store the result
    Dst *time.Duration
    // A variable name associated to it for helpful errors.
    Name string
}

DurationOpt provides a datatype to use with ParseDurations

type Identity Uses

type Identity struct {
    ID         peer.ID
    PrivateKey crypto.PrivKey
}

Identity represents identity of a cluster peer for communication, including the Consensus component.

func NewIdentity Uses

func NewIdentity() (*Identity, error)

NewIdentity returns a new random identity.

func (*Identity) ApplyEnvVars Uses

func (ident *Identity) ApplyEnvVars() error

ApplyEnvVars fills in any Config fields found as environment variables.

func (*Identity) ConfigKey Uses

func (ident *Identity) ConfigKey() string

ConfigKey returns a human-readable string to identify a cluster Identity.

func (*Identity) Default Uses

func (ident *Identity) Default() error

Default generates a random keypair for this identity.

func (*Identity) Equals Uses

func (ident *Identity) Equals(i *Identity) bool

Equals returns true if equal to provided identity.

func (*Identity) LoadJSON Uses

func (ident *Identity) LoadJSON(raw []byte) error

LoadJSON receives a raw json-formatted identity and sets the Config fields from it. Note that it should be JSON as generated by ToJSON().

func (*Identity) LoadJSONFromFile Uses

func (ident *Identity) LoadJSONFromFile(path string) error

LoadJSONFromFile reads an Identity file from disk and parses it and return Identity.

func (*Identity) SaveJSON Uses

func (ident *Identity) SaveJSON(path string) error

SaveJSON saves the JSON representation of the Identity to the given path.

func (*Identity) ToJSON Uses

func (ident *Identity) ToJSON() (raw []byte, err error)

ToJSON generates a human-friendly version of Identity.

func (*Identity) Validate Uses

func (ident *Identity) Validate() error

Validate will check that the values of this identity seem to be working ones.

type Manager Uses

type Manager struct {

    // stores original source if any
    Source string
    // contains filtered or unexported fields
}

Manager represents an ipfs-cluster configuration which bundles different ComponentConfigs object together. Use RegisterComponent() to add a component configurations to the object. Once registered, configurations will be parsed from the central configuration file when doing LoadJSON(), and saved to it when doing SaveJSON().

func NewManager Uses

func NewManager() *Manager

NewManager returns a correctly initialized Manager which is ready to accept component configurations.

func (*Manager) ApplyEnvVars Uses

func (cfg *Manager) ApplyEnvVars() error

ApplyEnvVars overrides configuration fields with any values found in environment variables.

func (*Manager) Default Uses

func (cfg *Manager) Default() error

Default generates a default configuration by generating defaults for all registered components.

func (*Manager) IsLoadedFromJSON Uses

func (cfg *Manager) IsLoadedFromJSON(t SectionType, name string) bool

IsLoadedFromJSON tells whether the given component belonging to the given section type is present in the cluster JSON config or not.

func (*Manager) LoadJSON Uses

func (cfg *Manager) LoadJSON(bs []byte) error

LoadJSON parses configurations for all registered components, In order to work, component configurations must have been registered beforehand with RegisterComponent.

func (*Manager) LoadJSONFileAndEnv Uses

func (cfg *Manager) LoadJSONFileAndEnv(path string) error

LoadJSONFileAndEnv calls LoadJSONFromFile followed by ApplyEnvVars, reading and parsing a Configuration file and then overriding fields with any values found in environment variables.

func (*Manager) LoadJSONFromFile Uses

func (cfg *Manager) LoadJSONFromFile(path string) error

LoadJSONFromFile reads a Configuration file from disk and parses it. See LoadJSON too.

func (*Manager) LoadJSONFromHTTPSource Uses

func (cfg *Manager) LoadJSONFromHTTPSource(url string) error

LoadJSONFromHTTPSource reads a Configuration file from a URL and parses it.

func (*Manager) RegisterComponent Uses

func (cfg *Manager) RegisterComponent(t SectionType, ccfg ComponentConfig)

RegisterComponent lets the Manager load and save component configurations

func (*Manager) SaveJSON Uses

func (cfg *Manager) SaveJSON(path string) error

SaveJSON saves the JSON representation of the Config to the given path.

func (*Manager) Shutdown Uses

func (cfg *Manager) Shutdown()

Shutdown makes sure all configuration save operations are finished before returning.

func (*Manager) ToDisplayJSON Uses

func (cfg *Manager) ToDisplayJSON() ([]byte, error)

ToDisplayJSON returns a printable cluster configuration.

func (*Manager) ToJSON Uses

func (cfg *Manager) ToJSON() ([]byte, error)

ToJSON provides a JSON representation of the configuration by generating JSON for all componenents registered.

func (*Manager) Validate Uses

func (cfg *Manager) Validate() error

Validate checks that all the registered components in this Manager have valid configurations. It also makes sure that the main Cluster compoenent exists.

type Saver Uses

type Saver struct {
    BaseDir string
    // contains filtered or unexported fields
}

Saver implements common functionality useful for ComponentConfigs

func (*Saver) NotifySave Uses

func (sv *Saver) NotifySave()

NotifySave signals the SaveCh() channel in a non-blocking fashion.

func (*Saver) SaveCh Uses

func (sv *Saver) SaveCh() <-chan struct{}

SaveCh returns a channel which is signaled when a component wants to persist its configuration

func (*Saver) SetBaseDir Uses

func (sv *Saver) SetBaseDir(dir string)

SetBaseDir is a setter for BaseDir and implements part of the ComponentConfig interface.

type Section Uses

type Section map[string]ComponentConfig

Section is a section of which stores component-specific configurations.

type SectionType Uses

type SectionType int

SectionType specifies to which section a component configuration belongs.

const (
    Cluster SectionType = iota
    Consensus
    API
    IPFSConn
    State
    PinTracker
    Monitor
    Allocator
    Informer
    Observations
    Datastore
)

These are the component configuration types supported by the Manager.

func SectionTypes Uses

func SectionTypes() []SectionType

SectionTypes returns the list of supported SectionTypes

Package config imports 16 packages (graph) and is imported by 13 packages. Updated 2020-06-05. Refresh now. Tools for package owners.