From 21456a5887ba0619ea028b1efbe40c37e82fc4bd Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Wed, 3 May 2023 10:00:55 +0200 Subject: [PATCH] subservers: add Handles method Add a Handles method to the subserver Manager which takes a URI string and returns true if one of the sub-servers it manages owns the given URI. --- subservers/manager.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/subservers/manager.go b/subservers/manager.go index c4e5f18f..12aa8bcd 100644 --- a/subservers/manager.go +++ b/subservers/manager.go @@ -300,6 +300,23 @@ func (s *Manager) ReadRemoteMacaroon(uri string) (bool, []byte, error) { return false, nil, nil } +// Handles returns true if one of its sub-servers owns the given URI along with +// the name of the service. +func (s *Manager) Handles(uri string) (bool, string) { + s.mu.RLock() + defer s.mu.RUnlock() + + for _, ss := range s.servers { + if !s.permsMgr.IsSubServerURI(ss.Name(), uri) { + continue + } + + return true, ss.Name() + } + + return false, "" +} + // Stop stops all the manager's sub-servers func (s *Manager) Stop() error { var returnErr error