1
- package terminal
1
+ package perms
2
2
3
3
import (
4
4
"net"
@@ -30,9 +30,9 @@ import (
30
30
)
31
31
32
32
var (
33
- // litPermissions is a map of all LiT RPC methods and their required
33
+ // LitPermissions is a map of all LiT RPC methods and their required
34
34
// macaroon permissions to access the session service.
35
- litPermissions = map [string ][]bakery.Op {
35
+ LitPermissions = map [string ][]bakery.Op {
36
36
"/litrpc.Sessions/AddSession" : {{
37
37
Entity : "sessions" ,
38
38
Action : "write" ,
@@ -93,15 +93,15 @@ const (
93
93
lndPerms subServerName = "lnd"
94
94
)
95
95
96
- // PermissionsManager manages the permission lists that Lit requires.
97
- type PermissionsManager struct {
96
+ // Manager manages the permission lists that Lit requires.
97
+ type Manager struct {
98
98
// lndSubServerPerms is a map from LND subserver name to permissions
99
99
// map. This is used once the manager receives a list of build tags
100
100
// that LND has been compiled with so that the correct permissions can
101
101
// be extracted based on subservers that LND has been compiled with.
102
102
lndSubServerPerms map [string ]map [string ][]bakery.Op
103
103
104
- // fixedPerms is constructed once on creation of the PermissionsManager .
104
+ // fixedPerms is constructed once on creation of the Manager .
105
105
// It contains all the permissions that will not change throughout the
106
106
// lifetime of the manager. It maps sub-server name to uri to permission
107
107
// operations.
@@ -117,14 +117,14 @@ type PermissionsManager struct {
117
117
permsMu sync.RWMutex
118
118
}
119
119
120
- // NewPermissionsManager constructs a new PermissionsManager instance and
121
- // collects any of the fixed permissions.
122
- func NewPermissionsManager () (* PermissionsManager , error ) {
120
+ // NewManager constructs a new Manager instance and collects any of the fixed
121
+ // permissions.
122
+ func NewManager () (* Manager , error ) {
123
123
permissions := make (map [subServerName ]map [string ][]bakery.Op )
124
124
permissions [faradayPerms ] = faraday .RequiredPermissions
125
125
permissions [loopPerms ] = loop .RequiredPermissions
126
126
permissions [poolPerms ] = pool .RequiredPermissions
127
- permissions [litPerms ] = litPermissions
127
+ permissions [litPerms ] = LitPermissions
128
128
permissions [lndPerms ] = lnd .MainRPCServerPermissions ()
129
129
for k , v := range whiteListedLNDMethods {
130
130
permissions [lndPerms ][k ] = v
@@ -163,7 +163,7 @@ func NewPermissionsManager() (*PermissionsManager, error) {
163
163
}
164
164
}
165
165
166
- return & PermissionsManager {
166
+ return & Manager {
167
167
lndSubServerPerms : lndSubServerPerms ,
168
168
fixedPerms : permissions ,
169
169
perms : allPerms ,
@@ -174,7 +174,7 @@ func NewPermissionsManager() (*PermissionsManager, error) {
174
174
// obtained. It then uses those build tags to decide which of the LND sub-server
175
175
// permissions to add to the main permissions list. This method should only
176
176
// be called once.
177
- func (pm * PermissionsManager ) OnLNDBuildTags (lndBuildTags []string ) {
177
+ func (pm * Manager ) OnLNDBuildTags (lndBuildTags []string ) {
178
178
pm .permsMu .Lock ()
179
179
defer pm .permsMu .Unlock ()
180
180
@@ -202,7 +202,7 @@ func (pm *PermissionsManager) OnLNDBuildTags(lndBuildTags []string) {
202
202
// URIPermissions returns a list of permission operations for the given URI if
203
203
// the uri is known to the manager. The second return parameter will be false
204
204
// if the URI is unknown to the manager.
205
- func (pm * PermissionsManager ) URIPermissions (uri string ) ([]bakery.Op , bool ) {
205
+ func (pm * Manager ) URIPermissions (uri string ) ([]bakery.Op , bool ) {
206
206
pm .permsMu .RLock ()
207
207
defer pm .permsMu .RUnlock ()
208
208
@@ -213,7 +213,7 @@ func (pm *PermissionsManager) URIPermissions(uri string) ([]bakery.Op, bool) {
213
213
// ActivePermissions returns all the available active permissions that the
214
214
// manager is aware of. Optionally, readOnly can be set to true if only the
215
215
// read-only permissions should be returned.
216
- func (pm * PermissionsManager ) ActivePermissions (readOnly bool ) []bakery.Op {
216
+ func (pm * Manager ) ActivePermissions (readOnly bool ) []bakery.Op {
217
217
pm .permsMu .RLock ()
218
218
defer pm .permsMu .RUnlock ()
219
219
@@ -254,7 +254,7 @@ func (pm *PermissionsManager) ActivePermissions(readOnly bool) []bakery.Op {
254
254
// GetLitPerms returns a map of all permissions that the manager is aware of
255
255
// _except_ for any LND permissions. In other words, this returns permissions
256
256
// for which the external validator of Lit is responsible.
257
- func (pm * PermissionsManager ) GetLitPerms () map [string ][]bakery.Op {
257
+ func (pm * Manager ) GetLitPerms () map [string ][]bakery.Op {
258
258
mapSize := len (pm .fixedPerms [litPerms ]) +
259
259
len (pm .fixedPerms [faradayPerms ]) +
260
260
len (pm .fixedPerms [loopPerms ]) + len (pm .fixedPerms [poolPerms ])
@@ -276,7 +276,7 @@ func (pm *PermissionsManager) GetLitPerms() map[string][]bakery.Op {
276
276
}
277
277
278
278
// IsLndURI returns true if the given URI belongs to an RPC of lnd.
279
- func (pm * PermissionsManager ) IsLndURI (uri string ) bool {
279
+ func (pm * Manager ) IsLndURI (uri string ) bool {
280
280
var lndSubServerCall bool
281
281
for _ , subserverPermissions := range pm .lndSubServerPerms {
282
282
_ , found := subserverPermissions [uri ]
@@ -290,25 +290,25 @@ func (pm *PermissionsManager) IsLndURI(uri string) bool {
290
290
}
291
291
292
292
// IsLoopURI returns true if the given URI belongs to an RPC of loopd.
293
- func (pm * PermissionsManager ) IsLoopURI (uri string ) bool {
293
+ func (pm * Manager ) IsLoopURI (uri string ) bool {
294
294
_ , ok := pm.fixedPerms [loopPerms ][uri ]
295
295
return ok
296
296
}
297
297
298
298
// IsFaradayURI returns true if the given URI belongs to an RPC of faraday.
299
- func (pm * PermissionsManager ) IsFaradayURI (uri string ) bool {
299
+ func (pm * Manager ) IsFaradayURI (uri string ) bool {
300
300
_ , ok := pm.fixedPerms [faradayPerms ][uri ]
301
301
return ok
302
302
}
303
303
304
304
// IsPoolURI returns true if the given URI belongs to an RPC of poold.
305
- func (pm * PermissionsManager ) IsPoolURI (uri string ) bool {
305
+ func (pm * Manager ) IsPoolURI (uri string ) bool {
306
306
_ , ok := pm.fixedPerms [poolPerms ][uri ]
307
307
return ok
308
308
}
309
309
310
310
// IsLitURI returns true if the given URI belongs to an RPC of LiT.
311
- func (pm * PermissionsManager ) IsLitURI (uri string ) bool {
311
+ func (pm * Manager ) IsLitURI (uri string ) bool {
312
312
_ , ok := pm.fixedPerms [litPerms ][uri ]
313
313
return ok
314
314
}
0 commit comments