@@ -15,6 +15,7 @@ import (
1515 "github.com/lightninglabs/lightning-terminal/litrpc"
1616 "github.com/lightninglabs/lightning-terminal/perms"
1717 "github.com/lightninglabs/lightning-terminal/session"
18+ "github.com/lightninglabs/lightning-terminal/subservers"
1819 "github.com/lightningnetwork/lnd/lncfg"
1920 "github.com/lightningnetwork/lnd/macaroons"
2021 grpcProxy "github.com/mwitkow/grpc-proxy/proxy"
@@ -361,18 +362,30 @@ func (p *rpcProxy) makeDirector(allowLitRPC bool) func(ctx context.Context,
361362 // since it must either be an lnd call or something that'll be
362363 // handled by the integrated daemons that are hooking into lnd's
363364 // 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+ )
364377 switch {
365- case p . permsMgr . IsFaradayURI ( requestURI ) && p .cfg .faradayRemote :
378+ case isFaraday && p .cfg .faradayRemote :
366379 return outCtx , p .faradayConn , nil
367380
368- case p . permsMgr . IsLoopURI ( requestURI ) && p .cfg .loopRemote :
381+ case isLoop && p .cfg .loopRemote :
369382 return outCtx , p .loopConn , nil
370383
371- case p . permsMgr . IsPoolURI ( requestURI ) && p .cfg .poolRemote :
384+ case isPool && p .cfg .poolRemote :
372385 return outCtx , p .poolConn , nil
373386
374387 // Calls to LiT session RPC aren't allowed in some cases.
375- case p . permsMgr . IsLitURI ( requestURI ) && ! allowLitRPC :
388+ case isLit && ! allowLitRPC :
376389 return outCtx , nil , status .Errorf (
377390 codes .Unimplemented , "unknown service %s" ,
378391 requestURI ,
@@ -533,37 +546,42 @@ func (p *rpcProxy) basicAuthToMacaroon(basicAuth, requestURI string,
533546 macPath string
534547 macData []byte
535548 )
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 :
538556 _ , _ , _ , macPath , macData = p .cfg .lndConnectParams ()
539557
540- case p . permsMgr . IsFaradayURI ( requestURI ) :
558+ case subservers . FARADAY :
541559 if p .cfg .faradayRemote {
542560 macPath = p .cfg .Remote .Faraday .MacaroonPath
543561 } else {
544562 macPath = p .cfg .Faraday .MacaroonPath
545563 }
546564
547- case p . permsMgr . IsLoopURI ( requestURI ) :
565+ case subservers . LOOP :
548566 if p .cfg .loopRemote {
549567 macPath = p .cfg .Remote .Loop .MacaroonPath
550568 } else {
551569 macPath = p .cfg .Loop .MacaroonPath
552570 }
553571
554- case p . permsMgr . IsPoolURI ( requestURI ) :
572+ case subservers . POOL :
555573 if p .cfg .poolRemote {
556574 macPath = p .cfg .Remote .Pool .MacaroonPath
557575 } else {
558576 macPath = p .cfg .Pool .MacaroonPath
559577 }
560578
561- case p . permsMgr . IsLitURI ( requestURI ) :
579+ case subservers . LIT :
562580 macPath = p .cfg .MacaroonPath
563581
564582 default :
565- return nil , fmt .Errorf ("unknown gRPC web request : %v" ,
566- requestURI )
583+ return nil , fmt .Errorf ("unknown subserver handler : %v" ,
584+ subserver )
567585 }
568586
569587 switch {
@@ -635,21 +653,22 @@ func (p *rpcProxy) convertSuperMacaroon(ctx context.Context, macHex string,
635653
636654 // Is this actually a request that goes to a daemon that is running
637655 // 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+ }
653672 }
654673
655674 return nil , nil
0 commit comments