From ebc9550a1b54dd2d17566dcc2427a513d884ef6c Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Thu, 23 Aug 2018 17:48:00 -0700 Subject: [PATCH] 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. --- cmd/lncli/main.go | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/cmd/lncli/main.go b/cmd/lncli/main.go index 504212ed..a40941f8 100644 --- a/cmd/lncli/main.go +++ b/cmd/lncli/main.go @@ -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// 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