cmd/lncli: properly parse cert and macaroon paths for all config variants

In this commit, we ensure that we're able to properly parse the cert and
macaroon paths for all relevant config variants. Before this commit, it
would be the case that the macaroon path ended up empty if a user wasn't
running the default (mainnet, lnddir) settings. In this commit, we
remedy this by parsing each of the two (cert+macaroon) paths
independently.
This commit is contained in:
Olaoluwa Osuntokun 2018-08-23 17:48:00 -07:00
parent 3d4843ed6c
commit ebc9550a1b
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21

@ -163,27 +163,36 @@ func parseArgs(ctx *cli.Context) (string, string) {
fatal(err)
}
var tlsCertPath, macPath string
// We'll now fetch the lnddir so we can make a decision on how to
// properly read the macaroons (if needed) and also the cert. This will
// either be the default, or will have been overwritten by the end
// user.
lndDir := cleanAndExpandPath(ctx.GlobalString("lnddir"))
if lndDir != defaultLndDir {
// If a custom lnd directory was set, we'll also check if custom
// paths for the TLS cert and macaroon file were set as well. If
// not, we'll override their paths so they can be found within
// the custom lnd directory set. This allows us to set a custom
// lnd directory, along with custom paths to the TLS cert and
// macaroon file.
tlsCertPath = cleanAndExpandPath(ctx.GlobalString("tlscertpath"))
if tlsCertPath == defaultTLSCertPath {
tlsCertPath = filepath.Join(lndDir, defaultTLSCertFilename)
}
// If the macaroon path as been manually provided, then we'll only
// target the specified file.
var macPath string
if ctx.GlobalString("macaroonpath") != "" {
macPath = cleanAndExpandPath(ctx.GlobalString("macaroonpath"))
if macPath == "" {
macPath = filepath.Join(
lndDir, defaultDataDir, defaultChainSubDir,
chain, network, defaultMacaroonFilename,
)
}
} else {
// Otherwise, we'll go into the path:
// lnddir/data/chain/<chain>/<network> in order to fetch the
// macaroon that we need.
macPath = filepath.Join(
lndDir, defaultDataDir, defaultChainSubDir, chain,
network, defaultMacaroonFilename,
)
}
tlsCertPath := cleanAndExpandPath(ctx.GlobalString("tlscertpath"))
// If a custom lnd directory was set, we'll also check if custom paths
// for the TLS cert and macaroon file were set as well. If not, we'll
// override their paths so they can be found within the custom lnd
// directory set. This allows us to set a custom lnd directory, along
// with custom paths to the TLS cert and macaroon file.
if lndDir != defaultLndDir {
tlsCertPath = filepath.Join(lndDir, defaultTLSCertFilename)
}
return tlsCertPath, macPath