multi: add MacaroonPath method to subserver manager

This commit is contained in:
Elle Mouton 2023-05-02 08:46:30 +02:00
parent 0ab5cb750b
commit 9eb01518e6
No known key found for this signature in database
GPG key ID: D7D916376026F177
2 changed files with 30 additions and 34 deletions

View file

@ -467,46 +467,21 @@ func (p *rpcProxy) basicAuthToMacaroon(basicAuth, requestURI string,
return nil, ctxErr
}
var (
macPath string
macData []byte
)
subserver, err := p.permsMgr.SubServerHandler(requestURI)
if err != nil {
return nil, err
}
var macData []byte
handled, macPath := p.subServerMgr.MacaroonPath(requestURI)
switch subserver {
case subservers.LND:
switch {
case handled:
case p.permsMgr.IsSubServerURI(subservers.LND, requestURI):
_, _, _, macPath, macData = p.cfg.lndConnectParams()
case subservers.FARADAY:
if p.cfg.faradayRemote {
macPath = p.cfg.Remote.Faraday.MacaroonPath
} else {
macPath = p.cfg.Faraday.MacaroonPath
}
case subservers.LOOP:
if p.cfg.loopRemote {
macPath = p.cfg.Remote.Loop.MacaroonPath
} else {
macPath = p.cfg.Loop.MacaroonPath
}
case subservers.POOL:
if p.cfg.poolRemote {
macPath = p.cfg.Remote.Pool.MacaroonPath
} else {
macPath = p.cfg.Pool.MacaroonPath
}
case subservers.LIT:
case p.permsMgr.IsSubServerURI(subservers.LIT, requestURI):
macPath = p.cfg.MacaroonPath
default:
return nil, fmt.Errorf("unknown subserver handler: %v",
subserver)
return nil, fmt.Errorf("unknown gRPC web request: %v",
requestURI)
}
switch {

View file

@ -189,6 +189,27 @@ func (s *Manager) ValidateMacaroon(ctx context.Context,
return false, nil
}
// MacaroonPath checks if any of the manager's sub-servers owns the given uri
// and if so, the appropriate macaroon path is returned for that sub-server.
func (s *Manager) MacaroonPath(uri string) (bool, string) {
s.mu.RLock()
defer s.mu.RUnlock()
for _, ss := range s.servers {
if !s.permsMgr.IsSubServerURI(ss.Name(), uri) {
continue
}
if ss.Remote() {
return true, ss.RemoteConfig().MacaroonPath
}
return true, ss.MacPath()
}
return false, ""
}
// Stop stops all the manager's sub-servers
func (s *Manager) Stop() error {
var returnErr error