cmd/loop: add macaroon params to CLI
@@ -67,8 +67,8 @@ var (
}
macaroonPathFlag = cli.StringFlag{
Name: "macaroonpath",
- Usage: "path to macaroon file, only needed if loop runs " +
- "in the same process as lnd",
+ Usage: "path to macaroon file",
+ Value: loopd.DefaultMacaroonPath,
}
)
@@ -171,25 +171,31 @@ func extractPathArgs(ctx *cli.Context) (string, string, error) {
}
// We'll now fetch the loopdir so we can make a decision on how to
- // properly read the cert. This will either be the default, or will have
- // been overwritten by the end user.
+ // properly read the macaroons and also the cert. This will either be
+ // the default, or will have been overwritten by the end user.
loopDir := lncfg.CleanAndExpandPath(ctx.GlobalString(loopDirFlag.Name))
tlsCertPath := lncfg.CleanAndExpandPath(ctx.GlobalString(
tlsCertFlag.Name,
))
+ macPath := lncfg.CleanAndExpandPath(ctx.GlobalString(
+ macaroonPathFlag.Name,
+ ))
- // If a custom lnd directory was set, we'll also check if custom paths
- // for the TLS cert file were set as well. If not, we'll override their
- // paths so they can be found within the custom loop directory set. This
- // allows us to set a custom lnd directory, along with custom paths to
- // the TLS cert file.
+ // If a custom loop 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 loop
+ // directory set. This allows us to set a custom loop directory, along
+ // with custom paths to the TLS cert and macaroon file.
if loopDir != loopd.LoopDirBase || networkStr != loopd.DefaultNetwork {
tlsCertPath = filepath.Join(
loopDir, networkStr, loopd.DefaultTLSCertFilename,
)
+ macPath = filepath.Join(
+ loopDir, networkStr, loopd.DefaultMacaroonFilename,
+ )
}
- return tlsCertPath, ctx.GlobalString(macaroonPathFlag.Name), nil
+ return tlsCertPath, macPath, nil
}
type inLimits struct {
@@ -373,8 +379,15 @@ func logSwap(swap *looprpc.SwapStatus) {
func getClientConn(address, tlsCertPath, macaroonPath string) (*grpc.ClientConn,
error) {
+ // We always need to send a macaroon.
+ macOption, err := readMacaroon(macaroonPath)
+ if err != nil {
+ return nil, err
+ }
+
opts := []grpc.DialOption{
grpc.WithDefaultCallOptions(maxMsgRecvSize),
+ macOption,
}
// TLS cannot be disabled, we'll always have a cert file to read.
@@ -383,15 +396,6 @@ func getClientConn(address, tlsCertPath, macaroonPath string) (*grpc.ClientConn,
return nil, err
}
- // Macaroons are not yet enabled by default.
- if macaroonPath != "" {
- macOption, err := readMacaroon(macaroonPath)
- if err != nil {
- return nil, err
- }
- opts = append(opts, macOption)
- }
-
opts = append(opts, grpc.WithTransportCredentials(creds))
conn, err := grpc.Dial(address, opts...)
