Skip to content

Commit 9eb0151

Browse files
committed
multi: add MacaroonPath method to subserver manager
1 parent 0ab5cb7 commit 9eb0151

File tree

2 files changed

+30
-34
lines changed

2 files changed

+30
-34
lines changed

rpc_proxy.go

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -467,46 +467,21 @@ func (p *rpcProxy) basicAuthToMacaroon(basicAuth, requestURI string,
467467
return nil, ctxErr
468468
}
469469

470-
var (
471-
macPath string
472-
macData []byte
473-
)
474-
subserver, err := p.permsMgr.SubServerHandler(requestURI)
475-
if err != nil {
476-
return nil, err
477-
}
478-
479-
switch subserver {
480-
case subservers.LND:
481-
_, _, _, macPath, macData = p.cfg.lndConnectParams()
470+
var macData []byte
471+
handled, macPath := p.subServerMgr.MacaroonPath(requestURI)
482472

483-
case subservers.FARADAY:
484-
if p.cfg.faradayRemote {
485-
macPath = p.cfg.Remote.Faraday.MacaroonPath
486-
} else {
487-
macPath = p.cfg.Faraday.MacaroonPath
488-
}
489-
490-
case subservers.LOOP:
491-
if p.cfg.loopRemote {
492-
macPath = p.cfg.Remote.Loop.MacaroonPath
493-
} else {
494-
macPath = p.cfg.Loop.MacaroonPath
495-
}
473+
switch {
474+
case handled:
496475

497-
case subservers.POOL:
498-
if p.cfg.poolRemote {
499-
macPath = p.cfg.Remote.Pool.MacaroonPath
500-
} else {
501-
macPath = p.cfg.Pool.MacaroonPath
502-
}
476+
case p.permsMgr.IsSubServerURI(subservers.LND, requestURI):
477+
_, _, _, macPath, macData = p.cfg.lndConnectParams()
503478

504-
case subservers.LIT:
479+
case p.permsMgr.IsSubServerURI(subservers.LIT, requestURI):
505480
macPath = p.cfg.MacaroonPath
506481

507482
default:
508-
return nil, fmt.Errorf("unknown subserver handler: %v",
509-
subserver)
483+
return nil, fmt.Errorf("unknown gRPC web request: %v",
484+
requestURI)
510485
}
511486

512487
switch {

subservers/manager.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,27 @@ func (s *Manager) ValidateMacaroon(ctx context.Context,
189189
return false, nil
190190
}
191191

192+
// MacaroonPath checks if any of the manager's sub-servers owns the given uri
193+
// and if so, the appropriate macaroon path is returned for that sub-server.
194+
func (s *Manager) MacaroonPath(uri string) (bool, string) {
195+
s.mu.RLock()
196+
defer s.mu.RUnlock()
197+
198+
for _, ss := range s.servers {
199+
if !s.permsMgr.IsSubServerURI(ss.Name(), uri) {
200+
continue
201+
}
202+
203+
if ss.Remote() {
204+
return true, ss.RemoteConfig().MacaroonPath
205+
}
206+
207+
return true, ss.MacPath()
208+
}
209+
210+
return false, ""
211+
}
212+
192213
// Stop stops all the manager's sub-servers
193214
func (s *Manager) Stop() error {
194215
var returnErr error

0 commit comments

Comments
 (0)