Skip to content

Commit bab21fb

Browse files
committed
subservers: start using the subservers manager
1 parent 0658cb9 commit bab21fb

File tree

2 files changed

+152
-220
lines changed

2 files changed

+152
-220
lines changed

subservers/manager.go

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,16 @@ var (
2727

2828
// Manager manages a set of subServer objects.
2929
type Manager struct {
30-
servers []*subServerWrapper
31-
mu sync.RWMutex
30+
servers []*subServerWrapper
31+
permsMgr *PermissionsMgr
32+
mu sync.RWMutex
3233
}
3334

3435
// NewManager constructs a new subServerMgr.
35-
func NewManager() *Manager {
36-
return &Manager{}
36+
func NewManager(permsMgr *PermissionsMgr) *Manager {
37+
return &Manager{
38+
permsMgr: permsMgr,
39+
}
3740
}
3841

3942
// AddServer adds a new subServer to the manager's set.
@@ -112,6 +115,29 @@ func (s *Manager) RegisterRPCServices(server grpc.ServiceRegistrar) {
112115
}
113116
}
114117

118+
// GetRemoteConn checks if any of the manager's sub-servers owns the given uri
119+
// and if so, the remote connection to that sub-server is returned. The bool
120+
// return value indicates if the uri is managed by one of the sub-servers
121+
// running in remote mode.
122+
func (s *Manager) GetRemoteConn(uri string) (bool, *grpc.ClientConn) {
123+
s.mu.RLock()
124+
defer s.mu.RUnlock()
125+
126+
for _, ss := range s.servers {
127+
if !s.permsMgr.IsSubServerURI(ss.subServer.Name(), uri) {
128+
continue
129+
}
130+
131+
if !ss.subServer.Remote() {
132+
return false, nil
133+
}
134+
135+
return true, ss.remoteConn
136+
}
137+
138+
return false, nil
139+
}
140+
115141
// ValidateMacaroon checks if any of the manager's sub-servers owns the given
116142
// uri and if so, if it is running in remote mode, then true is returned since
117143
// the macaroon will be validated by the remote subserver itself when the
@@ -124,7 +150,9 @@ func (s *Manager) ValidateMacaroon(ctx context.Context,
124150
defer s.mu.RUnlock()
125151

126152
for _, ss := range s.servers {
127-
// TODO(positiveblue): check subserver permissions.
153+
if !s.permsMgr.IsSubServerURI(ss.subServer.Name(), uri) {
154+
continue
155+
}
128156

129157
// If the sub-server is running in remote mode, then we don't
130158
// need to validate the macaroon here since the remote server

0 commit comments

Comments
 (0)