Implement ApplyEnvVars for all ComponentConfigs
License: MIT Signed-off-by: Robert Ignat <robert.ignat91@gmail.com>
This commit is contained in:
parent
ed30ac1ab4
commit
032f02802f
|
@ -157,8 +157,14 @@ func (cfg *Config) Default() error {
|
|||
// ApplyEnvVars fills in any Config fields found
|
||||
// as environment variables.
|
||||
func (cfg *Config) ApplyEnvVars() error {
|
||||
// doesn't read any config from env
|
||||
return nil
|
||||
jcfg := &jsonConfig{}
|
||||
|
||||
err := envconfig.Process(envConfigKey, jcfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return cfg.applyJSONConfig(jcfg)
|
||||
}
|
||||
|
||||
// Validate checks that the fields of this Config have sensible values,
|
||||
|
@ -217,12 +223,10 @@ func (cfg *Config) LoadJSON(raw []byte) error {
|
|||
return fmt.Errorf("error setting config to default values: %s", err)
|
||||
}
|
||||
|
||||
// override json config with env var
|
||||
err = envconfig.Process("cluster_ipfsproxy", jcfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return cfg.applyJSONConfig(jcfg)
|
||||
}
|
||||
|
||||
func (cfg *Config) applyJSONConfig(jcfg *jsonConfig) error {
|
||||
proxyAddr, err := ma.NewMultiaddr(jcfg.ListenMultiaddress)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error parsing proxy listen_multiaddress: %s", err)
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
|
||||
"github.com/ipfs/ipfs-cluster/api"
|
||||
"github.com/ipfs/ipfs-cluster/config"
|
||||
"github.com/kelseyhightower/envconfig"
|
||||
|
||||
hraft "github.com/hashicorp/raft"
|
||||
peer "github.com/libp2p/go-libp2p-peer"
|
||||
|
@ -17,6 +18,7 @@ import (
|
|||
// ConfigKey is the default configuration key for holding this component's
|
||||
// configuration section.
|
||||
var configKey = "raft"
|
||||
var envConfigKey = "cluster_raft"
|
||||
|
||||
// Configuration defaults
|
||||
var (
|
||||
|
@ -185,6 +187,10 @@ func (cfg *Config) LoadJSON(raw []byte) error {
|
|||
|
||||
cfg.Default()
|
||||
|
||||
return cfg.applyJSONConfig(jcfg)
|
||||
}
|
||||
|
||||
func (cfg *Config) applyJSONConfig(jcfg *jsonConfig) error {
|
||||
parseDuration := func(txt string) time.Duration {
|
||||
d, _ := time.ParseDuration(txt)
|
||||
if txt != "" && d == 0 {
|
||||
|
@ -275,8 +281,14 @@ func (cfg *Config) Default() error {
|
|||
// ApplyEnvVars fills in any Config fields found
|
||||
// as environment variables.
|
||||
func (cfg *Config) ApplyEnvVars() error {
|
||||
// doesn't read any config from env
|
||||
return nil
|
||||
jcfg := &jsonConfig{}
|
||||
|
||||
err := envconfig.Process(envConfigKey, jcfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return cfg.applyJSONConfig(jcfg)
|
||||
}
|
||||
|
||||
// GetDataFolder returns the Raft data folder that we are using.
|
||||
|
|
|
@ -6,9 +6,11 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/ipfs/ipfs-cluster/config"
|
||||
"github.com/kelseyhightower/envconfig"
|
||||
)
|
||||
|
||||
const configKey = "disk"
|
||||
const envConfigKey = "cluster_disk"
|
||||
|
||||
// Default values for disk Config
|
||||
const (
|
||||
|
@ -56,8 +58,14 @@ func (cfg *Config) Default() error {
|
|||
// ApplyEnvVars fills in any Config fields found
|
||||
// as environment variables.
|
||||
func (cfg *Config) ApplyEnvVars() error {
|
||||
// doesn't read any config from env
|
||||
return nil
|
||||
jcfg := &jsonConfig{}
|
||||
|
||||
err := envconfig.Process(envConfigKey, jcfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return cfg.applyJSONConfig(jcfg)
|
||||
}
|
||||
|
||||
// Validate checks that the fields of this Config have working values,
|
||||
|
@ -83,6 +91,12 @@ func (cfg *Config) LoadJSON(raw []byte) error {
|
|||
return err
|
||||
}
|
||||
|
||||
cfg.Default()
|
||||
|
||||
return cfg.applyJSONConfig(jcfg)
|
||||
}
|
||||
|
||||
func (cfg *Config) applyJSONConfig(jcfg *jsonConfig) error {
|
||||
t, _ := time.ParseDuration(jcfg.MetricTTL)
|
||||
cfg.MetricTTL = t
|
||||
|
||||
|
|
|
@ -6,9 +6,11 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/ipfs/ipfs-cluster/config"
|
||||
"github.com/kelseyhightower/envconfig"
|
||||
)
|
||||
|
||||
const configKey = "numpin"
|
||||
const envConfigKey = "cluster_numpin"
|
||||
|
||||
// These are the default values for a Config.
|
||||
const (
|
||||
|
@ -41,8 +43,14 @@ func (cfg *Config) Default() error {
|
|||
// ApplyEnvVars fills in any Config fields found
|
||||
// as environment variables.
|
||||
func (cfg *Config) ApplyEnvVars() error {
|
||||
// doesn't read any config from env
|
||||
return nil
|
||||
jcfg := &jsonConfig{}
|
||||
|
||||
err := envconfig.Process(envConfigKey, jcfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return cfg.applyJSONConfig(jcfg)
|
||||
}
|
||||
|
||||
// Validate checks that the fields of this configuration have
|
||||
|
@ -63,6 +71,12 @@ func (cfg *Config) LoadJSON(raw []byte) error {
|
|||
return err
|
||||
}
|
||||
|
||||
cfg.Default()
|
||||
|
||||
return cfg.applyJSONConfig(jcfg)
|
||||
}
|
||||
|
||||
func (cfg *Config) applyJSONConfig(jcfg *jsonConfig) error {
|
||||
t, _ := time.ParseDuration(jcfg.MetricTTL)
|
||||
cfg.MetricTTL = t
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
)
|
||||
|
||||
const configKey = "ipfshttp"
|
||||
const envConfigKey = "cluster_ipfshttp"
|
||||
|
||||
// Default values for Config.
|
||||
const (
|
||||
|
@ -140,6 +141,10 @@ func (cfg *Config) LoadJSON(raw []byte) error {
|
|||
|
||||
cfg.Default()
|
||||
|
||||
return cfg.applyJSONConfig(jcfg)
|
||||
}
|
||||
|
||||
func (cfg *Config) applyJSONConfig(jcfg *jsonConfig) error {
|
||||
nodeAddr, err := ma.NewMultiaddr(jcfg.NodeMultiaddress)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error parsing ipfs_node_multiaddress: %s", err)
|
||||
|
|
|
@ -6,9 +6,11 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/ipfs/ipfs-cluster/config"
|
||||
"github.com/kelseyhightower/envconfig"
|
||||
)
|
||||
|
||||
const configKey = "monbasic"
|
||||
const envConfigKey = "cluster_monbasic"
|
||||
|
||||
// Default values for this Config.
|
||||
const (
|
||||
|
@ -40,8 +42,14 @@ func (cfg *Config) Default() error {
|
|||
// ApplyEnvVars fills in any Config fields found
|
||||
// as environment variables.
|
||||
func (cfg *Config) ApplyEnvVars() error {
|
||||
// doesn't read any config from env
|
||||
return nil
|
||||
jcfg := &jsonConfig{}
|
||||
|
||||
err := envconfig.Process(envConfigKey, jcfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return cfg.applyJSONConfig(jcfg)
|
||||
}
|
||||
|
||||
// Validate checks that the fields of this Config have working values,
|
||||
|
@ -63,6 +71,12 @@ func (cfg *Config) LoadJSON(raw []byte) error {
|
|||
return err
|
||||
}
|
||||
|
||||
cfg.Default()
|
||||
|
||||
return cfg.applyJSONConfig(jcfg)
|
||||
}
|
||||
|
||||
func (cfg *Config) applyJSONConfig(jcfg *jsonConfig) error {
|
||||
interval, _ := time.ParseDuration(jcfg.CheckInterval)
|
||||
cfg.CheckInterval = interval
|
||||
|
||||
|
|
|
@ -6,9 +6,11 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/ipfs/ipfs-cluster/config"
|
||||
"github.com/kelseyhightower/envconfig"
|
||||
)
|
||||
|
||||
const configKey = "pubsubmon"
|
||||
const envConfigKey = "cluster_pubsubmon"
|
||||
|
||||
// Default values for this Config.
|
||||
const (
|
||||
|
@ -40,8 +42,14 @@ func (cfg *Config) Default() error {
|
|||
// ApplyEnvVars fills in any Config fields found
|
||||
// as environment variables.
|
||||
func (cfg *Config) ApplyEnvVars() error {
|
||||
// doesn't read any config from env
|
||||
return nil
|
||||
jcfg := &jsonConfig{}
|
||||
|
||||
err := envconfig.Process(envConfigKey, jcfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return cfg.applyJSONConfig(jcfg)
|
||||
}
|
||||
|
||||
// Validate checks that the fields of this Config have working values,
|
||||
|
@ -63,6 +71,12 @@ func (cfg *Config) LoadJSON(raw []byte) error {
|
|||
return err
|
||||
}
|
||||
|
||||
cfg.Default()
|
||||
|
||||
return cfg.applyJSONConfig(jcfg)
|
||||
}
|
||||
|
||||
func (cfg *Config) applyJSONConfig(jcfg *jsonConfig) error {
|
||||
interval, _ := time.ParseDuration(jcfg.CheckInterval)
|
||||
cfg.CheckInterval = interval
|
||||
|
||||
|
|
|
@ -61,8 +61,14 @@ func (cfg *MetricsConfig) Default() error {
|
|||
// ApplyEnvVars fills in any Config fields found
|
||||
// as environment variables.
|
||||
func (cfg *MetricsConfig) ApplyEnvVars() error {
|
||||
// doesn't read any config from env
|
||||
return nil
|
||||
jcfg := &jsonMetricsConfig{}
|
||||
|
||||
err := envconfig.Process(envConfigKey, jcfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return cfg.applyJSONConfig(jcfg)
|
||||
}
|
||||
|
||||
// Validate checks that the fields of this Config have working values,
|
||||
|
@ -91,13 +97,11 @@ func (cfg *MetricsConfig) LoadJSON(raw []byte) error {
|
|||
|
||||
cfg.Default()
|
||||
|
||||
// override json config with env var
|
||||
err = envconfig.Process(envConfigKey, jcfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return cfg.applyJSONConfig(jcfg)
|
||||
}
|
||||
|
||||
err = cfg.loadMetricsOptions(jcfg)
|
||||
func (cfg *MetricsConfig) applyJSONConfig(jcfg *jsonMetricsConfig) error {
|
||||
err := cfg.loadMetricsOptions(jcfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -169,8 +173,14 @@ func (cfg *TracingConfig) Default() error {
|
|||
// ApplyEnvVars fills in any Config fields found
|
||||
// as environment variables.
|
||||
func (cfg *TracingConfig) ApplyEnvVars() error {
|
||||
// doesn't read any config from env
|
||||
return nil
|
||||
jcfg := &jsonTracingConfig{}
|
||||
|
||||
err := envconfig.Process(envConfigKey, jcfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return cfg.applyJSONConfig(jcfg)
|
||||
}
|
||||
|
||||
// Validate checks that the fields of this Config have working values,
|
||||
|
@ -199,13 +209,11 @@ func (cfg *TracingConfig) LoadJSON(raw []byte) error {
|
|||
|
||||
cfg.Default()
|
||||
|
||||
// override json config with env var
|
||||
err = envconfig.Process(envConfigKey, jcfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return cfg.applyJSONConfig(jcfg)
|
||||
}
|
||||
|
||||
err = cfg.loadTracingOptions(jcfg)
|
||||
func (cfg *TracingConfig) applyJSONConfig(jcfg *jsonTracingConfig) error {
|
||||
err := cfg.loadTracingOptions(jcfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -4,10 +4,13 @@ import (
|
|||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/kelseyhightower/envconfig"
|
||||
|
||||
"github.com/ipfs/ipfs-cluster/config"
|
||||
)
|
||||
|
||||
const configKey = "maptracker"
|
||||
const envConfigKey = "cluster_maptracker"
|
||||
|
||||
// Default values for this Config.
|
||||
const (
|
||||
|
@ -47,8 +50,14 @@ func (cfg *Config) Default() error {
|
|||
// ApplyEnvVars fills in any Config fields found
|
||||
// as environment variables.
|
||||
func (cfg *Config) ApplyEnvVars() error {
|
||||
// doesn't read any config from env
|
||||
return nil
|
||||
jcfg := &jsonConfig{}
|
||||
|
||||
err := envconfig.Process(envConfigKey, jcfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return cfg.applyJSONConfig(jcfg)
|
||||
}
|
||||
|
||||
// Validate checks that the fields of this Config have working values,
|
||||
|
@ -76,6 +85,10 @@ func (cfg *Config) LoadJSON(raw []byte) error {
|
|||
|
||||
cfg.Default()
|
||||
|
||||
return cfg.applyJSONConfig(jcfg)
|
||||
}
|
||||
|
||||
func (cfg *Config) applyJSONConfig(jcfg *jsonConfig) error {
|
||||
config.SetIfNotDefault(jcfg.MaxPinQueueSize, &cfg.MaxPinQueueSize)
|
||||
config.SetIfNotDefault(jcfg.ConcurrentPins, &cfg.ConcurrentPins)
|
||||
|
||||
|
|
|
@ -4,10 +4,13 @@ import (
|
|||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/kelseyhightower/envconfig"
|
||||
|
||||
"github.com/ipfs/ipfs-cluster/config"
|
||||
)
|
||||
|
||||
const configKey = "stateless"
|
||||
const envConfigKey = "cluster_stateless"
|
||||
|
||||
// Default values for this Config.
|
||||
const (
|
||||
|
@ -47,8 +50,14 @@ func (cfg *Config) Default() error {
|
|||
// ApplyEnvVars fills in any Config fields found
|
||||
// as environment variables.
|
||||
func (cfg *Config) ApplyEnvVars() error {
|
||||
// doesn't read any config from env
|
||||
return nil
|
||||
jcfg := &jsonConfig{}
|
||||
|
||||
err := envconfig.Process(envConfigKey, jcfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return cfg.applyJSONConfig(jcfg)
|
||||
}
|
||||
|
||||
// Validate checks that the fields of this Config have working values,
|
||||
|
@ -76,6 +85,10 @@ func (cfg *Config) LoadJSON(raw []byte) error {
|
|||
|
||||
cfg.Default()
|
||||
|
||||
return cfg.applyJSONConfig(jcfg)
|
||||
}
|
||||
|
||||
func (cfg *Config) applyJSONConfig(jcfg *jsonConfig) error {
|
||||
config.SetIfNotDefault(jcfg.MaxPinQueueSize, &cfg.MaxPinQueueSize)
|
||||
config.SetIfNotDefault(jcfg.ConcurrentPins, &cfg.ConcurrentPins)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user