1- package terminal
1+ package perms
22
33import (
44 "net"
@@ -30,9 +30,9 @@ import (
3030)
3131
3232var (
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
3434 // macaroon permissions to access the session service.
35- litPermissions = map [string ][]bakery.Op {
35+ LitPermissions = map [string ][]bakery.Op {
3636 "/litrpc.Sessions/AddSession" : {{
3737 Entity : "sessions" ,
3838 Action : "write" ,
@@ -93,15 +93,15 @@ const (
9393 lndPerms subServerName = "lnd"
9494)
9595
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 {
9898 // lndSubServerPerms is a map from LND subserver name to permissions
9999 // map. This is used once the manager receives a list of build tags
100100 // that LND has been compiled with so that the correct permissions can
101101 // be extracted based on subservers that LND has been compiled with.
102102 lndSubServerPerms map [string ]map [string ][]bakery.Op
103103
104- // fixedPerms is constructed once on creation of the PermissionsManager .
104+ // fixedPerms is constructed once on creation of the Manager .
105105 // It contains all the permissions that will not change throughout the
106106 // lifetime of the manager. It maps sub-server name to uri to permission
107107 // operations.
@@ -117,14 +117,14 @@ type PermissionsManager struct {
117117 permsMu sync.RWMutex
118118}
119119
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 ) {
123123 permissions := make (map [subServerName ]map [string ][]bakery.Op )
124124 permissions [faradayPerms ] = faraday .RequiredPermissions
125125 permissions [loopPerms ] = loop .RequiredPermissions
126126 permissions [poolPerms ] = pool .RequiredPermissions
127- permissions [litPerms ] = litPermissions
127+ permissions [litPerms ] = LitPermissions
128128 permissions [lndPerms ] = lnd .MainRPCServerPermissions ()
129129 for k , v := range whiteListedLNDMethods {
130130 permissions [lndPerms ][k ] = v
@@ -163,7 +163,7 @@ func NewPermissionsManager() (*PermissionsManager, error) {
163163 }
164164 }
165165
166- return & PermissionsManager {
166+ return & Manager {
167167 lndSubServerPerms : lndSubServerPerms ,
168168 fixedPerms : permissions ,
169169 perms : allPerms ,
@@ -174,7 +174,7 @@ func NewPermissionsManager() (*PermissionsManager, error) {
174174// obtained. It then uses those build tags to decide which of the LND sub-server
175175// permissions to add to the main permissions list. This method should only
176176// be called once.
177- func (pm * PermissionsManager ) OnLNDBuildTags (lndBuildTags []string ) {
177+ func (pm * Manager ) OnLNDBuildTags (lndBuildTags []string ) {
178178 pm .permsMu .Lock ()
179179 defer pm .permsMu .Unlock ()
180180
@@ -202,7 +202,7 @@ func (pm *PermissionsManager) OnLNDBuildTags(lndBuildTags []string) {
202202// URIPermissions returns a list of permission operations for the given URI if
203203// the uri is known to the manager. The second return parameter will be false
204204// 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 ) {
206206 pm .permsMu .RLock ()
207207 defer pm .permsMu .RUnlock ()
208208
@@ -213,7 +213,7 @@ func (pm *PermissionsManager) URIPermissions(uri string) ([]bakery.Op, bool) {
213213// ActivePermissions returns all the available active permissions that the
214214// manager is aware of. Optionally, readOnly can be set to true if only the
215215// read-only permissions should be returned.
216- func (pm * PermissionsManager ) ActivePermissions (readOnly bool ) []bakery.Op {
216+ func (pm * Manager ) ActivePermissions (readOnly bool ) []bakery.Op {
217217 pm .permsMu .RLock ()
218218 defer pm .permsMu .RUnlock ()
219219
@@ -254,7 +254,7 @@ func (pm *PermissionsManager) ActivePermissions(readOnly bool) []bakery.Op {
254254// GetLitPerms returns a map of all permissions that the manager is aware of
255255// _except_ for any LND permissions. In other words, this returns permissions
256256// 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 {
258258 mapSize := len (pm .fixedPerms [litPerms ]) +
259259 len (pm .fixedPerms [faradayPerms ]) +
260260 len (pm .fixedPerms [loopPerms ]) + len (pm .fixedPerms [poolPerms ])
@@ -276,7 +276,7 @@ func (pm *PermissionsManager) GetLitPerms() map[string][]bakery.Op {
276276}
277277
278278// 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 {
280280 var lndSubServerCall bool
281281 for _ , subserverPermissions := range pm .lndSubServerPerms {
282282 _ , found := subserverPermissions [uri ]
@@ -290,25 +290,25 @@ func (pm *PermissionsManager) IsLndURI(uri string) bool {
290290}
291291
292292// 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 {
294294 _ , ok := pm.fixedPerms [loopPerms ][uri ]
295295 return ok
296296}
297297
298298// 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 {
300300 _ , ok := pm.fixedPerms [faradayPerms ][uri ]
301301 return ok
302302}
303303
304304// 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 {
306306 _ , ok := pm.fixedPerms [poolPerms ][uri ]
307307 return ok
308308}
309309
310310// 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 {
312312 _ , ok := pm.fixedPerms [litPerms ][uri ]
313313 return ok
314314}
0 commit comments