Skip to content

Commit d41f796

Browse files
committed
multi: move permissions' manager to perms folder
1 parent 98513f7 commit d41f796

File tree

5 files changed

+32
-28
lines changed

5 files changed

+32
-28
lines changed

itest/litd_mode_integrated_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/lightninglabs/lightning-node-connect/mailbox"
2222
terminal "github.com/lightninglabs/lightning-terminal"
2323
"github.com/lightninglabs/lightning-terminal/litrpc"
24+
"github.com/lightninglabs/lightning-terminal/perms"
2425
"github.com/lightninglabs/lightning-terminal/session"
2526
"github.com/lightninglabs/loop/looprpc"
2627
"github.com/lightninglabs/pool/poolrpc"
@@ -945,7 +946,7 @@ func bakeSuperMacaroon(cfg *LitNodeConfig, readOnly bool) (string, error) {
945946
lndAdminCtx := macaroonContext(ctxt, lndAdminMacBytes)
946947
lndConn := lnrpc.NewLightningClient(rawConn)
947948

948-
permsMgr, err := terminal.NewPermissionsManager()
949+
permsMgr, err := perms.NewManager()
949950
if err != nil {
950951
return "", err
951952
}

subserver_permissions.go renamed to perms/permissions.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package terminal
1+
package perms
22

33
import (
44
"net"
@@ -30,9 +30,9 @@ import (
3030
)
3131

3232
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
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
}

rpc_proxy.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"time"
1414

1515
"github.com/improbable-eng/grpc-web/go/grpcweb"
16+
"github.com/lightninglabs/lightning-terminal/perms"
1617
"github.com/lightninglabs/lightning-terminal/session"
1718
"github.com/lightningnetwork/lnd/lncfg"
1819
"github.com/lightningnetwork/lnd/macaroons"
@@ -58,7 +59,7 @@ func (e *proxyErr) Unwrap() error {
5859
// component.
5960
func newRpcProxy(cfg *Config, validator macaroons.MacaroonValidator,
6061
superMacValidator session.SuperMacaroonValidator,
61-
permsMgr *PermissionsManager, bufListener *bufconn.Listener) *rpcProxy {
62+
permsMgr *perms.Manager, bufListener *bufconn.Listener) *rpcProxy {
6263

6364
// The gRPC web calls are protected by HTTP basic auth which is defined
6465
// by base64(username:password). Because we only have a password, we
@@ -146,7 +147,7 @@ func newRpcProxy(cfg *Config, validator macaroons.MacaroonValidator,
146147
type rpcProxy struct {
147148
cfg *Config
148149
basicAuth string
149-
permsMgr *PermissionsManager
150+
permsMgr *perms.Manager
150151

151152
macValidator macaroons.MacaroonValidator
152153
superMacValidator session.SuperMacaroonValidator

session_rpcserver.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/btcsuite/btcd/btcec/v2"
1111
"github.com/lightninglabs/lightning-node-connect/mailbox"
1212
"github.com/lightninglabs/lightning-terminal/litrpc"
13+
"github.com/lightninglabs/lightning-terminal/perms"
1314
"github.com/lightninglabs/lightning-terminal/session"
1415
"github.com/lightningnetwork/lnd/macaroons"
1516
"google.golang.org/grpc"
@@ -41,7 +42,7 @@ type sessionRpcServerConfig struct {
4142
superMacBaker func(ctx context.Context, rootKeyID uint64,
4243
recipe *session.MacaroonRecipe) (string, error)
4344
firstConnectionDeadline time.Duration
44-
permMgr *PermissionsManager
45+
permMgr *perms.Manager
4546
}
4647

4748
// newSessionRPCServer creates a new sessionRpcServer using the passed config.

terminal.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/lightninglabs/faraday/frdrpc"
2323
"github.com/lightninglabs/faraday/frdrpcserver"
2424
"github.com/lightninglabs/lightning-terminal/litrpc"
25+
"github.com/lightninglabs/lightning-terminal/perms"
2526
"github.com/lightninglabs/lightning-terminal/queue"
2627
mid "github.com/lightninglabs/lightning-terminal/rpcmiddleware"
2728
"github.com/lightninglabs/lightning-terminal/session"
@@ -136,7 +137,7 @@ type LightningTerminal struct {
136137

137138
defaultImplCfg *lnd.ImplementationCfg
138139

139-
permsMgr *PermissionsManager
140+
permsMgr *perms.Manager
140141

141142
// lndInterceptorChain is a reference to lnd's interceptor chain that
142143
// guards all incoming calls. This is only set in integrated mode!
@@ -204,8 +205,8 @@ func (g *LightningTerminal) Run() error {
204205
g.errQueue.Start()
205206
defer g.errQueue.Stop()
206207

207-
// Construct a new PermissionsManager.
208-
g.permsMgr, err = NewPermissionsManager()
208+
// Construct a new Manager.
209+
g.permsMgr, err = perms.NewManager()
209210
if err != nil {
210211
return fmt.Errorf("could not create permissions manager")
211212
}
@@ -589,7 +590,7 @@ func (g *LightningTerminal) startSubservers() error {
589590
DBPath: filepath.Join(g.cfg.LitDir, g.cfg.Network),
590591
MacaroonLocation: "litd",
591592
StatelessInit: !createDefaultMacaroons,
592-
RequiredPerms: litPermissions,
593+
RequiredPerms: perms.LitPermissions,
593594
LndClient: &g.lndClient.LndServices,
594595
EphemeralKey: lndclient.SharedKeyNUMS,
595596
KeyLocator: lndclient.SharedKeyLocator,

0 commit comments

Comments
 (0)