mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-29 18:10:48 +02:00
lnrpc+rpcserver: add ListPermissions RPC
As a convenience method for users to look up what RPC method URIs exist and what permissions they require, we add a new ListPermissions call that simply returns all registered URIs (including internal and external subservers) and their required permissions.
This commit is contained in:
31
rpcserver.go
31
rpcserver.go
@ -453,6 +453,10 @@ func mainRPCServerPermissions() map[string][]bakery.Op {
|
||||
Entity: "macaroon",
|
||||
Action: "write",
|
||||
}},
|
||||
"/lnrpc.Lightning/ListPermissions": {{
|
||||
Entity: "info",
|
||||
Action: "read",
|
||||
}},
|
||||
"/lnrpc.Lightning/SubscribePeerEvents": {{
|
||||
Entity: "peers",
|
||||
Action: "read",
|
||||
@ -6572,6 +6576,33 @@ func (r *rpcServer) DeleteMacaroonID(ctx context.Context,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// ListPermissions lists all RPC method URIs and their required macaroon
|
||||
// permissions to access them.
|
||||
func (r *rpcServer) ListPermissions(_ context.Context,
|
||||
_ *lnrpc.ListPermissionsRequest) (*lnrpc.ListPermissionsResponse,
|
||||
error) {
|
||||
|
||||
rpcsLog.Debugf("[listpermissions]")
|
||||
|
||||
permissionMap := make(map[string]*lnrpc.MacaroonPermissionList)
|
||||
for uri, perms := range r.allPermissions {
|
||||
rpcPerms := make([]*lnrpc.MacaroonPermission, len(perms))
|
||||
for idx, perm := range perms {
|
||||
rpcPerms[idx] = &lnrpc.MacaroonPermission{
|
||||
Entity: perm.Entity,
|
||||
Action: perm.Action,
|
||||
}
|
||||
}
|
||||
permissionMap[uri] = &lnrpc.MacaroonPermissionList{
|
||||
Permissions: rpcPerms,
|
||||
}
|
||||
}
|
||||
|
||||
return &lnrpc.ListPermissionsResponse{
|
||||
MethodPermissions: permissionMap,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// FundingStateStep is an advanced funding related call that allows the caller
|
||||
// to either execute some preparatory steps for a funding workflow, or manually
|
||||
// progress a funding workflow. The primary way a funding flow is identified is
|
||||
|
Reference in New Issue
Block a user