From 8ecd9673f2ab9535bf180a93e0e9a0395d7a79f4 Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Thu, 3 Sep 2020 14:35:42 +0200 Subject: [PATCH] cmd/loop: add macaroon params to CLI --- cmd/loop/main.go | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/cmd/loop/main.go b/cmd/loop/main.go index 6847975..97d33cd 100644 --- a/cmd/loop/main.go +++ b/cmd/loop/main.go @@ -66,9 +66,9 @@ var ( Value: loopd.DefaultTLSCertPath, } macaroonPathFlag = cli.StringFlag{ - Name: "macaroonpath", - Usage: "path to macaroon file, only needed if loop runs " + - "in the same process as lnd", + Name: "macaroonpath", + 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...)