mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 01:43:16 +01:00
Rpcserver: Add GetAllPermissions function for retrieving permissions for external macaroon baking
This commit is contained in:
parent
57fc32fe6a
commit
218fa1e43e
36
rpcserver.go
36
rpcserver.go
@ -258,6 +258,42 @@ func calculateFeeRate(satPerByte, satPerVByte uint64, targetConf uint32,
|
||||
|
||||
}
|
||||
|
||||
// GetAllPermissions returns all the permissions required to interact with lnd.
|
||||
func GetAllPermissions() []bakery.Op {
|
||||
allPerms := make([]bakery.Op, 0)
|
||||
|
||||
// The map will help keep track of which specific permission pairs have
|
||||
// already been added to the slice.
|
||||
allPermsMap := make(map[string]map[string]struct{})
|
||||
|
||||
for _, perms := range MainRPCServerPermissions() {
|
||||
for _, perm := range perms {
|
||||
entity := perm.Entity
|
||||
action := perm.Action
|
||||
|
||||
// If this specific entity-action permission pair isn't
|
||||
// in the map yet. Add it to map, and the permission
|
||||
// slice.
|
||||
if acts, ok := allPermsMap[entity]; ok {
|
||||
if _, ok := acts[action]; !ok {
|
||||
allPermsMap[entity][action] = struct{}{}
|
||||
|
||||
allPerms = append(
|
||||
allPerms, perm,
|
||||
)
|
||||
}
|
||||
|
||||
} else {
|
||||
allPermsMap[entity] = make(map[string]struct{})
|
||||
allPermsMap[entity][action] = struct{}{}
|
||||
allPerms = append(allPerms, perm)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return allPerms
|
||||
}
|
||||
|
||||
// MainRPCServerPermissions returns a mapping of the main RPC server calls to
|
||||
// the permissions they require.
|
||||
func MainRPCServerPermissions() map[string][]bakery.Op {
|
||||
|
14
rpcserver_test.go
Normal file
14
rpcserver_test.go
Normal file
@ -0,0 +1,14 @@
|
||||
package lnd
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestGetAllPermissions(t *testing.T) {
|
||||
perms := GetAllPermissions()
|
||||
|
||||
// Currently there are there are 16 entity:action pairs in use.
|
||||
assert.Equal(t, len(perms), 16)
|
||||
}
|
Loading…
Reference in New Issue
Block a user