|
5 | 5 | "crypto/x509" |
6 | 6 | "fmt" |
7 | 7 | "os" |
| 8 | + "path" |
8 | 9 | "path/filepath" |
9 | 10 | "time" |
10 | 11 |
|
|
46 | 47 |
|
47 | 48 | defaultSelfSignedOrganization = "loop autogenerated cert" |
48 | 49 |
|
| 50 | + // defaultLndMacaroon is the default macaroon file we use if the old, |
| 51 | + // deprecated --lnd.macaroondir config option is used. |
| 52 | + defaultLndMacaroon = "admin.macaroon" |
| 53 | + |
49 | 54 | // DefaultTLSCertPath is the default full path of the autogenerated TLS |
50 | 55 | // certificate. |
51 | 56 | DefaultTLSCertPath = filepath.Join( |
|
70 | 75 | ) |
71 | 76 |
|
72 | 77 | type lndConfig struct { |
73 | | - Host string `long:"host" description:"lnd instance rpc address"` |
74 | | - MacaroonDir string `long:"macaroondir" description:"Path to the directory containing all the required lnd macaroons"` |
75 | | - TLSPath string `long:"tlspath" description:"Path to lnd tls certificate"` |
| 78 | + Host string `long:"host" description:"lnd instance rpc address"` |
| 79 | + |
| 80 | + // MacaroonDir is the directory that contains all the macaroon files |
| 81 | + // required for the remote connection. |
| 82 | + MacaroonDir string `long:"macaroondir" description:"DEPRECATED: Use macaroonpath."` |
| 83 | + |
| 84 | + // MacaroonPath is the path to the single macaroon that should be used |
| 85 | + // instead of needing to specify the macaroon directory that contains |
| 86 | + // all of lnd's macaroons. The specified macaroon MUST have all |
| 87 | + // permissions that all the subservers use, otherwise permission errors |
| 88 | + // will occur. |
| 89 | + MacaroonPath string `long:"macaroonpath" description:"The full path to the single macaroon to use, either the admin.macaroon or a custom baked one. Cannot be specified at the same time as macaroondir. A custom macaroon must contain ALL permissions required for all subservers to work, otherwise permission errors will occur."` |
| 90 | + |
| 91 | + TLSPath string `long:"tlspath" description:"Path to lnd tls certificate"` |
76 | 92 | } |
77 | 93 |
|
78 | 94 | type loopServerConfig struct { |
@@ -235,6 +251,30 @@ func Validate(cfg *Config) error { |
235 | 251 | return err |
236 | 252 | } |
237 | 253 |
|
| 254 | + // Make sure only one of the macaroon options is used. |
| 255 | + switch { |
| 256 | + case cfg.Lnd.MacaroonPath != "" && cfg.Lnd.MacaroonDir != "": |
| 257 | + return fmt.Errorf("use --lnd.macaroonpath only") |
| 258 | + |
| 259 | + case cfg.Lnd.MacaroonDir != "": |
| 260 | + // With the new version of lndclient we can only specify a |
| 261 | + // single macaroon instead of all of them. If the old |
| 262 | + // macaroondir is used, we use the admin macaroon located in |
| 263 | + // that directory. |
| 264 | + cfg.Lnd.MacaroonPath = path.Join( |
| 265 | + lncfg.CleanAndExpandPath(cfg.Lnd.MacaroonDir), |
| 266 | + defaultLndMacaroon, |
| 267 | + ) |
| 268 | + |
| 269 | + case cfg.Lnd.MacaroonPath != "": |
| 270 | + cfg.Lnd.MacaroonPath = lncfg.CleanAndExpandPath( |
| 271 | + cfg.Lnd.MacaroonPath, |
| 272 | + ) |
| 273 | + |
| 274 | + default: |
| 275 | + return fmt.Errorf("must specify --lnd.macaroonpath") |
| 276 | + } |
| 277 | + |
238 | 278 | return nil |
239 | 279 | } |
240 | 280 |
|
|
0 commit comments