@@ -15,6 +15,7 @@ import (
15
15
"github.com/lightninglabs/lightning-terminal/litrpc"
16
16
"github.com/lightninglabs/lightning-terminal/perms"
17
17
"github.com/lightninglabs/lightning-terminal/session"
18
+ "github.com/lightninglabs/lightning-terminal/subservers"
18
19
"github.com/lightningnetwork/lnd/lncfg"
19
20
"github.com/lightningnetwork/lnd/macaroons"
20
21
grpcProxy "github.com/mwitkow/grpc-proxy/proxy"
@@ -361,18 +362,30 @@ func (p *rpcProxy) makeDirector(allowLitRPC bool) func(ctx context.Context,
361
362
// since it must either be an lnd call or something that'll be
362
363
// handled by the integrated daemons that are hooking into lnd's
363
364
// gRPC server.
365
+ isFaraday := p .permsMgr .IsSubServerURI (
366
+ subservers .FARADAY , requestURI ,
367
+ )
368
+ isLoop := p .permsMgr .IsSubServerURI (
369
+ subservers .LOOP , requestURI ,
370
+ )
371
+ isPool := p .permsMgr .IsSubServerURI (
372
+ subservers .POOL , requestURI ,
373
+ )
374
+ isLit := p .permsMgr .IsSubServerURI (
375
+ subservers .LIT , requestURI ,
376
+ )
364
377
switch {
365
- case p . permsMgr . IsFaradayURI ( requestURI ) && p .cfg .faradayRemote :
378
+ case isFaraday && p .cfg .faradayRemote :
366
379
return outCtx , p .faradayConn , nil
367
380
368
- case p . permsMgr . IsLoopURI ( requestURI ) && p .cfg .loopRemote :
381
+ case isLoop && p .cfg .loopRemote :
369
382
return outCtx , p .loopConn , nil
370
383
371
- case p . permsMgr . IsPoolURI ( requestURI ) && p .cfg .poolRemote :
384
+ case isPool && p .cfg .poolRemote :
372
385
return outCtx , p .poolConn , nil
373
386
374
387
// Calls to LiT session RPC aren't allowed in some cases.
375
- case p . permsMgr . IsLitURI ( requestURI ) && ! allowLitRPC :
388
+ case isLit && ! allowLitRPC :
376
389
return outCtx , nil , status .Errorf (
377
390
codes .Unimplemented , "unknown service %s" ,
378
391
requestURI ,
@@ -533,37 +546,42 @@ func (p *rpcProxy) basicAuthToMacaroon(basicAuth, requestURI string,
533
546
macPath string
534
547
macData []byte
535
548
)
536
- switch {
537
- case p .permsMgr .IsLndURI (requestURI ):
549
+ subserver , err := p .permsMgr .SubServerHandler (requestURI )
550
+ if err != nil {
551
+ return nil , err
552
+ }
553
+
554
+ switch subserver {
555
+ case subservers .LND :
538
556
_ , _ , _ , macPath , macData = p .cfg .lndConnectParams ()
539
557
540
- case p . permsMgr . IsFaradayURI ( requestURI ) :
558
+ case subservers . FARADAY :
541
559
if p .cfg .faradayRemote {
542
560
macPath = p .cfg .Remote .Faraday .MacaroonPath
543
561
} else {
544
562
macPath = p .cfg .Faraday .MacaroonPath
545
563
}
546
564
547
- case p . permsMgr . IsLoopURI ( requestURI ) :
565
+ case subservers . LOOP :
548
566
if p .cfg .loopRemote {
549
567
macPath = p .cfg .Remote .Loop .MacaroonPath
550
568
} else {
551
569
macPath = p .cfg .Loop .MacaroonPath
552
570
}
553
571
554
- case p . permsMgr . IsPoolURI ( requestURI ) :
572
+ case subservers . POOL :
555
573
if p .cfg .poolRemote {
556
574
macPath = p .cfg .Remote .Pool .MacaroonPath
557
575
} else {
558
576
macPath = p .cfg .Pool .MacaroonPath
559
577
}
560
578
561
- case p . permsMgr . IsLitURI ( requestURI ) :
579
+ case subservers . LIT :
562
580
macPath = p .cfg .MacaroonPath
563
581
564
582
default :
565
- return nil , fmt .Errorf ("unknown gRPC web request : %v" ,
566
- requestURI )
583
+ return nil , fmt .Errorf ("unknown subserver handler : %v" ,
584
+ subserver )
567
585
}
568
586
569
587
switch {
@@ -635,21 +653,22 @@ func (p *rpcProxy) convertSuperMacaroon(ctx context.Context, macHex string,
635
653
636
654
// Is this actually a request that goes to a daemon that is running
637
655
// remotely?
638
- switch {
639
- case p .permsMgr .IsFaradayURI (fullMethod ) && p .cfg .faradayRemote :
640
- return readMacaroon (lncfg .CleanAndExpandPath (
641
- p .cfg .Remote .Faraday .MacaroonPath ,
642
- ))
643
-
644
- case p .permsMgr .IsLoopURI (fullMethod ) && p .cfg .loopRemote :
645
- return readMacaroon (lncfg .CleanAndExpandPath (
646
- p .cfg .Remote .Loop .MacaroonPath ,
647
- ))
648
-
649
- case p .permsMgr .IsPoolURI (fullMethod ) && p .cfg .poolRemote :
650
- return readMacaroon (lncfg .CleanAndExpandPath (
651
- p .cfg .Remote .Pool .MacaroonPath ,
652
- ))
656
+ subserver , err := p .permsMgr .SubServerHandler (fullMethod )
657
+ if err == nil {
658
+ switch {
659
+ case subserver == subservers .FARADAY && p .cfg .faradayRemote :
660
+ return readMacaroon (lncfg .CleanAndExpandPath (
661
+ p .cfg .Remote .Faraday .MacaroonPath ,
662
+ ))
663
+ case subserver == subservers .LOOP && p .cfg .loopRemote :
664
+ return readMacaroon (lncfg .CleanAndExpandPath (
665
+ p .cfg .Remote .Loop .MacaroonPath ,
666
+ ))
667
+ case subserver == subservers .POOL && p .cfg .poolRemote :
668
+ return readMacaroon (lncfg .CleanAndExpandPath (
669
+ p .cfg .Remote .Pool .MacaroonPath ,
670
+ ))
671
+ }
653
672
}
654
673
655
674
return nil , nil
0 commit comments