Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

config: Deprecate --configfile. #470

Merged
merged 1 commit into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 10 additions & 22 deletions cmd/vspd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ var (
defaultHomeDir = dcrutil.AppDataDir(appName, false)
defaultConfigFilename = fmt.Sprintf("%s.conf", appName)
defaultDBFilename = fmt.Sprintf("%s.db", appName)
defaultConfigFile = filepath.Join(defaultHomeDir, defaultConfigFilename)
defaultDcrdHost = "127.0.0.1"
defaultWalletHost = "127.0.0.1"
defaultWebServerDebug = false
Expand Down Expand Up @@ -74,7 +73,7 @@ type vspdConfig struct {
ShowVersion bool `long:"version" no-ini:"true" description:"Display version information and exit."`
FeeXPub string `long:"feexpub" no-ini:"true" description:"Cold wallet xpub used for collecting fees. Should be provided once to initialize a vspd database."`
HomeDir string `long:"homedir" no-ini:"true" description:"Path to application home directory. Used for storing VSP database and logs."`
ConfigFile string `long:"configfile" no-ini:"true" description:"Path to configuration file."`
ConfigFile string `long:"configfile" no-ini:"true" description:"DEPRECATED: This behavior is no longer available and this option will be removed in a future version of the software."`

logBackend *slog.Backend
logLevel slog.Level
Expand Down Expand Up @@ -181,7 +180,6 @@ func loadConfig() (*vspdConfig, error) {
NetworkName: defaultNetworkName,
VSPFee: defaultVSPFee,
HomeDir: defaultHomeDir,
ConfigFile: defaultConfigFile,
DcrdHost: defaultDcrdHost,
WalletHosts: defaultWalletHost,
WebServerDebug: defaultWebServerDebug,
Expand All @@ -195,8 +193,8 @@ func loadConfig() (*vspdConfig, error) {
os.Exit(0)
}

// Pre-parse the command line options to see if an alternative config file,
// home dir, or the version flag were specified.
// Pre-parse the command line options to see if an alternative home dir or
// the version flag were specified.
preCfg := cfg

preParser := flags.NewParser(&preCfg, flags.None)
Expand All @@ -217,20 +215,9 @@ func loadConfig() (*vspdConfig, error) {
appName = strings.TrimSuffix(appName, filepath.Ext(appName))
usageMessage := fmt.Sprintf("Use %s -h to show usage", appName)

// Update the home directory if specified on CLI. Since the home
// directory is updated, other variables need to be updated to
// reflect the new changes.
// Update the home directory if specified on CLI.
if preCfg.HomeDir != "" {
cfg.HomeDir = cleanAndExpandPath(cfg.HomeDir)
cfg.HomeDir, _ = filepath.Abs(preCfg.HomeDir)

if preCfg.ConfigFile == defaultConfigFile {
defaultConfigFile = filepath.Join(cfg.HomeDir, defaultConfigFilename)
preCfg.ConfigFile = defaultConfigFile
cfg.ConfigFile = defaultConfigFile
} else {
cfg.ConfigFile = preCfg.ConfigFile
}
cfg.HomeDir = cleanAndExpandPath(preCfg.HomeDir)
}

// Create the home directory if it doesn't already exist.
Expand All @@ -243,15 +230,16 @@ func loadConfig() (*vspdConfig, error) {

// Create a default config file when one does not exist and the user did
// not specify an override.
if preCfg.ConfigFile == defaultConfigFile && !fileExists(preCfg.ConfigFile) {
configFile := filepath.Join(cfg.HomeDir, defaultConfigFilename)
if !fileExists(configFile) {
preIni := flags.NewIniParser(preParser)
err = preIni.WriteFile(preCfg.ConfigFile,
err = preIni.WriteFile(configFile,
flags.IniIncludeComments|flags.IniIncludeDefaults)
if err != nil {
return nil, fmt.Errorf("error creating a default "+
"config file: %w", err)
}
fmt.Printf("Config file with default values written to %s\n", defaultConfigFile)
fmt.Printf("Config file with default values written to %s\n", configFile)

// File created, user now has to fill in values. Proceeding with the
// default file just causes errors.
Expand All @@ -261,7 +249,7 @@ func loadConfig() (*vspdConfig, error) {
// Load additional config from file.
parser := flags.NewParser(&cfg, flags.None)

err = flags.NewIniParser(parser).ParseFile(preCfg.ConfigFile)
err = flags.NewIniParser(parser).ParseFile(configFile)
if err != nil {
return nil, fmt.Errorf("error parsing config file: %w", err)
}
Expand Down
12 changes: 9 additions & 3 deletions cmd/vspd/main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2020-2023 The Decred developers
// Copyright (c) 2020-2024 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.

Expand Down Expand Up @@ -55,13 +55,19 @@ func run() int {

if cfg.network == &config.MainNet && version.IsPreRelease() {
log.Warnf("")
log.Warnf("\tWARNING: This is a pre-release version of vspd which should not be used on mainnet.")
log.Warnf("\tWARNING: This is a pre-release version of vspd which should not be used on mainnet")
log.Warnf("")
}

if cfg.VspClosed {
log.Warnf("")
log.Warnf("\tWARNING: Config --vspclosed is set. This will prevent vspd from accepting new tickets.")
log.Warnf("\tWARNING: Config --vspclosed is set. This will prevent vspd from accepting new tickets")
log.Warnf("")
}

if cfg.ConfigFile != "" {
log.Warnf("")
log.Warnf("\tWARNING: Config --configfile is set. This is a deprecated option which has no effect and will be removed in a future release")
log.Warnf("")
}

Expand Down
4 changes: 2 additions & 2 deletions harness.sh
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@ EOF
tmux new-window -t $TMUX_SESSION -n "vspd"

echo "Creating vspd database"
tmux send-keys "vspd --configfile=${HARNESS_ROOT}/vspd/vspd.conf --homedir=${HARNESS_ROOT}/vspd --feexpub=${VSPD_FEE_XPUB}" C-m
tmux send-keys "vspd --homedir=${HARNESS_ROOT}/vspd --feexpub=${VSPD_FEE_XPUB}" C-m
sleep 3 # wait for database creation and ensure dcrwallet rpc listeners are started
echo "Starting vspd"
tmux send-keys "vspd --configfile=${HARNESS_ROOT}/vspd/vspd.conf --homedir=${HARNESS_ROOT}/vspd" C-m
tmux send-keys "vspd --homedir=${HARNESS_ROOT}/vspd" C-m

#################################################
# All done - attach to tmux session.
Expand Down
Loading