6
6
"sync"
7
7
"time"
8
8
9
+ "github.com/lightninglabs/lightning-terminal/perms"
9
10
"github.com/lightninglabs/lndclient"
10
11
"github.com/lightningnetwork/lnd/lnrpc"
11
12
grpcProxy "github.com/mwitkow/grpc-proxy/proxy"
@@ -27,13 +28,16 @@ var (
27
28
28
29
// Manager manages a set of subServer objects.
29
30
type Manager struct {
30
- servers []* subServerWrapper
31
- mu sync.RWMutex
31
+ servers []* subServerWrapper
32
+ permsMgr * perms.Manager
33
+ mu sync.RWMutex
32
34
}
33
35
34
36
// NewManager constructs a new subServerMgr.
35
- func NewManager () * Manager {
36
- return & Manager {}
37
+ func NewManager (permsMgr * perms.Manager ) * Manager {
38
+ return & Manager {
39
+ permsMgr : permsMgr ,
40
+ }
37
41
}
38
42
39
43
// AddServer adds a new subServer to the manager's set.
@@ -112,6 +116,29 @@ func (s *Manager) RegisterRPCServices(server grpc.ServiceRegistrar) {
112
116
}
113
117
}
114
118
119
+ // GetRemoteConn checks if any of the manager's sub-servers owns the given uri
120
+ // and if so, the remote connection to that sub-server is returned. The bool
121
+ // return value indicates if the uri is managed by one of the sub-servers
122
+ // running in remote mode.
123
+ func (s * Manager ) GetRemoteConn (uri string ) (bool , * grpc.ClientConn ) {
124
+ s .mu .RLock ()
125
+ defer s .mu .RUnlock ()
126
+
127
+ for _ , ss := range s .servers {
128
+ if ! s .permsMgr .IsSubServerURI (ss .subServer .Name (), uri ) {
129
+ continue
130
+ }
131
+
132
+ if ! ss .subServer .Remote () {
133
+ return false , nil
134
+ }
135
+
136
+ return true , ss .remoteConn
137
+ }
138
+
139
+ return false , nil
140
+ }
141
+
115
142
// ValidateMacaroon checks if any of the manager's sub-servers owns the given
116
143
// uri and if so, if it is running in remote mode, then true is returned since
117
144
// the macaroon will be validated by the remote subserver itself when the
@@ -124,7 +151,9 @@ func (s *Manager) ValidateMacaroon(ctx context.Context,
124
151
defer s .mu .RUnlock ()
125
152
126
153
for _ , ss := range s .servers {
127
- // TODO(positiveblue): check subserver permissions.
154
+ if ! s .permsMgr .IsSubServerURI (ss .subServer .Name (), uri ) {
155
+ continue
156
+ }
128
157
129
158
// If the sub-server is running in remote mode, then we don't
130
159
// need to validate the macaroon here since the remote server
0 commit comments