Skip to content

Commit

Permalink
Merge pull request #192 from ellemouton/fixMacaroonPathParsing
Browse files Browse the repository at this point in the history
config+frcli: fix macaroon & tls cert path parsing
  • Loading branch information
ViktorTigerstrom authored Aug 19, 2024
2 parents f9fec2f + 951cc86 commit 242d5e5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
23 changes: 17 additions & 6 deletions cmd/frcli/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,23 @@ func extractPathArgs(ctx *cli.Context) (string, string, error) {
if faradayDir != faraday.FaradayDirBase ||
networkStr != faraday.DefaultNetwork {

tlsCertPath = filepath.Join(
faradayDir, networkStr, faraday.DefaultTLSCertFilename,
)
macPath = filepath.Join(
faradayDir, networkStr, faraday.DefaultMacaroonFilename,
)
// Only overwrite the tls cert path if the user has not
// explicitly defined it.
if !ctx.GlobalIsSet(tlsCertFlag.Name) {
tlsCertPath = filepath.Join(
faradayDir, networkStr,
faraday.DefaultTLSCertFilename,
)
}

// Only overwrite the macaroon path if the user has not
// explicitly defined it.
if !ctx.GlobalIsSet(macaroonPathFlag.Name) {
macPath = filepath.Join(
faradayDir, networkStr,
faraday.DefaultMacaroonFilename,
)
}
}

return tlsCertPath, macPath, nil
Expand Down
5 changes: 4 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ func ValidateConfig(config *Config) error {
config.TLSKeyPath = lncfg.CleanAndExpandPath(config.TLSKeyPath)
config.MacaroonPath = lncfg.CleanAndExpandPath(config.MacaroonPath)

// Before adding the network namespace below, check if the user has
// overwritten the default faraday directory.
faradayDirSet := config.FaradayDir != FaradayDirBase

// Append the network type to faraday directory so they are "namespaced"
// per network.
config.FaradayDir = filepath.Join(config.FaradayDir, config.Network)
Expand All @@ -205,7 +209,6 @@ func ValidateConfig(config *Config) error {
// values, make sure that they are not set when faraday dir is set. We
// fail hard here rather than overwriting and potentially confusing the
// user.
faradayDirSet := config.FaradayDir != FaradayDirBase
if faradayDirSet {
tlsCertPathSet := config.TLSCertPath != DefaultTLSCertPath
tlsKeyPathSet := config.TLSKeyPath != DefaultTLSKeyPath
Expand Down

0 comments on commit 242d5e5

Please sign in to comment.