config

package
v0.0.0-...-422bc60 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2022 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FXProviderFixer = "fixer"
	EncryptedFile   = "config.dat"
	File            = "config.json"
	TestFile        = "../testdata/configtest.json"

	DefaultAPIKey      = "Key"
	DefaultAPISecret   = "Secret"
	DefaultAPIClientID = "ClientID"

	DefaultOrderbookPublishPeriod = time.Second * 10
)

Constants declared here are filename strings and test strings

View Source
const (
	ErrExchangeNameEmpty                       = "exchange #%d name is empty"
	ErrNoEnabledExchanges                      = "no exchanges enabled"
	ErrFailureOpeningConfig                    = "fatal error opening %s file. Error: %s"
	ErrCheckingConfigValues                    = "fatal error checking config values. Error: %s"
	WarningExchangeAuthAPIDefaultOrEmptyValues = "exchange %s authenticated API support disabled due to default/empty APIKey/Secret/ClientID values"
	WarningPairsLastUpdatedThresholdExceeded   = "exchange %s last manual update of available currency pairs has exceeded %d days. Manual update required!"
)

Constants here hold some messages

View Source
const (
	APIURLNonDefaultMessage              = "NON_DEFAULT_HTTP_LINK_TO_EXCHANGE_API"
	WebsocketURLNonDefaultMessage        = "NON_DEFAULT_HTTP_LINK_TO_WEBSOCKET_EXCHANGE_API"
	DefaultUnsetAPIKey                   = "Key"
	DefaultUnsetAPISecret                = "Secret"
	DefaultUnsetAccountPlan              = "accountPlan"
	DefaultForexProviderExchangeRatesAPI = "ExchangeRateHost"
)

Constants here define unset default values displayed in the config.json file

View Source
const (
	// EncryptConfirmString has a the general confirmation string to allow us to
	// see if the file is correctly encrypted
	EncryptConfirmString = "THORS-HAMMER"
	// SaltPrefix string
	SaltPrefix = "~GCT~SO~SALTY~"
	// SaltRandomLength is the number of random bytes to append after the prefix string
	SaltRandomLength = 12
)

Variables

This section is empty.

Functions

func ConfirmECS

func ConfirmECS(file []byte) bool

ConfirmECS confirms that the encryption confirmation string is found

func ConfirmSalt

func ConfirmSalt(file []byte) bool

ConfirmSalt checks whether the encrypted data contains a salt

func DecryptConfigFile

func DecryptConfigFile(configData, key []byte) ([]byte, error)

DecryptConfigFile decrypts configuration data with the supplied key and returns the un-encrypted data as a byte array with an error

func EncryptConfigFile

func EncryptConfigFile(configData, key []byte) ([]byte, error)

EncryptConfigFile encrypts configuration data that is parsed in with a key and returns it as a byte array with an error

func GetFilePath

func GetFilePath(configFile string) (configPath string, isImplicitDefaultPath bool, err error)

GetFilePath returns the desired config file or the default config file name and whether it was loaded from a default location (rather than explicitly specified)

func PromptForConfigKey

func PromptForConfigKey(initialSetup bool) ([]byte, error)

PromptForConfigKey asks for configuration key if initialSetup is true, the password needs to be repeated

func Unencrypted

func Unencrypted() ([]byte, error)

Unencrypted provides the default key provider implementation for unencrypted files

Types

type Config

type Config struct {
	Name              string          `json:"name"`
	DataDirectory     string          `json:"dataDirectory"`
	EncryptConfig     int             `json:"encryptConfig"`
	GlobalHTTPTimeout time.Duration   `json:"globalHTTPTimeout"`
	Database          database.Config `json:"database"`
	Logging           log.Config      `json:"logging"`
	// contains filtered or unexported fields
}

Config is the overarching object that holds all the information for prestart management of Portfolio, Webserver and Enabled Exchanges

var (
	Cfg Config

	ErrExchangeNotFound = errors.New("exchange not found")
)

Variables here are used for configuration

func GetConfig

func GetConfig() *Config

GetConfig returns a pointer to a configuration object

func ReadConfig

func ReadConfig(configReader io.Reader, keyProvider func() ([]byte, error)) (*Config, bool, error)

ReadConfig verifies and checks for encryption and loads the config from a JSON object. Prompts for decryption key, if target data is encrypted. Returns the loaded configuration and whether it was encrypted.

func (*Config) LoadConfig

func (c *Config) LoadConfig(configPath string, dryrun bool) error

LoadConfig loads your configuration file into your configuration object

func (*Config) ReadConfigFromFile

func (c *Config) ReadConfigFromFile(configPath string, dryrun bool) error

ReadConfigFromFile reads the configuration from the given file if target file is encrypted, prompts for encryption key Also - if not in dryrun mode - it checks if the configuration needs to be encrypted and stores the file as encrypted, if necessary (prompting for enryption key)

func (*Config) Save

func (c *Config) Save(writerProvider func() (io.Writer, error), keyProvider func() ([]byte, error)) error

Save saves your configuration to the writer as a JSON object with encryption, if configured If there is an error when preparing the data to store, the writer is never requested

func (*Config) SaveConfigToFile

func (c *Config) SaveConfigToFile(configPath string) error

SaveConfigToFile saves your configuration to your desired path as a JSON object. The function encrypts the data and prompts for encryption key, if necessary

func (*Config) UpdateConfig

func (c *Config) UpdateConfig(configPath string, newCfg *Config, dryrun bool) error

UpdateConfig updates the config with a supplied config file

type ConnectionMonitorConfig

type ConnectionMonitorConfig struct {
	DNSList          []string      `json:"preferredDNSList"`
	PublicDomainList []string      `json:"preferredDomainList"`
	CheckInterval    time.Duration `json:"checkInterval"`
}

ConnectionMonitorConfig defines the connection monitor variables to ensure that there is internet connectivity

Jump to

Keyboard shortcuts

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