@@ -27,13 +27,16 @@ var (
27
27
28
28
// Manager manages a set of subServer objects.
29
29
type Manager struct {
30
- servers []* subServerWrapper
31
- mu sync.RWMutex
30
+ servers []* subServerWrapper
31
+ permsMgr * PermissionsMgr
32
+ mu sync.RWMutex
32
33
}
33
34
34
35
// 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
+ }
37
40
}
38
41
39
42
// AddServer adds a new subServer to the manager's set.
@@ -112,6 +115,29 @@ func (s *Manager) RegisterRPCServices(server grpc.ServiceRegistrar) {
112
115
}
113
116
}
114
117
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
+
115
141
// ValidateMacaroon checks if any of the manager's sub-servers owns the given
116
142
// uri and if so, if it is running in remote mode, then true is returned since
117
143
// the macaroon will be validated by the remote subserver itself when the
@@ -124,7 +150,9 @@ func (s *Manager) ValidateMacaroon(ctx context.Context,
124
150
defer s .mu .RUnlock ()
125
151
126
152
for _ , ss := range s .servers {
127
- // TODO(positiveblue): check subserver permissions.
153
+ if ! s .permsMgr .IsSubServerURI (ss .subServer .Name (), uri ) {
154
+ continue
155
+ }
128
156
129
157
// If the sub-server is running in remote mode, then we don't
130
158
// need to validate the macaroon here since the remote server
0 commit comments