mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 01:43:16 +01:00
lnd: consolidate WalletUnlocker- and AdminAuthOptions
This commit is contained in:
parent
8789247bf9
commit
db28e7c891
26
lnd.go
26
lnd.go
@ -54,31 +54,15 @@ import (
|
||||
"github.com/lightningnetwork/lnd/watchtower/wtdb"
|
||||
)
|
||||
|
||||
// WalletUnlockerAuthOptions returns a list of DialOptions that can be used to
|
||||
// authenticate with the wallet unlocker service.
|
||||
//
|
||||
// NOTE: This should only be called after the WalletUnlocker listener has
|
||||
// signaled it is ready.
|
||||
func WalletUnlockerAuthOptions(cfg *Config) ([]grpc.DialOption, error) {
|
||||
creds, err := credentials.NewClientTLSFromFile(cfg.TLSCertPath, "")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to read TLS cert: %v", err)
|
||||
}
|
||||
|
||||
// Create a dial options array with the TLS credentials.
|
||||
opts := []grpc.DialOption{
|
||||
grpc.WithTransportCredentials(creds),
|
||||
}
|
||||
|
||||
return opts, nil
|
||||
}
|
||||
|
||||
// AdminAuthOptions returns a list of DialOptions that can be used to
|
||||
// authenticate with the RPC server with admin capabilities.
|
||||
// skipMacaroons=true should be set if we don't want to include macaroons with
|
||||
// the auth options. This is needed for instance for the WalletUnlocker
|
||||
// service, which must be usable also before macaroons are created.
|
||||
//
|
||||
// NOTE: This should only be called after the RPCListener has signaled it is
|
||||
// ready.
|
||||
func AdminAuthOptions(cfg *Config) ([]grpc.DialOption, error) {
|
||||
func AdminAuthOptions(cfg *Config, skipMacaroons bool) ([]grpc.DialOption, error) {
|
||||
creds, err := credentials.NewClientTLSFromFile(cfg.TLSCertPath, "")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to read TLS cert: %v", err)
|
||||
@ -90,7 +74,7 @@ func AdminAuthOptions(cfg *Config) ([]grpc.DialOption, error) {
|
||||
}
|
||||
|
||||
// Get the admin macaroon if macaroons are active.
|
||||
if !cfg.NoMacaroons {
|
||||
if !skipMacaroons && !cfg.NoMacaroons {
|
||||
// Load the adming macaroon file.
|
||||
macBytes, err := ioutil.ReadFile(cfg.AdminMacPath)
|
||||
if err != nil {
|
||||
|
@ -105,7 +105,7 @@ func Start(extraArgs string, unlockerReady, rpcReady Callback) {
|
||||
|
||||
// We must set the TLS certificates in order to properly
|
||||
// authenticate with the wallet unlocker service.
|
||||
auth, err := lnd.WalletUnlockerAuthOptions(loadedConfig)
|
||||
auth, err := lnd.AdminAuthOptions(loadedConfig, true)
|
||||
if err != nil {
|
||||
unlockerReady.OnError(err)
|
||||
return
|
||||
@ -123,7 +123,7 @@ func Start(extraArgs string, unlockerReady, rpcReady Callback) {
|
||||
// Now that the RPC server is ready, we can get the needed
|
||||
// authentication options, and add them to the global dial
|
||||
// options.
|
||||
auth, err := lnd.AdminAuthOptions(loadedConfig)
|
||||
auth, err := lnd.AdminAuthOptions(loadedConfig, false)
|
||||
if err != nil {
|
||||
rpcReady.OnError(err)
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user