config.go: check for RPCUser AND RPCPass (AND ZMQPath for bitcoind)

This commit causes the configuration parser to accept the values of
RPCUser, RPCPass, and (for the bitcoind back-end) ZMQPath configured
in lnd.conf or on the command line ONLY when all are specified. It
causes the configuration parser to look in btcd.conf or bitcoin.conf
ONLY when none are specified, and causes an error to be returned when
only some are specified, as users have done so erroneously and the
lack of clear feedback has caused difficulties.
This commit is contained in:
Alex 2018-01-18 13:54:41 -07:00 committed by Olaoluwa Osuntokun
parent 4f91b66c51
commit 4559438c4b

View File

@ -621,13 +621,30 @@ func parseRPCParams(cConfig *chainConfig, nodeConfig interface{}, net chainCode,
// specified, we can return.
switch conf := nodeConfig.(type) {
case *btcdConfig:
if conf.RPCUser != "" || conf.RPCPass != "" {
// If both RPCUser and RPCPass are set, we assume those
// credentials are good to use.
if conf.RPCUser != "" && conf.RPCPass != "" {
return nil
}
// If only ONE of RPCUser or RPCPass is set, we assume the
// user did that unintentionally.
if conf.RPCUser != "" || conf.RPCPass != "" {
return fmt.Errorf("please set both or neither of " +
"btcd.rpcuser and btcd.rpcpass")
}
case *bitcoindConfig:
if conf.RPCUser != "" || conf.RPCPass != "" || conf.ZMQPath != "" {
// If all of RPCUser, RPCPass, and ZMQPath are set, we assume
// those parameters are good to use.
if conf.RPCUser != "" && conf.RPCPass != "" && conf.ZMQPath != "" {
return nil
}
// If only one or two of the parameters are set, we assume the
// user did that unintentionally.
if conf.RPCUser != "" || conf.RPCPass != "" || conf.ZMQPath != "" {
return fmt.Errorf("please set all or none of " +
"bitcoind.rpcuser, bitcoind.rpcpass, and " +
"bitcoind.zmqpath")
}
}
// If we're in simnet mode, then the running btcd instance won't read