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:
6 files changed
+1070
-741
No files matched your search
@@ -137,6 +137,8 @@ http:
|
|||||||
get: "/v1/macaroon/ids"
|
get: "/v1/macaroon/ids"
|
||||||
- selector: lnrpc.Lightning.DeleteMacaroonID
|
- selector: lnrpc.Lightning.DeleteMacaroonID
|
||||||
delete: "/v1/macaroon/{root_key_id}"
|
delete: "/v1/macaroon/{root_key_id}"
|
||||||
|
- selector: lnrpc.Lightning.ListPermissions
|
||||||
|
get: "/v1/macaroon/permissions"
|
||||||
|
|
||||||
# walletunlocker.proto
|
# walletunlocker.proto
|
||||||
- selector: lnrpc.WalletUnlocker.GenSeed
|
- selector: lnrpc.WalletUnlocker.GenSeed
|
||||||
|
|||||||
+906
-741
File diff suppressed because it is too large.
Load diff
@@ -1985,6 +1985,24 @@ func local_request_Lightning_DeleteMacaroonID_0(ctx context.Context, marshaler r
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func request_Lightning_ListPermissions_0(ctx context.Context, marshaler runtime.Marshaler, client LightningClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||||
|
var protoReq ListPermissionsRequest
|
||||||
|
var metadata runtime.ServerMetadata
|
||||||
|
|
||||||
|
msg, err := client.ListPermissions(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||||
|
return msg, metadata, err
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func local_request_Lightning_ListPermissions_0(ctx context.Context, marshaler runtime.Marshaler, server LightningServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||||
|
var protoReq ListPermissionsRequest
|
||||||
|
var metadata runtime.ServerMetadata
|
||||||
|
|
||||||
|
msg, err := server.ListPermissions(ctx, &protoReq)
|
||||||
|
return msg, metadata, err
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// RegisterLightningHandlerServer registers the http handlers for service Lightning to "mux".
|
// RegisterLightningHandlerServer registers the http handlers for service Lightning to "mux".
|
||||||
// UnaryRPC :call LightningServer directly.
|
// UnaryRPC :call LightningServer directly.
|
||||||
// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906.
|
// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906.
|
||||||
@@ -2986,6 +3004,26 @@ func RegisterLightningHandlerServer(ctx context.Context, mux *runtime.ServeMux,
|
|||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
mux.Handle("GET", pattern_Lightning_ListPermissions_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||||
|
ctx, cancel := context.WithCancel(req.Context())
|
||||||
|
defer cancel()
|
||||||
|
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||||
|
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req)
|
||||||
|
if err != nil {
|
||||||
|
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resp, md, err := local_request_Lightning_ListPermissions_0(rctx, inboundMarshaler, server, req, pathParams)
|
||||||
|
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||||
|
if err != nil {
|
||||||
|
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
forward_Lightning_ListPermissions_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4127,6 +4165,26 @@ func RegisterLightningHandlerClient(ctx context.Context, mux *runtime.ServeMux,
|
|||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
mux.Handle("GET", pattern_Lightning_ListPermissions_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||||
|
ctx, cancel := context.WithCancel(req.Context())
|
||||||
|
defer cancel()
|
||||||
|
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||||
|
rctx, err := runtime.AnnotateContext(ctx, mux, req)
|
||||||
|
if err != nil {
|
||||||
|
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resp, md, err := request_Lightning_ListPermissions_0(rctx, inboundMarshaler, client, req, pathParams)
|
||||||
|
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||||
|
if err != nil {
|
||||||
|
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
forward_Lightning_ListPermissions_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4240,6 +4298,8 @@ var (
|
|||||||
pattern_Lightning_ListMacaroonIDs_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "macaroon", "ids"}, "", runtime.AssumeColonVerbOpt(true)))
|
pattern_Lightning_ListMacaroonIDs_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "macaroon", "ids"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||||
|
|
||||||
pattern_Lightning_DeleteMacaroonID_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2}, []string{"v1", "macaroon", "root_key_id"}, "", runtime.AssumeColonVerbOpt(true)))
|
pattern_Lightning_DeleteMacaroonID_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2}, []string{"v1", "macaroon", "root_key_id"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||||
|
|
||||||
|
pattern_Lightning_ListPermissions_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "macaroon", "permissions"}, "", runtime.AssumeColonVerbOpt(true)))
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -4352,4 +4412,6 @@ var (
|
|||||||
forward_Lightning_ListMacaroonIDs_0 = runtime.ForwardResponseMessage
|
forward_Lightning_ListMacaroonIDs_0 = runtime.ForwardResponseMessage
|
||||||
|
|
||||||
forward_Lightning_DeleteMacaroonID_0 = runtime.ForwardResponseMessage
|
forward_Lightning_DeleteMacaroonID_0 = runtime.ForwardResponseMessage
|
||||||
|
|
||||||
|
forward_Lightning_ListPermissions_0 = runtime.ForwardResponseMessage
|
||||||
)
|
)
|
||||||
@@ -506,6 +506,13 @@ service Lightning {
|
|||||||
*/
|
*/
|
||||||
rpc DeleteMacaroonID (DeleteMacaroonIDRequest)
|
rpc DeleteMacaroonID (DeleteMacaroonIDRequest)
|
||||||
returns (DeleteMacaroonIDResponse);
|
returns (DeleteMacaroonIDResponse);
|
||||||
|
|
||||||
|
/* lncli: `listpermissions`
|
||||||
|
ListPermissions lists all RPC method URIs and their required macaroon
|
||||||
|
permissions to access them.
|
||||||
|
*/
|
||||||
|
rpc ListPermissions (ListPermissionsRequest)
|
||||||
|
returns (ListPermissionsResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
message Utxo {
|
message Utxo {
|
||||||
@@ -3375,6 +3382,21 @@ message DeleteMacaroonIDResponse {
|
|||||||
bool deleted = 1;
|
bool deleted = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message MacaroonPermissionList {
|
||||||
|
// A list of macaroon permissions.
|
||||||
|
repeated MacaroonPermission permissions = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message ListPermissionsRequest {
|
||||||
|
}
|
||||||
|
message ListPermissionsResponse {
|
||||||
|
/*
|
||||||
|
A map between all RPC method URIs and their required macaroon permissions to
|
||||||
|
access them.
|
||||||
|
*/
|
||||||
|
map<string, MacaroonPermissionList> method_permissions = 1;
|
||||||
|
}
|
||||||
|
|
||||||
message Failure {
|
message Failure {
|
||||||
enum FailureCode {
|
enum FailureCode {
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -1456,6 +1456,29 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/v1/macaroon/permissions": {
|
||||||
|
"get": {
|
||||||
|
"summary": "lncli: `listpermissions`\nListPermissions lists all RPC method URIs and their required macaroon\npermissions to access them.",
|
||||||
|
"operationId": "ListPermissions",
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "A successful response.",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/lnrpcListPermissionsResponse"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"default": {
|
||||||
|
"description": "An unexpected error response",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/runtimeError"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"tags": [
|
||||||
|
"Lightning"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
"/v1/macaroon/{root_key_id}": {
|
"/v1/macaroon/{root_key_id}": {
|
||||||
"delete": {
|
"delete": {
|
||||||
"summary": "lncli: `deletemacaroonid`\nDeleteMacaroonID deletes the specified macaroon ID and invalidates all\nmacaroons derived from that ID.",
|
"summary": "lncli: `deletemacaroonid`\nDeleteMacaroonID deletes the specified macaroon ID and invalidates all\nmacaroons derived from that ID.",
|
||||||
@@ -4220,6 +4243,18 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"lnrpcListPermissionsResponse": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"method_permissions": {
|
||||||
|
"type": "object",
|
||||||
|
"additionalProperties": {
|
||||||
|
"$ref": "#/definitions/lnrpcMacaroonPermissionList"
|
||||||
|
},
|
||||||
|
"description": "A map between all RPC method URIs and their required macaroon permissions to\naccess them."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"lnrpcListUnspentResponse": {
|
"lnrpcListUnspentResponse": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
@@ -4260,6 +4295,18 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"lnrpcMacaroonPermissionList": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"permissions": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/definitions/lnrpcMacaroonPermission"
|
||||||
|
},
|
||||||
|
"description": "A list of macaroon permissions."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"lnrpcMultiChanBackup": {
|
"lnrpcMultiChanBackup": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
|||||||
@@ -453,6 +453,10 @@ func mainRPCServerPermissions() map[string][]bakery.Op {
|
|||||||
Entity: "macaroon",
|
Entity: "macaroon",
|
||||||
Action: "write",
|
Action: "write",
|
||||||
}},
|
}},
|
||||||
|
"/lnrpc.Lightning/ListPermissions": {{
|
||||||
|
Entity: "info",
|
||||||
|
Action: "read",
|
||||||
|
}},
|
||||||
"/lnrpc.Lightning/SubscribePeerEvents": {{
|
"/lnrpc.Lightning/SubscribePeerEvents": {{
|
||||||
Entity: "peers",
|
Entity: "peers",
|
||||||
Action: "read",
|
Action: "read",
|
||||||
@@ -6572,6 +6576,33 @@ func (r *rpcServer) DeleteMacaroonID(ctx context.Context,
|
|||||||
}, nil
|
}, 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
|
// FundingStateStep is an advanced funding related call that allows the caller
|
||||||
// to either execute some preparatory steps for a funding workflow, or manually
|
// 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
|
// progress a funding workflow. The primary way a funding flow is identified is
|
||||||
|
|||||||
Reference in new issue
Block a user