From e22f9e7b83f627f778f48d16fc128aab9695b934 Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Sun, 19 Mar 2023 20:01:04 +0200 Subject: [PATCH] litrpc: add Litd REST annotations --- litrpc/firewall.pb.gw.go | 248 ++++++++++++ litrpc/firewall.swagger.json | 283 +++++++++++++ litrpc/firewall.yaml | 13 + litrpc/gen_protos.sh | 25 +- litrpc/lit-accounts.pb.gw.go | 446 +++++++++++++++++++++ litrpc/lit-accounts.swagger.json | 305 ++++++++++++++ litrpc/lit-accounts.yaml | 17 + litrpc/lit-autopilot.pb.go | 1 + litrpc/lit-autopilot.pb.gw.go | 396 +++++++++++++++++++ litrpc/lit-autopilot.proto | 1 + litrpc/lit-autopilot.swagger.json | 637 ++++++++++++++++++++++++++++++ litrpc/lit-autopilot.yaml | 16 + litrpc/lit-sessions.pb.go | 1 + litrpc/lit-sessions.pb.gw.go | 331 ++++++++++++++++ litrpc/lit-sessions.proto | 1 + litrpc/lit-sessions.swagger.json | 520 ++++++++++++++++++++++++ litrpc/lit-sessions.yaml | 14 + litrpc/proxy.pb.gw.go | 232 +++++++++++ litrpc/proxy.swagger.json | 123 ++++++ litrpc/proxy.yaml | 12 + 20 files changed, 3618 insertions(+), 4 deletions(-) create mode 100644 litrpc/firewall.pb.gw.go create mode 100644 litrpc/firewall.swagger.json create mode 100644 litrpc/firewall.yaml create mode 100644 litrpc/lit-accounts.pb.gw.go create mode 100644 litrpc/lit-accounts.swagger.json create mode 100644 litrpc/lit-accounts.yaml create mode 100644 litrpc/lit-autopilot.pb.gw.go create mode 100644 litrpc/lit-autopilot.swagger.json create mode 100644 litrpc/lit-autopilot.yaml create mode 100644 litrpc/lit-sessions.pb.gw.go create mode 100644 litrpc/lit-sessions.swagger.json create mode 100644 litrpc/lit-sessions.yaml create mode 100644 litrpc/proxy.pb.gw.go create mode 100644 litrpc/proxy.swagger.json create mode 100644 litrpc/proxy.yaml diff --git a/litrpc/firewall.pb.gw.go b/litrpc/firewall.pb.gw.go new file mode 100644 index 00000000..3bd76652 --- /dev/null +++ b/litrpc/firewall.pb.gw.go @@ -0,0 +1,248 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: firewall.proto + +/* +Package litrpc is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package litrpc + +import ( + "context" + "io" + "net/http" + + "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" + "github.com/grpc-ecosystem/grpc-gateway/v2/utilities" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" + "google.golang.org/protobuf/proto" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = metadata.Join + +func request_Firewall_ListActions_0(ctx context.Context, marshaler runtime.Marshaler, client FirewallClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq ListActionsRequest + var metadata runtime.ServerMetadata + + newReader, berr := utilities.IOReaderFactory(req.Body) + if berr != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) + } + if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.ListActions(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Firewall_ListActions_0(ctx context.Context, marshaler runtime.Marshaler, server FirewallServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq ListActionsRequest + var metadata runtime.ServerMetadata + + newReader, berr := utilities.IOReaderFactory(req.Body) + if berr != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) + } + if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.ListActions(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Firewall_PrivacyMapConversion_0(ctx context.Context, marshaler runtime.Marshaler, client FirewallClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq PrivacyMapConversionRequest + var metadata runtime.ServerMetadata + + newReader, berr := utilities.IOReaderFactory(req.Body) + if berr != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) + } + if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.PrivacyMapConversion(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Firewall_PrivacyMapConversion_0(ctx context.Context, marshaler runtime.Marshaler, server FirewallServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq PrivacyMapConversionRequest + var metadata runtime.ServerMetadata + + newReader, berr := utilities.IOReaderFactory(req.Body) + if berr != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) + } + if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.PrivacyMapConversion(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterFirewallHandlerServer registers the http handlers for service Firewall to "mux". +// UnaryRPC :call FirewallServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterFirewallHandlerFromEndpoint instead. +func RegisterFirewallHandlerServer(ctx context.Context, mux *runtime.ServeMux, server FirewallServer) error { + + mux.Handle("POST", pattern_Firewall_ListActions_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/litrpc.Firewall/ListActions", runtime.WithHTTPPathPattern("/v1/firewall/actions")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Firewall_ListActions_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Firewall_ListActions_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("POST", pattern_Firewall_PrivacyMapConversion_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/litrpc.Firewall/PrivacyMapConversion", runtime.WithHTTPPathPattern("/v1/firewall/privacy_map/convert")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Firewall_PrivacyMapConversion_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Firewall_PrivacyMapConversion_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterFirewallHandlerFromEndpoint is same as RegisterFirewallHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterFirewallHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.Dial(endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterFirewallHandler(ctx, mux, conn) +} + +// RegisterFirewallHandler registers the http handlers for service Firewall to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterFirewallHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterFirewallHandlerClient(ctx, mux, NewFirewallClient(conn)) +} + +// RegisterFirewallHandlerClient registers the http handlers for service Firewall +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "FirewallClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "FirewallClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "FirewallClient" to call the correct interceptors. +func RegisterFirewallHandlerClient(ctx context.Context, mux *runtime.ServeMux, client FirewallClient) error { + + mux.Handle("POST", pattern_Firewall_ListActions_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, "/litrpc.Firewall/ListActions", runtime.WithHTTPPathPattern("/v1/firewall/actions")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Firewall_ListActions_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Firewall_ListActions_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("POST", pattern_Firewall_PrivacyMapConversion_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, "/litrpc.Firewall/PrivacyMapConversion", runtime.WithHTTPPathPattern("/v1/firewall/privacy_map/convert")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Firewall_PrivacyMapConversion_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Firewall_PrivacyMapConversion_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_Firewall_ListActions_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "firewall", "actions"}, "")) + + pattern_Firewall_PrivacyMapConversion_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v1", "firewall", "privacy_map", "convert"}, "")) +) + +var ( + forward_Firewall_ListActions_0 = runtime.ForwardResponseMessage + + forward_Firewall_PrivacyMapConversion_0 = runtime.ForwardResponseMessage +) diff --git a/litrpc/firewall.swagger.json b/litrpc/firewall.swagger.json new file mode 100644 index 00000000..e7bab1aa --- /dev/null +++ b/litrpc/firewall.swagger.json @@ -0,0 +1,283 @@ +{ + "swagger": "2.0", + "info": { + "title": "firewall.proto", + "version": "version not set" + }, + "tags": [ + { + "name": "Firewall" + } + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "paths": { + "/v1/firewall/actions": { + "post": { + "summary": "litcli: `actions`\nListActions will return a list of actions that have been performed on the\nnode. The actions that will be persisted depends on the value of the\n`--firewall.request-logger.level` config option. The default value of the\noption is the \"interceptor\" mode which will persist only the actions (with\nall request parameters) made with macaroons with caveats that force them\nto be checked by an rpc middleware interceptor. If the \"all\" mode is used\nthen all actions will be persisted but only full request parameters will\nonly be stored if the actions are interceptor actions, otherwise only the\nURI and timestamp of the actions will be stored. The \"full\" mode will\npersist all request data for all actions.", + "operationId": "Firewall_ListActions", + "responses": { + "200": { + "description": "A successful response.", + "schema": { + "$ref": "#/definitions/litrpcListActionsResponse" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "#/definitions/rpcStatus" + } + } + }, + "parameters": [ + { + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/litrpcListActionsRequest" + } + } + ], + "tags": [ + "Firewall" + ] + } + }, + "/v1/firewall/privacy_map/convert": { + "post": { + "summary": "litcli: `privacy`\nPrivacyMapConversion can be used map real values to their pseudo\ncounterpart and vice versa.", + "operationId": "Firewall_PrivacyMapConversion", + "responses": { + "200": { + "description": "A successful response.", + "schema": { + "$ref": "#/definitions/litrpcPrivacyMapConversionResponse" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "#/definitions/rpcStatus" + } + } + }, + "parameters": [ + { + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/litrpcPrivacyMapConversionRequest" + } + } + ], + "tags": [ + "Firewall" + ] + } + } + }, + "definitions": { + "litrpcAction": { + "type": "object", + "properties": { + "actor_name": { + "type": "string", + "description": "The name of the actor that initiated the action." + }, + "feature_name": { + "type": "string", + "description": "The name of the feature that triggered the action." + }, + "trigger": { + "type": "string", + "description": "A human readable reason that the action was performed." + }, + "intent": { + "type": "string", + "description": "A human readable string describing the intended outcome successfully\nperforming the action." + }, + "structured_json_data": { + "type": "string", + "description": "Structured info added by the action performer." + }, + "rpc_method": { + "type": "string", + "description": "The URI of the method called." + }, + "rpc_params_json": { + "type": "string", + "description": "The parameters of the method call in compact json form." + }, + "timestamp": { + "type": "string", + "format": "uint64", + "description": "The unix timestamp in seconds at which the action was attempted." + }, + "state": { + "$ref": "#/definitions/litrpcActionState", + "description": "The action state. See ActionState for the meaning of each state." + }, + "error_reason": { + "type": "string", + "description": "If the state is Error, then this string will show the human readable reason\nfor why the action errored out." + }, + "session_id": { + "type": "string", + "format": "byte", + "description": "The ID of the session under which the action was performed." + } + } + }, + "litrpcActionState": { + "type": "string", + "enum": [ + "STATE_UNKNOWN", + "STATE_PENDING", + "STATE_DONE", + "STATE_ERROR" + ], + "default": "STATE_UNKNOWN", + "description": " - STATE_UNKNOWN: No state was assigned to the action. This should never be the case.\n - STATE_PENDING: Pending means that the request resulting in the action being created\ncame through but that no response came back from the appropriate backend.\nThis means that the Action is either still being processed or that it\ndid not successfully complete.\n - STATE_DONE: Done means that the action successfully completed.\n - STATE_ERROR: Error means that the Action did not successfully complete." + }, + "litrpcListActionsRequest": { + "type": "object", + "properties": { + "feature_name": { + "type": "string", + "description": "The feature name which the filter the actions by. If left empty, all feature\nactions will be returned." + }, + "actor_name": { + "type": "string", + "description": "The actor name to filter on. If left empty, all actor actions will be\nreturned." + }, + "method_name": { + "type": "string", + "description": "The method name to filter on. If left empty, actions for any method will be\nreturned." + }, + "state": { + "$ref": "#/definitions/litrpcActionState", + "description": "The action state to filter on. If set to zero, actions for any state will\nbe returned." + }, + "index_offset": { + "type": "string", + "format": "uint64", + "description": "The index of an action that will be used as the start of a query to\ndetermine which actions should be returned in the response." + }, + "max_num_actions": { + "type": "string", + "format": "uint64", + "description": "The max number of actions to return in the response to this query." + }, + "reversed": { + "type": "boolean", + "description": "If set, the actions returned will result from seeking backwards from the\nspecified index offset. This can be used to paginate backwards." + }, + "count_total": { + "type": "boolean", + "description": "Set to true if the total number of all actions that match the given filters\nshould be counted and returned in the request. Note that setting this will\nsignificantly decrease the performance of the query if there are many\nactions in the db." + }, + "session_id": { + "type": "string", + "format": "byte", + "description": "The session ID to filter on. If left empty, actions for any session will\nbe returned." + }, + "start_timestamp": { + "type": "string", + "format": "uint64", + "description": "If specified, then only actions created after the given timestamp will be\nconsidered." + }, + "end_timestamp": { + "type": "string", + "format": "uint64", + "description": "If specified, then only actions created before the given timestamp will be\nconsidered." + } + } + }, + "litrpcListActionsResponse": { + "type": "object", + "properties": { + "actions": { + "type": "array", + "items": { + "$ref": "#/definitions/litrpcAction" + }, + "description": "A list of actions performed by the autopilot server." + }, + "last_index_offset": { + "type": "string", + "format": "uint64", + "description": "The index of the last item in the set of returned actions. This can be used\nto seek further, pagination style." + }, + "total_count": { + "type": "string", + "format": "uint64", + "description": "The total number of actions that matched the filter in the request. It is\nonly set if count_total was set in the request." + } + } + }, + "litrpcPrivacyMapConversionRequest": { + "type": "object", + "properties": { + "real_to_pseudo": { + "type": "boolean", + "description": "If set to true, then the input string will be taken as the real value and\nthe response will the the pseudo value it if exists. Otherwise, the input\nstring will be assumed to be the pseudo value." + }, + "session_id": { + "type": "string", + "format": "byte", + "description": "The session ID under which to search for the real-pseudo pair." + }, + "input": { + "type": "string", + "description": "The input to be converted into the real or pseudo value." + } + } + }, + "litrpcPrivacyMapConversionResponse": { + "type": "object", + "properties": { + "output": { + "type": "string", + "description": "The resulting real or pseudo output." + } + } + }, + "protobufAny": { + "type": "object", + "properties": { + "type_url": { + "type": "string" + }, + "value": { + "type": "string", + "format": "byte" + } + } + }, + "rpcStatus": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "format": "int32" + }, + "message": { + "type": "string" + }, + "details": { + "type": "array", + "items": { + "$ref": "#/definitions/protobufAny" + } + } + } + } + } +} diff --git a/litrpc/firewall.yaml b/litrpc/firewall.yaml new file mode 100644 index 00000000..bd726164 --- /dev/null +++ b/litrpc/firewall.yaml @@ -0,0 +1,13 @@ +type: google.api.Service +config_version: 3 + +http: + rules: + + # firewall.proto + - selector: litrpc.Firewall.ListActions + post: "/v1/firewall/actions" + body: "*" + - selector: litrpc.Firewall.PrivacyMapConversion + post: "/v1/firewall/privacy_map/convert" + body: "*" diff --git a/litrpc/gen_protos.sh b/litrpc/gen_protos.sh index d0de7d16..06734e67 100755 --- a/litrpc/gen_protos.sh +++ b/litrpc/gen_protos.sh @@ -11,11 +11,28 @@ function generate() { --go-grpc_out . --go-grpc_opt paths=source_relative \ "${file}" - # Only generate JSON/WASM stubs if requested. - if [[ "$1" == "no-wasm" ]]; then - return + # Only generate REST stubs if requested. + if [[ "$1" == "no-rest" ]]; then + continue fi + # Generate the REST reverse proxy. + annotationsFile=${file//proto/yaml} + protoc -I/usr/local/include -I. -I.. \ + --grpc-gateway_out . \ + --grpc-gateway_opt logtostderr=true \ + --grpc-gateway_opt paths=source_relative \ + --grpc-gateway_opt grpc_api_configuration=${annotationsFile} \ + "${file}" + + # Finally, generate the swagger file which describes the REST API in detail. + protoc -I/usr/local/include -I. -I.. \ + --openapiv2_out . \ + --openapiv2_opt logtostderr=true \ + --openapiv2_opt grpc_api_configuration=${annotationsFile} \ + --openapiv2_opt json_names_for_fields=false \ + "${file}" + # Generate the JSON/WASM autopilot stubs. falafel=$(which falafel) pkg="litrpc" @@ -41,5 +58,5 @@ popd pushd autopilotserverrpc format -generate no-wasm +generate no-rest popd \ No newline at end of file diff --git a/litrpc/lit-accounts.pb.gw.go b/litrpc/lit-accounts.pb.gw.go new file mode 100644 index 00000000..e8b727f5 --- /dev/null +++ b/litrpc/lit-accounts.pb.gw.go @@ -0,0 +1,446 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: lit-accounts.proto + +/* +Package litrpc is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package litrpc + +import ( + "context" + "io" + "net/http" + + "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" + "github.com/grpc-ecosystem/grpc-gateway/v2/utilities" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" + "google.golang.org/protobuf/proto" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = metadata.Join + +func request_Accounts_CreateAccount_0(ctx context.Context, marshaler runtime.Marshaler, client AccountsClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq CreateAccountRequest + var metadata runtime.ServerMetadata + + newReader, berr := utilities.IOReaderFactory(req.Body) + if berr != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) + } + if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.CreateAccount(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Accounts_CreateAccount_0(ctx context.Context, marshaler runtime.Marshaler, server AccountsServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq CreateAccountRequest + var metadata runtime.ServerMetadata + + newReader, berr := utilities.IOReaderFactory(req.Body) + if berr != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) + } + if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.CreateAccount(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Accounts_UpdateAccount_0(ctx context.Context, marshaler runtime.Marshaler, client AccountsClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq UpdateAccountRequest + var metadata runtime.ServerMetadata + + newReader, berr := utilities.IOReaderFactory(req.Body) + if berr != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) + } + if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") + } + + protoReq.Id, err = runtime.String(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) + } + + msg, err := client.UpdateAccount(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Accounts_UpdateAccount_0(ctx context.Context, marshaler runtime.Marshaler, server AccountsServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq UpdateAccountRequest + var metadata runtime.ServerMetadata + + newReader, berr := utilities.IOReaderFactory(req.Body) + if berr != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) + } + if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") + } + + protoReq.Id, err = runtime.String(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) + } + + msg, err := server.UpdateAccount(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Accounts_ListAccounts_0(ctx context.Context, marshaler runtime.Marshaler, client AccountsClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq ListAccountsRequest + var metadata runtime.ServerMetadata + + msg, err := client.ListAccounts(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Accounts_ListAccounts_0(ctx context.Context, marshaler runtime.Marshaler, server AccountsServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq ListAccountsRequest + var metadata runtime.ServerMetadata + + msg, err := server.ListAccounts(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Accounts_RemoveAccount_0(ctx context.Context, marshaler runtime.Marshaler, client AccountsClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq RemoveAccountRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") + } + + protoReq.Id, err = runtime.String(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) + } + + msg, err := client.RemoveAccount(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Accounts_RemoveAccount_0(ctx context.Context, marshaler runtime.Marshaler, server AccountsServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq RemoveAccountRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") + } + + protoReq.Id, err = runtime.String(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) + } + + msg, err := server.RemoveAccount(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterAccountsHandlerServer registers the http handlers for service Accounts to "mux". +// UnaryRPC :call AccountsServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterAccountsHandlerFromEndpoint instead. +func RegisterAccountsHandlerServer(ctx context.Context, mux *runtime.ServeMux, server AccountsServer) error { + + mux.Handle("POST", pattern_Accounts_CreateAccount_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/litrpc.Accounts/CreateAccount", runtime.WithHTTPPathPattern("/v1/accounts")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Accounts_CreateAccount_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Accounts_CreateAccount_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("POST", pattern_Accounts_UpdateAccount_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/litrpc.Accounts/UpdateAccount", runtime.WithHTTPPathPattern("/v1/accounts/{id}")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Accounts_UpdateAccount_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Accounts_UpdateAccount_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Accounts_ListAccounts_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/litrpc.Accounts/ListAccounts", runtime.WithHTTPPathPattern("/v1/accounts")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Accounts_ListAccounts_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Accounts_ListAccounts_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("DELETE", pattern_Accounts_RemoveAccount_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/litrpc.Accounts/RemoveAccount", runtime.WithHTTPPathPattern("/v1/accounts/{id}")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Accounts_RemoveAccount_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Accounts_RemoveAccount_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterAccountsHandlerFromEndpoint is same as RegisterAccountsHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterAccountsHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.Dial(endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterAccountsHandler(ctx, mux, conn) +} + +// RegisterAccountsHandler registers the http handlers for service Accounts to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterAccountsHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterAccountsHandlerClient(ctx, mux, NewAccountsClient(conn)) +} + +// RegisterAccountsHandlerClient registers the http handlers for service Accounts +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "AccountsClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "AccountsClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "AccountsClient" to call the correct interceptors. +func RegisterAccountsHandlerClient(ctx context.Context, mux *runtime.ServeMux, client AccountsClient) error { + + mux.Handle("POST", pattern_Accounts_CreateAccount_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, "/litrpc.Accounts/CreateAccount", runtime.WithHTTPPathPattern("/v1/accounts")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Accounts_CreateAccount_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Accounts_CreateAccount_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("POST", pattern_Accounts_UpdateAccount_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, "/litrpc.Accounts/UpdateAccount", runtime.WithHTTPPathPattern("/v1/accounts/{id}")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Accounts_UpdateAccount_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Accounts_UpdateAccount_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Accounts_ListAccounts_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, "/litrpc.Accounts/ListAccounts", runtime.WithHTTPPathPattern("/v1/accounts")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Accounts_ListAccounts_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Accounts_ListAccounts_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("DELETE", pattern_Accounts_RemoveAccount_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, "/litrpc.Accounts/RemoveAccount", runtime.WithHTTPPathPattern("/v1/accounts/{id}")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Accounts_RemoveAccount_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Accounts_RemoveAccount_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_Accounts_CreateAccount_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "accounts"}, "")) + + pattern_Accounts_UpdateAccount_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2}, []string{"v1", "accounts", "id"}, "")) + + pattern_Accounts_ListAccounts_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "accounts"}, "")) + + pattern_Accounts_RemoveAccount_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2}, []string{"v1", "accounts", "id"}, "")) +) + +var ( + forward_Accounts_CreateAccount_0 = runtime.ForwardResponseMessage + + forward_Accounts_UpdateAccount_0 = runtime.ForwardResponseMessage + + forward_Accounts_ListAccounts_0 = runtime.ForwardResponseMessage + + forward_Accounts_RemoveAccount_0 = runtime.ForwardResponseMessage +) diff --git a/litrpc/lit-accounts.swagger.json b/litrpc/lit-accounts.swagger.json new file mode 100644 index 00000000..18bfb60f --- /dev/null +++ b/litrpc/lit-accounts.swagger.json @@ -0,0 +1,305 @@ +{ + "swagger": "2.0", + "info": { + "title": "lit-accounts.proto", + "version": "version not set" + }, + "tags": [ + { + "name": "Accounts" + } + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "paths": { + "/v1/accounts": { + "get": { + "summary": "litcli: `accounts list`\nListAccounts returns all accounts that are currently stored in the account\ndatabase.", + "operationId": "Accounts_ListAccounts", + "responses": { + "200": { + "description": "A successful response.", + "schema": { + "$ref": "#/definitions/litrpcListAccountsResponse" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "#/definitions/rpcStatus" + } + } + }, + "tags": [ + "Accounts" + ] + }, + "post": { + "summary": "litcli: `accounts create`\nCreateAccount adds an entry to the account database. This entry represents\nan amount of satoshis (account balance) that can be spent using off-chain\ntransactions (e.g. paying invoices).", + "description": "Macaroons can be created to be locked to an account. This makes sure that\nthe bearer of the macaroon can only spend at most that amount of satoshis\nthrough the daemon that has issued the macaroon.\n\nAccounts only assert a maximum amount spendable. Having a certain account\nbalance does not guarantee that the node has the channel liquidity to\nactually spend that amount.", + "operationId": "Accounts_CreateAccount", + "responses": { + "200": { + "description": "A successful response.", + "schema": { + "$ref": "#/definitions/litrpcCreateAccountResponse" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "#/definitions/rpcStatus" + } + } + }, + "parameters": [ + { + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/litrpcCreateAccountRequest" + } + } + ], + "tags": [ + "Accounts" + ] + } + }, + "/v1/accounts/{id}": { + "delete": { + "summary": "litcli: `accounts remove`\nRemoveAccount removes the given account from the account database.", + "operationId": "Accounts_RemoveAccount", + "responses": { + "200": { + "description": "A successful response.", + "schema": { + "$ref": "#/definitions/litrpcRemoveAccountResponse" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "#/definitions/rpcStatus" + } + } + }, + "parameters": [ + { + "name": "id", + "description": "The hexadecimal ID of the account to remove.", + "in": "path", + "required": true, + "type": "string" + } + ], + "tags": [ + "Accounts" + ] + }, + "post": { + "summary": "litcli: `accounts update`\nUpdateAccount updates an existing account in the account database.", + "operationId": "Accounts_UpdateAccount", + "responses": { + "200": { + "description": "A successful response.", + "schema": { + "$ref": "#/definitions/litrpcAccount" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "#/definitions/rpcStatus" + } + } + }, + "parameters": [ + { + "name": "id", + "description": "The ID of the account to update.", + "in": "path", + "required": true, + "type": "string" + }, + { + "name": "body", + "in": "body", + "required": true, + "schema": { + "type": "object", + "properties": { + "account_balance": { + "type": "string", + "format": "int64", + "description": "The new account balance to set. Set to -1 to not update the balance." + }, + "expiration_date": { + "type": "string", + "format": "int64", + "description": "The new account expiry to set. Set to -1 to not update the expiry. Set to 0\nto never expire." + } + } + } + } + ], + "tags": [ + "Accounts" + ] + } + } + }, + "definitions": { + "litrpcAccount": { + "type": "object", + "properties": { + "id": { + "type": "string", + "description": "The ID of the account." + }, + "initial_balance": { + "type": "string", + "format": "uint64", + "description": "The initial balance in satoshis that was set when the account was created." + }, + "current_balance": { + "type": "string", + "format": "int64", + "description": "The current balance in satoshis." + }, + "last_update": { + "type": "string", + "format": "int64", + "description": "Timestamp of the last time the account was updated." + }, + "expiration_date": { + "type": "string", + "format": "int64", + "description": "Timestamp of the account's expiration date. Zero means it does not expire." + }, + "invoices": { + "type": "array", + "items": { + "$ref": "#/definitions/litrpcAccountInvoice" + }, + "description": "The list of invoices created by the account. An invoice created by an\naccount will credit the account balance if it is settled." + }, + "payments": { + "type": "array", + "items": { + "$ref": "#/definitions/litrpcAccountPayment" + }, + "description": "The list of payments made by the account. A payment made by an account will\ndebit the account balance if it is settled." + } + } + }, + "litrpcAccountInvoice": { + "type": "object", + "properties": { + "hash": { + "type": "string", + "format": "byte", + "description": "The payment hash of the invoice." + } + } + }, + "litrpcAccountPayment": { + "type": "object", + "properties": { + "hash": { + "type": "string", + "format": "byte", + "description": "The payment hash." + }, + "state": { + "type": "string", + "description": "The state of the payment as reported by lnd." + }, + "full_amount": { + "type": "string", + "format": "int64", + "description": "The full amount in satoshis reserved for this payment. This includes the\nrouting fee estimated by the fee limit of the payment request. The actual\ndebited amount will likely be lower if the fee is below the limit." + } + } + }, + "litrpcCreateAccountRequest": { + "type": "object", + "properties": { + "account_balance": { + "type": "string", + "format": "uint64", + "description": "The initial account balance in satoshis representing the maximum amount that\ncan be spent." + }, + "expiration_date": { + "type": "string", + "format": "int64", + "description": "The expiration date of the account as a timestamp. Set to 0 to never expire." + } + } + }, + "litrpcCreateAccountResponse": { + "type": "object", + "properties": { + "account": { + "$ref": "#/definitions/litrpcAccount", + "description": "The new account that was created." + }, + "macaroon": { + "type": "string", + "format": "byte", + "description": "The macaroon with all permissions required to access the account." + } + } + }, + "litrpcListAccountsResponse": { + "type": "object", + "properties": { + "accounts": { + "type": "array", + "items": { + "$ref": "#/definitions/litrpcAccount" + }, + "description": "All accounts in the account database." + } + } + }, + "litrpcRemoveAccountResponse": { + "type": "object" + }, + "protobufAny": { + "type": "object", + "properties": { + "type_url": { + "type": "string" + }, + "value": { + "type": "string", + "format": "byte" + } + } + }, + "rpcStatus": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "format": "int32" + }, + "message": { + "type": "string" + }, + "details": { + "type": "array", + "items": { + "$ref": "#/definitions/protobufAny" + } + } + } + } + } +} diff --git a/litrpc/lit-accounts.yaml b/litrpc/lit-accounts.yaml new file mode 100644 index 00000000..b4e9c773 --- /dev/null +++ b/litrpc/lit-accounts.yaml @@ -0,0 +1,17 @@ +type: google.api.Service +config_version: 3 + +http: + rules: + + # lit-accounts.proto + - selector: litrpc.Accounts.CreateAccount + post: "/v1/accounts" + body: "*" + - selector: litrpc.Accounts.UpdateAccount + post: "/v1/accounts/{id}" + body: "*" + - selector: litrpc.Accounts.ListAccounts + get: "/v1/accounts" + - selector: litrpc.Accounts.RemoveAccount + delete: "/v1/accounts/{id}" diff --git a/litrpc/lit-autopilot.pb.go b/litrpc/lit-autopilot.pb.go index aa162caf..2c48354e 100644 --- a/litrpc/lit-autopilot.pb.go +++ b/litrpc/lit-autopilot.pb.go @@ -409,6 +409,7 @@ type RevokeAutopilotSessionRequest struct { unknownFields protoimpl.UnknownFields // The local static public key of the Autopilot session to be revoked. + // When using REST, this field must be encoded as base64. LocalPublicKey []byte `protobuf:"bytes,1,opt,name=local_public_key,json=localPublicKey,proto3" json:"local_public_key,omitempty"` } diff --git a/litrpc/lit-autopilot.pb.gw.go b/litrpc/lit-autopilot.pb.gw.go new file mode 100644 index 00000000..a670ff61 --- /dev/null +++ b/litrpc/lit-autopilot.pb.gw.go @@ -0,0 +1,396 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: lit-autopilot.proto + +/* +Package litrpc is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package litrpc + +import ( + "context" + "io" + "net/http" + + "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" + "github.com/grpc-ecosystem/grpc-gateway/v2/utilities" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" + "google.golang.org/protobuf/proto" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = metadata.Join + +func request_Autopilot_ListAutopilotFeatures_0(ctx context.Context, marshaler runtime.Marshaler, client AutopilotClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq ListAutopilotFeaturesRequest + var metadata runtime.ServerMetadata + + msg, err := client.ListAutopilotFeatures(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Autopilot_ListAutopilotFeatures_0(ctx context.Context, marshaler runtime.Marshaler, server AutopilotServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq ListAutopilotFeaturesRequest + var metadata runtime.ServerMetadata + + msg, err := server.ListAutopilotFeatures(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Autopilot_AddAutopilotSession_0(ctx context.Context, marshaler runtime.Marshaler, client AutopilotClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq AddAutopilotSessionRequest + var metadata runtime.ServerMetadata + + newReader, berr := utilities.IOReaderFactory(req.Body) + if berr != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) + } + if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.AddAutopilotSession(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Autopilot_AddAutopilotSession_0(ctx context.Context, marshaler runtime.Marshaler, server AutopilotServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq AddAutopilotSessionRequest + var metadata runtime.ServerMetadata + + newReader, berr := utilities.IOReaderFactory(req.Body) + if berr != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) + } + if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.AddAutopilotSession(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Autopilot_ListAutopilotSessions_0(ctx context.Context, marshaler runtime.Marshaler, client AutopilotClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq ListAutopilotSessionsRequest + var metadata runtime.ServerMetadata + + msg, err := client.ListAutopilotSessions(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Autopilot_ListAutopilotSessions_0(ctx context.Context, marshaler runtime.Marshaler, server AutopilotServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq ListAutopilotSessionsRequest + var metadata runtime.ServerMetadata + + msg, err := server.ListAutopilotSessions(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Autopilot_RevokeAutopilotSession_0(ctx context.Context, marshaler runtime.Marshaler, client AutopilotClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq RevokeAutopilotSessionRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["local_public_key"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "local_public_key") + } + + protoReq.LocalPublicKey, err = runtime.Bytes(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "local_public_key", err) + } + + msg, err := client.RevokeAutopilotSession(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Autopilot_RevokeAutopilotSession_0(ctx context.Context, marshaler runtime.Marshaler, server AutopilotServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq RevokeAutopilotSessionRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["local_public_key"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "local_public_key") + } + + protoReq.LocalPublicKey, err = runtime.Bytes(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "local_public_key", err) + } + + msg, err := server.RevokeAutopilotSession(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterAutopilotHandlerServer registers the http handlers for service Autopilot to "mux". +// UnaryRPC :call AutopilotServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterAutopilotHandlerFromEndpoint instead. +func RegisterAutopilotHandlerServer(ctx context.Context, mux *runtime.ServeMux, server AutopilotServer) error { + + mux.Handle("GET", pattern_Autopilot_ListAutopilotFeatures_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/litrpc.Autopilot/ListAutopilotFeatures", runtime.WithHTTPPathPattern("/v1/autopilot/features")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Autopilot_ListAutopilotFeatures_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Autopilot_ListAutopilotFeatures_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("POST", pattern_Autopilot_AddAutopilotSession_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/litrpc.Autopilot/AddAutopilotSession", runtime.WithHTTPPathPattern("/v1/autopilot/sessions")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Autopilot_AddAutopilotSession_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Autopilot_AddAutopilotSession_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Autopilot_ListAutopilotSessions_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/litrpc.Autopilot/ListAutopilotSessions", runtime.WithHTTPPathPattern("/v1/autopilot/sessions")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Autopilot_ListAutopilotSessions_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Autopilot_ListAutopilotSessions_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("DELETE", pattern_Autopilot_RevokeAutopilotSession_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/litrpc.Autopilot/RevokeAutopilotSession", runtime.WithHTTPPathPattern("/v1/autopilot/sessions/{local_public_key}")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Autopilot_RevokeAutopilotSession_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Autopilot_RevokeAutopilotSession_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterAutopilotHandlerFromEndpoint is same as RegisterAutopilotHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterAutopilotHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.Dial(endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterAutopilotHandler(ctx, mux, conn) +} + +// RegisterAutopilotHandler registers the http handlers for service Autopilot to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterAutopilotHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterAutopilotHandlerClient(ctx, mux, NewAutopilotClient(conn)) +} + +// RegisterAutopilotHandlerClient registers the http handlers for service Autopilot +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "AutopilotClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "AutopilotClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "AutopilotClient" to call the correct interceptors. +func RegisterAutopilotHandlerClient(ctx context.Context, mux *runtime.ServeMux, client AutopilotClient) error { + + mux.Handle("GET", pattern_Autopilot_ListAutopilotFeatures_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, "/litrpc.Autopilot/ListAutopilotFeatures", runtime.WithHTTPPathPattern("/v1/autopilot/features")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Autopilot_ListAutopilotFeatures_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Autopilot_ListAutopilotFeatures_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("POST", pattern_Autopilot_AddAutopilotSession_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, "/litrpc.Autopilot/AddAutopilotSession", runtime.WithHTTPPathPattern("/v1/autopilot/sessions")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Autopilot_AddAutopilotSession_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Autopilot_AddAutopilotSession_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Autopilot_ListAutopilotSessions_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, "/litrpc.Autopilot/ListAutopilotSessions", runtime.WithHTTPPathPattern("/v1/autopilot/sessions")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Autopilot_ListAutopilotSessions_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Autopilot_ListAutopilotSessions_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("DELETE", pattern_Autopilot_RevokeAutopilotSession_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, "/litrpc.Autopilot/RevokeAutopilotSession", runtime.WithHTTPPathPattern("/v1/autopilot/sessions/{local_public_key}")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Autopilot_RevokeAutopilotSession_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Autopilot_RevokeAutopilotSession_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_Autopilot_ListAutopilotFeatures_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "autopilot", "features"}, "")) + + pattern_Autopilot_AddAutopilotSession_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "autopilot", "sessions"}, "")) + + pattern_Autopilot_ListAutopilotSessions_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "autopilot", "sessions"}, "")) + + pattern_Autopilot_RevokeAutopilotSession_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"v1", "autopilot", "sessions", "local_public_key"}, "")) +) + +var ( + forward_Autopilot_ListAutopilotFeatures_0 = runtime.ForwardResponseMessage + + forward_Autopilot_AddAutopilotSession_0 = runtime.ForwardResponseMessage + + forward_Autopilot_ListAutopilotSessions_0 = runtime.ForwardResponseMessage + + forward_Autopilot_RevokeAutopilotSession_0 = runtime.ForwardResponseMessage +) diff --git a/litrpc/lit-autopilot.proto b/litrpc/lit-autopilot.proto index 26c57c3f..ecc0b3a6 100644 --- a/litrpc/lit-autopilot.proto +++ b/litrpc/lit-autopilot.proto @@ -119,6 +119,7 @@ message ListAutopilotFeaturesResponse { message RevokeAutopilotSessionRequest { /* The local static public key of the Autopilot session to be revoked. + When using REST, this field must be encoded as base64. */ bytes local_public_key = 1; } diff --git a/litrpc/lit-autopilot.swagger.json b/litrpc/lit-autopilot.swagger.json new file mode 100644 index 00000000..4b05891d --- /dev/null +++ b/litrpc/lit-autopilot.swagger.json @@ -0,0 +1,637 @@ +{ + "swagger": "2.0", + "info": { + "title": "lit-autopilot.proto", + "version": "version not set" + }, + "tags": [ + { + "name": "Autopilot" + } + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "paths": { + "/v1/autopilot/features": { + "get": { + "summary": "litcli: `autopilot features`\nListAutopilotFeatures fetches all the features supported by the Autopilot\nserver along with the rules that we need to support in order to subscribe\nto those features.", + "operationId": "Autopilot_ListAutopilotFeatures", + "responses": { + "200": { + "description": "A successful response.", + "schema": { + "$ref": "#/definitions/litrpcListAutopilotFeaturesResponse" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "#/definitions/rpcStatus" + } + } + }, + "tags": [ + "Autopilot" + ] + } + }, + "/v1/autopilot/sessions": { + "get": { + "summary": "litcli: `autopilot list`\nListAutopilotSessions lists all the sessions that are of type\nTypeAutopilot.", + "operationId": "Autopilot_ListAutopilotSessions", + "responses": { + "200": { + "description": "A successful response.", + "schema": { + "$ref": "#/definitions/litrpcListAutopilotSessionsResponse" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "#/definitions/rpcStatus" + } + } + }, + "tags": [ + "Autopilot" + ] + }, + "post": { + "summary": "litcli: `autopilot add`\nAddAutopilotSession creates a new LNC session and attempts to register it\nwith the Autopilot server.", + "operationId": "Autopilot_AddAutopilotSession", + "responses": { + "200": { + "description": "A successful response.", + "schema": { + "$ref": "#/definitions/litrpcAddAutopilotSessionResponse" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "#/definitions/rpcStatus" + } + } + }, + "parameters": [ + { + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/litrpcAddAutopilotSessionRequest" + } + } + ], + "tags": [ + "Autopilot" + ] + } + }, + "/v1/autopilot/sessions/{local_public_key}": { + "delete": { + "summary": "litcli: `autopilot revoke`\nRevokeAutopilotSession revokes an Autopilot session.", + "operationId": "Autopilot_RevokeAutopilotSession", + "responses": { + "200": { + "description": "A successful response.", + "schema": { + "$ref": "#/definitions/litrpcRevokeAutopilotSessionResponse" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "#/definitions/rpcStatus" + } + } + }, + "parameters": [ + { + "name": "local_public_key", + "description": "The local static public key of the Autopilot session to be revoked.\nWhen using REST, this field must be encoded as base64.", + "in": "path", + "required": true, + "type": "string", + "format": "byte" + } + ], + "tags": [ + "Autopilot" + ] + } + } + }, + "definitions": { + "litrpcAddAutopilotSessionRequest": { + "type": "object", + "properties": { + "label": { + "type": "string", + "description": "A human readable label to assign to the session." + }, + "expiry_timestamp_seconds": { + "type": "string", + "format": "uint64", + "description": "The unix timestamp at which this session should be revoked." + }, + "mailbox_server_addr": { + "type": "string", + "description": "The address of the mailbox server to connect to for this session." + }, + "dev_server": { + "type": "boolean", + "description": "Set to true if tls should be skipped for when connecting to the mailbox." + }, + "features": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/litrpcFeatureConfig" + }, + "description": "The features that the session should subscribe to. Each feature maps to\na FeatureConfig that should be applied to that feature." + }, + "session_rules": { + "$ref": "#/definitions/litrpcRulesMap", + "description": "Rules that apply to the entire session. By default, no rules will apply\nto the entire session." + }, + "no_privacy_mapper": { + "type": "boolean", + "description": "Set to true of the session should not make use of the privacy mapper." + } + } + }, + "litrpcAddAutopilotSessionResponse": { + "type": "object", + "properties": { + "session": { + "$ref": "#/definitions/litrpcSession", + "description": "Details of the session that was just created." + } + } + }, + "litrpcChannelPolicyBounds": { + "type": "object", + "properties": { + "min_base_msat": { + "type": "string", + "format": "uint64", + "description": "The minimum base fee in msat that the autopilot can set for a channel." + }, + "max_base_msat": { + "type": "string", + "format": "uint64", + "description": "The maximum base fee in msat that the autopilot can set for a channel." + }, + "min_rate_ppm": { + "type": "integer", + "format": "int64", + "description": "The minimum ppm fee in msat that the autopilot can set for a channel." + }, + "max_rate_ppm": { + "type": "integer", + "format": "int64", + "description": "The maximum ppm fee in msat that the autopilot can set for a channel." + }, + "min_cltv_delta": { + "type": "integer", + "format": "int64", + "description": "The minimum cltv delta that the autopilot may set for a channel." + }, + "max_cltv_delta": { + "type": "integer", + "format": "int64", + "description": "The maximum cltv delta that the autopilot may set for a channel." + }, + "min_htlc_msat": { + "type": "string", + "format": "uint64", + "description": "The minimum htlc msat that the autopilot may set for a channel." + }, + "max_htlc_msat": { + "type": "string", + "format": "uint64", + "description": "The maximum htlc msat that the autopilot may set for a channel." + } + } + }, + "litrpcChannelRestrict": { + "type": "object", + "properties": { + "channel_ids": { + "type": "array", + "items": { + "type": "string", + "format": "uint64" + }, + "description": "A list of channel IDs that the Autopilot should _not_ perform any actions\non." + } + } + }, + "litrpcFeature": { + "type": "object", + "properties": { + "name": { + "type": "string", + "description": "Name is the name of the Autopilot feature." + }, + "description": { + "type": "string", + "description": "A human readable description of what the feature offers." + }, + "rules": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/litrpcRuleValues" + }, + "description": "A map of rules that make sense for this feature. Each rule is accompanied\nwith appropriate default values for the feature along with minimum and\nmaximum values for the rules." + }, + "permissions_list": { + "type": "array", + "items": { + "$ref": "#/definitions/litrpcPermissions" + }, + "description": "A list of URI permissions required by the feature." + }, + "requires_upgrade": { + "type": "boolean", + "description": "A boolean indicating if the user would need to upgrade their Litd version in\norder to subscribe to the Autopilot feature. This will be true if the\nfeature rules set contains a rule that Litd is unaware of." + } + } + }, + "litrpcFeatureConfig": { + "type": "object", + "properties": { + "rules": { + "$ref": "#/definitions/litrpcRulesMap", + "description": "The RulesMap acts as an override map. In other words, by default the rules\nvalues recommended by the Auto Pilot server will be used but the RulesMap\ncan be used to override the defaults." + }, + "config": { + "type": "string", + "format": "byte", + "description": "Serialised configuration for the feature." + } + } + }, + "litrpcHistoryLimit": { + "type": "object", + "properties": { + "start_time": { + "type": "string", + "format": "uint64", + "description": "The absolute unix timestamp in seconds before which no information should\nbe shared. This should only be set if duration is not set." + }, + "duration": { + "type": "string", + "format": "uint64", + "description": "The maximum relative duration in seconds that a request is allowed to query\nfor. This should only be set if start_time is not set." + } + } + }, + "litrpcListAutopilotFeaturesResponse": { + "type": "object", + "properties": { + "features": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/litrpcFeature" + }, + "description": "A map of feature names to Feature objects describing the feature." + } + } + }, + "litrpcListAutopilotSessionsResponse": { + "type": "object", + "properties": { + "sessions": { + "type": "array", + "items": { + "$ref": "#/definitions/litrpcSession" + }, + "description": "A list of the Autopilot sessions." + } + } + }, + "litrpcMacaroonPermission": { + "type": "object", + "properties": { + "entity": { + "type": "string", + "description": "The entity a permission grants access to. If a entity is set to the\n\"uri\" keyword then the action entry should be one of the special cases\ndescribed in the comment for action." + }, + "action": { + "type": "string", + "description": "The action that is granted. If entity is set to \"uri\", then action must\nbe set to either:\n- a particular URI to which access should be granted.\n- a URI regex, in which case access will be granted to each URI that\nmatches the regex.\n- the \"***readonly***\" keyword. This will result in the access being\ngranted to all read-only endpoints." + } + } + }, + "litrpcMacaroonRecipe": { + "type": "object", + "properties": { + "permissions": { + "type": "array", + "items": { + "$ref": "#/definitions/litrpcMacaroonPermission" + }, + "description": "A list of permissions that should be included in the macaroon." + }, + "caveats": { + "type": "array", + "items": { + "type": "string" + }, + "description": "A list of caveats to add to the macaroon." + } + } + }, + "litrpcOffChainBudget": { + "type": "object", + "properties": { + "max_amt_msat": { + "type": "string", + "format": "uint64", + "description": "The maximum amount that can be spent off-chain excluding fees." + }, + "max_fees_msat": { + "type": "string", + "format": "uint64", + "description": "The maximum amount that can be spent off-chain on fees." + } + } + }, + "litrpcOnChainBudget": { + "type": "object", + "properties": { + "absolute_amt_sats": { + "type": "string", + "format": "uint64", + "description": "The maximum amount that can be spent on-chain including fees." + }, + "max_sat_per_v_byte": { + "type": "string", + "format": "uint64", + "description": "The maximum amount that can be spent on-chain in fees." + } + } + }, + "litrpcPeerRestrict": { + "type": "object", + "properties": { + "peer_ids": { + "type": "array", + "items": { + "type": "string" + }, + "description": "A list of peer IDs that the Autopilot should _not_ perform any actions on." + } + } + }, + "litrpcPermissions": { + "type": "object", + "properties": { + "method": { + "type": "string", + "description": "The URI in question." + }, + "operations": { + "type": "array", + "items": { + "$ref": "#/definitions/litrpcMacaroonPermission" + }, + "description": "A list of the permissions required for this method." + } + } + }, + "litrpcRate": { + "type": "object", + "properties": { + "iterations": { + "type": "integer", + "format": "int64", + "description": "The number of times a call is allowed in num_hours number of hours." + }, + "num_hours": { + "type": "integer", + "format": "int64", + "description": "The number of hours in which the iterations count takes place over." + } + } + }, + "litrpcRateLimit": { + "type": "object", + "properties": { + "read_limit": { + "$ref": "#/definitions/litrpcRate", + "description": "The rate limit for read-only calls." + }, + "write_limit": { + "$ref": "#/definitions/litrpcRate", + "description": "The rate limit for write/execution calls." + } + } + }, + "litrpcRevokeAutopilotSessionResponse": { + "type": "object" + }, + "litrpcRuleValue": { + "type": "object", + "properties": { + "rate_limit": { + "$ref": "#/definitions/litrpcRateLimit" + }, + "chan_policy_bounds": { + "$ref": "#/definitions/litrpcChannelPolicyBounds" + }, + "history_limit": { + "$ref": "#/definitions/litrpcHistoryLimit" + }, + "off_chain_budget": { + "$ref": "#/definitions/litrpcOffChainBudget" + }, + "on_chain_budget": { + "$ref": "#/definitions/litrpcOnChainBudget" + }, + "send_to_self": { + "$ref": "#/definitions/litrpcSendToSelf" + }, + "channel_restrict": { + "$ref": "#/definitions/litrpcChannelRestrict" + }, + "peer_restrict": { + "$ref": "#/definitions/litrpcPeerRestrict" + } + } + }, + "litrpcRuleValues": { + "type": "object", + "properties": { + "known": { + "type": "boolean", + "description": "Whether or not the users version of Litd is aware of this rule." + }, + "defaults": { + "$ref": "#/definitions/litrpcRuleValue", + "description": "The default values for the rule that the Autopilot server recommends for\nthe associated feature." + }, + "min_value": { + "$ref": "#/definitions/litrpcRuleValue", + "description": "The minimum sane value for this rule for the associated feature." + }, + "max_value": { + "$ref": "#/definitions/litrpcRuleValue", + "description": "The maximum sane value for this rule for the associated feature." + } + } + }, + "litrpcRulesMap": { + "type": "object", + "properties": { + "rules": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/litrpcRuleValue" + }, + "description": "A map of rule name to RuleValue. The RuleValue should be parsed based on\nthe name of the rule." + } + } + }, + "litrpcSendToSelf": { + "type": "object" + }, + "litrpcSession": { + "type": "object", + "properties": { + "id": { + "type": "string", + "format": "byte", + "description": "A unique ID assigned to the session. It is derived from the session\nmacaroon." + }, + "label": { + "type": "string", + "description": "A user assigned label for the session." + }, + "session_state": { + "$ref": "#/definitions/litrpcSessionState", + "description": "The current state that the session is in. This will give an indication of\nif the session is currently usable or not." + }, + "session_type": { + "$ref": "#/definitions/litrpcSessionType", + "description": "The session type. The will given an indication of the restrictions applied\nto the macaroon assigned to the session." + }, + "expiry_timestamp_seconds": { + "type": "string", + "format": "uint64", + "description": "The time at which the session will automatically be revoked." + }, + "mailbox_server_addr": { + "type": "string", + "description": "The address of the mailbox server that the LNC connection should use." + }, + "dev_server": { + "type": "boolean", + "description": "If set to true, tls will be skipped when connecting to the mailbox." + }, + "pairing_secret": { + "type": "string", + "format": "byte", + "description": "The LNC pairing phrase in byte form." + }, + "pairing_secret_mnemonic": { + "type": "string", + "description": "The LNC pairing phrase in mnemonic form." + }, + "local_public_key": { + "type": "string", + "format": "byte", + "description": "The long term, local static public key used by this node for the LNC\nconnection." + }, + "remote_public_key": { + "type": "string", + "format": "byte", + "description": "The long term, remote static public key used by the remote party for the\nLNC connection." + }, + "created_at": { + "type": "string", + "format": "uint64", + "description": "The time at which the session was created." + }, + "macaroon_recipe": { + "$ref": "#/definitions/litrpcMacaroonRecipe", + "description": "The recipe used for creating a macaroon to use with this session. This will\nbe closely linked to the session type." + }, + "account_id": { + "type": "string", + "description": "If the session is for a specific account, then this will be the account ID\nit is associated with." + }, + "autopilot_feature_info": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/litrpcRulesMap" + }, + "description": "If this session is for Autopilot use, then this will be the set of features\nthat the session can be used for along with the rules for each feature." + }, + "revoked_at": { + "type": "string", + "format": "uint64", + "description": "The unix timestamp indicating the time at which the session was revoked.\nNote that this field has not been around since the beginning and so it\ncould be the case that a session has been revoked but that this field\nwill not have been set for that session. Therefore, it is suggested that\nreaders should not assume that if this field is zero that the session is\nnot revoked. Readers should instead first check the session_state field." + } + } + }, + "litrpcSessionState": { + "type": "string", + "enum": [ + "STATE_CREATED", + "STATE_IN_USE", + "STATE_REVOKED", + "STATE_EXPIRED" + ], + "default": "STATE_CREATED" + }, + "litrpcSessionType": { + "type": "string", + "enum": [ + "TYPE_MACAROON_READONLY", + "TYPE_MACAROON_ADMIN", + "TYPE_MACAROON_CUSTOM", + "TYPE_UI_PASSWORD", + "TYPE_AUTOPILOT", + "TYPE_MACAROON_ACCOUNT" + ], + "default": "TYPE_MACAROON_READONLY" + }, + "protobufAny": { + "type": "object", + "properties": { + "type_url": { + "type": "string" + }, + "value": { + "type": "string", + "format": "byte" + } + } + }, + "rpcStatus": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "format": "int32" + }, + "message": { + "type": "string" + }, + "details": { + "type": "array", + "items": { + "$ref": "#/definitions/protobufAny" + } + } + } + } + } +} diff --git a/litrpc/lit-autopilot.yaml b/litrpc/lit-autopilot.yaml new file mode 100644 index 00000000..1051b0cc --- /dev/null +++ b/litrpc/lit-autopilot.yaml @@ -0,0 +1,16 @@ +type: google.api.Service +config_version: 3 + +http: + rules: + + # lit-autopilot.proto + - selector: litrpc.Autopilot.AddAutopilotSession + post: "/v1/autopilot/sessions" + body: "*" + - selector: litrpc.Autopilot.ListAutopilotFeatures + get: "/v1/autopilot/features" + - selector: litrpc.Autopilot.ListAutopilotSessions + get: "/v1/autopilot/sessions" + - selector: litrpc.Autopilot.RevokeAutopilotSession + delete: "/v1/autopilot/sessions/{local_public_key}" diff --git a/litrpc/lit-sessions.pb.go b/litrpc/lit-sessions.pb.go index b21ab02f..0070b9a3 100644 --- a/litrpc/lit-sessions.pb.go +++ b/litrpc/lit-sessions.pb.go @@ -692,6 +692,7 @@ type RevokeSessionRequest struct { unknownFields protoimpl.UnknownFields // The local static key of the session to be revoked. + // When using REST, this field must be encoded as base64. LocalPublicKey []byte `protobuf:"bytes,8,opt,name=local_public_key,json=localPublicKey,proto3" json:"local_public_key,omitempty"` } diff --git a/litrpc/lit-sessions.pb.gw.go b/litrpc/lit-sessions.pb.gw.go new file mode 100644 index 00000000..87a550fe --- /dev/null +++ b/litrpc/lit-sessions.pb.gw.go @@ -0,0 +1,331 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: lit-sessions.proto + +/* +Package litrpc is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package litrpc + +import ( + "context" + "io" + "net/http" + + "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" + "github.com/grpc-ecosystem/grpc-gateway/v2/utilities" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" + "google.golang.org/protobuf/proto" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = metadata.Join + +func request_Sessions_AddSession_0(ctx context.Context, marshaler runtime.Marshaler, client SessionsClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq AddSessionRequest + var metadata runtime.ServerMetadata + + newReader, berr := utilities.IOReaderFactory(req.Body) + if berr != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) + } + if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.AddSession(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Sessions_AddSession_0(ctx context.Context, marshaler runtime.Marshaler, server SessionsServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq AddSessionRequest + var metadata runtime.ServerMetadata + + newReader, berr := utilities.IOReaderFactory(req.Body) + if berr != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) + } + if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.AddSession(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Sessions_ListSessions_0(ctx context.Context, marshaler runtime.Marshaler, client SessionsClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq ListSessionsRequest + var metadata runtime.ServerMetadata + + msg, err := client.ListSessions(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Sessions_ListSessions_0(ctx context.Context, marshaler runtime.Marshaler, server SessionsServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq ListSessionsRequest + var metadata runtime.ServerMetadata + + msg, err := server.ListSessions(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Sessions_RevokeSession_0(ctx context.Context, marshaler runtime.Marshaler, client SessionsClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq RevokeSessionRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["local_public_key"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "local_public_key") + } + + protoReq.LocalPublicKey, err = runtime.Bytes(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "local_public_key", err) + } + + msg, err := client.RevokeSession(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Sessions_RevokeSession_0(ctx context.Context, marshaler runtime.Marshaler, server SessionsServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq RevokeSessionRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["local_public_key"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "local_public_key") + } + + protoReq.LocalPublicKey, err = runtime.Bytes(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "local_public_key", err) + } + + msg, err := server.RevokeSession(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterSessionsHandlerServer registers the http handlers for service Sessions to "mux". +// UnaryRPC :call SessionsServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterSessionsHandlerFromEndpoint instead. +func RegisterSessionsHandlerServer(ctx context.Context, mux *runtime.ServeMux, server SessionsServer) error { + + mux.Handle("POST", pattern_Sessions_AddSession_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/litrpc.Sessions/AddSession", runtime.WithHTTPPathPattern("/v1/sessions")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Sessions_AddSession_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Sessions_AddSession_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Sessions_ListSessions_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/litrpc.Sessions/ListSessions", runtime.WithHTTPPathPattern("/v1/sessions")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Sessions_ListSessions_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Sessions_ListSessions_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("DELETE", pattern_Sessions_RevokeSession_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/litrpc.Sessions/RevokeSession", runtime.WithHTTPPathPattern("/v1/sessions/{local_public_key}")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Sessions_RevokeSession_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Sessions_RevokeSession_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterSessionsHandlerFromEndpoint is same as RegisterSessionsHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterSessionsHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.Dial(endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterSessionsHandler(ctx, mux, conn) +} + +// RegisterSessionsHandler registers the http handlers for service Sessions to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterSessionsHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterSessionsHandlerClient(ctx, mux, NewSessionsClient(conn)) +} + +// RegisterSessionsHandlerClient registers the http handlers for service Sessions +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "SessionsClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "SessionsClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "SessionsClient" to call the correct interceptors. +func RegisterSessionsHandlerClient(ctx context.Context, mux *runtime.ServeMux, client SessionsClient) error { + + mux.Handle("POST", pattern_Sessions_AddSession_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, "/litrpc.Sessions/AddSession", runtime.WithHTTPPathPattern("/v1/sessions")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Sessions_AddSession_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Sessions_AddSession_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Sessions_ListSessions_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, "/litrpc.Sessions/ListSessions", runtime.WithHTTPPathPattern("/v1/sessions")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Sessions_ListSessions_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Sessions_ListSessions_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("DELETE", pattern_Sessions_RevokeSession_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, "/litrpc.Sessions/RevokeSession", runtime.WithHTTPPathPattern("/v1/sessions/{local_public_key}")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Sessions_RevokeSession_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Sessions_RevokeSession_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_Sessions_AddSession_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "sessions"}, "")) + + pattern_Sessions_ListSessions_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "sessions"}, "")) + + pattern_Sessions_RevokeSession_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2}, []string{"v1", "sessions", "local_public_key"}, "")) +) + +var ( + forward_Sessions_AddSession_0 = runtime.ForwardResponseMessage + + forward_Sessions_ListSessions_0 = runtime.ForwardResponseMessage + + forward_Sessions_RevokeSession_0 = runtime.ForwardResponseMessage +) diff --git a/litrpc/lit-sessions.proto b/litrpc/lit-sessions.proto index ee6289e0..b9ff9df8 100644 --- a/litrpc/lit-sessions.proto +++ b/litrpc/lit-sessions.proto @@ -226,6 +226,7 @@ message ListSessionsResponse { message RevokeSessionRequest { /* The local static key of the session to be revoked. + When using REST, this field must be encoded as base64. */ bytes local_public_key = 8; } diff --git a/litrpc/lit-sessions.swagger.json b/litrpc/lit-sessions.swagger.json new file mode 100644 index 00000000..c4e8b118 --- /dev/null +++ b/litrpc/lit-sessions.swagger.json @@ -0,0 +1,520 @@ +{ + "swagger": "2.0", + "info": { + "title": "lit-sessions.proto", + "version": "version not set" + }, + "tags": [ + { + "name": "Sessions" + } + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "paths": { + "/v1/sessions": { + "get": { + "summary": "litcli: `sessions list`\nListSessions returns all sessions known to the session store.", + "operationId": "Sessions_ListSessions", + "responses": { + "200": { + "description": "A successful response.", + "schema": { + "$ref": "#/definitions/litrpcListSessionsResponse" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "#/definitions/rpcStatus" + } + } + }, + "tags": [ + "Sessions" + ] + }, + "post": { + "summary": "litcli: `sessions add`\nAddSession adds and starts a new LNC session.", + "operationId": "Sessions_AddSession", + "responses": { + "200": { + "description": "A successful response.", + "schema": { + "$ref": "#/definitions/litrpcAddSessionResponse" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "#/definitions/rpcStatus" + } + } + }, + "parameters": [ + { + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/litrpcAddSessionRequest" + } + } + ], + "tags": [ + "Sessions" + ] + } + }, + "/v1/sessions/{local_public_key}": { + "delete": { + "summary": "litcli: `sessions revoke`\nRevokeSession revokes a single session and also stops it if it is currently\nactive.", + "operationId": "Sessions_RevokeSession", + "responses": { + "200": { + "description": "A successful response.", + "schema": { + "$ref": "#/definitions/litrpcRevokeSessionResponse" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "#/definitions/rpcStatus" + } + } + }, + "parameters": [ + { + "name": "local_public_key", + "description": "The local static key of the session to be revoked.\nWhen using REST, this field must be encoded as base64.", + "in": "path", + "required": true, + "type": "string", + "format": "byte" + } + ], + "tags": [ + "Sessions" + ] + } + } + }, + "definitions": { + "litrpcAddSessionRequest": { + "type": "object", + "properties": { + "label": { + "type": "string", + "description": "A user assigned label for the session." + }, + "session_type": { + "$ref": "#/definitions/litrpcSessionType", + "description": "The session type. This will be used during macaroon construction to\ndetermine how restrictive to make the macaroon and thus the session access." + }, + "expiry_timestamp_seconds": { + "type": "string", + "format": "uint64", + "description": "The time at which the session should automatically be revoked." + }, + "mailbox_server_addr": { + "type": "string", + "description": "The address of the mailbox server that the LNC connection should use." + }, + "dev_server": { + "type": "boolean", + "description": "If set to true, tls will be skipped when connecting to the mailbox." + }, + "macaroon_custom_permissions": { + "type": "array", + "items": { + "$ref": "#/definitions/litrpcMacaroonPermission" + }, + "description": "Any custom permissions to add the session's macaroon." + }, + "account_id": { + "type": "string", + "description": "The ID of the account to associate this session with. This should only be\nset if the session_type is TYPE_MACAROON_ACCOUNT." + } + } + }, + "litrpcAddSessionResponse": { + "type": "object", + "properties": { + "session": { + "$ref": "#/definitions/litrpcSession", + "description": "The session of the newly created session." + } + } + }, + "litrpcChannelPolicyBounds": { + "type": "object", + "properties": { + "min_base_msat": { + "type": "string", + "format": "uint64", + "description": "The minimum base fee in msat that the autopilot can set for a channel." + }, + "max_base_msat": { + "type": "string", + "format": "uint64", + "description": "The maximum base fee in msat that the autopilot can set for a channel." + }, + "min_rate_ppm": { + "type": "integer", + "format": "int64", + "description": "The minimum ppm fee in msat that the autopilot can set for a channel." + }, + "max_rate_ppm": { + "type": "integer", + "format": "int64", + "description": "The maximum ppm fee in msat that the autopilot can set for a channel." + }, + "min_cltv_delta": { + "type": "integer", + "format": "int64", + "description": "The minimum cltv delta that the autopilot may set for a channel." + }, + "max_cltv_delta": { + "type": "integer", + "format": "int64", + "description": "The maximum cltv delta that the autopilot may set for a channel." + }, + "min_htlc_msat": { + "type": "string", + "format": "uint64", + "description": "The minimum htlc msat that the autopilot may set for a channel." + }, + "max_htlc_msat": { + "type": "string", + "format": "uint64", + "description": "The maximum htlc msat that the autopilot may set for a channel." + } + } + }, + "litrpcChannelRestrict": { + "type": "object", + "properties": { + "channel_ids": { + "type": "array", + "items": { + "type": "string", + "format": "uint64" + }, + "description": "A list of channel IDs that the Autopilot should _not_ perform any actions\non." + } + } + }, + "litrpcHistoryLimit": { + "type": "object", + "properties": { + "start_time": { + "type": "string", + "format": "uint64", + "description": "The absolute unix timestamp in seconds before which no information should\nbe shared. This should only be set if duration is not set." + }, + "duration": { + "type": "string", + "format": "uint64", + "description": "The maximum relative duration in seconds that a request is allowed to query\nfor. This should only be set if start_time is not set." + } + } + }, + "litrpcListSessionsResponse": { + "type": "object", + "properties": { + "sessions": { + "type": "array", + "items": { + "$ref": "#/definitions/litrpcSession" + }, + "description": "A list of sessions." + } + } + }, + "litrpcMacaroonPermission": { + "type": "object", + "properties": { + "entity": { + "type": "string", + "description": "The entity a permission grants access to. If a entity is set to the\n\"uri\" keyword then the action entry should be one of the special cases\ndescribed in the comment for action." + }, + "action": { + "type": "string", + "description": "The action that is granted. If entity is set to \"uri\", then action must\nbe set to either:\n- a particular URI to which access should be granted.\n- a URI regex, in which case access will be granted to each URI that\nmatches the regex.\n- the \"***readonly***\" keyword. This will result in the access being\ngranted to all read-only endpoints." + } + } + }, + "litrpcMacaroonRecipe": { + "type": "object", + "properties": { + "permissions": { + "type": "array", + "items": { + "$ref": "#/definitions/litrpcMacaroonPermission" + }, + "description": "A list of permissions that should be included in the macaroon." + }, + "caveats": { + "type": "array", + "items": { + "type": "string" + }, + "description": "A list of caveats to add to the macaroon." + } + } + }, + "litrpcOffChainBudget": { + "type": "object", + "properties": { + "max_amt_msat": { + "type": "string", + "format": "uint64", + "description": "The maximum amount that can be spent off-chain excluding fees." + }, + "max_fees_msat": { + "type": "string", + "format": "uint64", + "description": "The maximum amount that can be spent off-chain on fees." + } + } + }, + "litrpcOnChainBudget": { + "type": "object", + "properties": { + "absolute_amt_sats": { + "type": "string", + "format": "uint64", + "description": "The maximum amount that can be spent on-chain including fees." + }, + "max_sat_per_v_byte": { + "type": "string", + "format": "uint64", + "description": "The maximum amount that can be spent on-chain in fees." + } + } + }, + "litrpcPeerRestrict": { + "type": "object", + "properties": { + "peer_ids": { + "type": "array", + "items": { + "type": "string" + }, + "description": "A list of peer IDs that the Autopilot should _not_ perform any actions on." + } + } + }, + "litrpcRate": { + "type": "object", + "properties": { + "iterations": { + "type": "integer", + "format": "int64", + "description": "The number of times a call is allowed in num_hours number of hours." + }, + "num_hours": { + "type": "integer", + "format": "int64", + "description": "The number of hours in which the iterations count takes place over." + } + } + }, + "litrpcRateLimit": { + "type": "object", + "properties": { + "read_limit": { + "$ref": "#/definitions/litrpcRate", + "description": "The rate limit for read-only calls." + }, + "write_limit": { + "$ref": "#/definitions/litrpcRate", + "description": "The rate limit for write/execution calls." + } + } + }, + "litrpcRevokeSessionResponse": { + "type": "object" + }, + "litrpcRuleValue": { + "type": "object", + "properties": { + "rate_limit": { + "$ref": "#/definitions/litrpcRateLimit" + }, + "chan_policy_bounds": { + "$ref": "#/definitions/litrpcChannelPolicyBounds" + }, + "history_limit": { + "$ref": "#/definitions/litrpcHistoryLimit" + }, + "off_chain_budget": { + "$ref": "#/definitions/litrpcOffChainBudget" + }, + "on_chain_budget": { + "$ref": "#/definitions/litrpcOnChainBudget" + }, + "send_to_self": { + "$ref": "#/definitions/litrpcSendToSelf" + }, + "channel_restrict": { + "$ref": "#/definitions/litrpcChannelRestrict" + }, + "peer_restrict": { + "$ref": "#/definitions/litrpcPeerRestrict" + } + } + }, + "litrpcRulesMap": { + "type": "object", + "properties": { + "rules": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/litrpcRuleValue" + }, + "description": "A map of rule name to RuleValue. The RuleValue should be parsed based on\nthe name of the rule." + } + } + }, + "litrpcSendToSelf": { + "type": "object" + }, + "litrpcSession": { + "type": "object", + "properties": { + "id": { + "type": "string", + "format": "byte", + "description": "A unique ID assigned to the session. It is derived from the session\nmacaroon." + }, + "label": { + "type": "string", + "description": "A user assigned label for the session." + }, + "session_state": { + "$ref": "#/definitions/litrpcSessionState", + "description": "The current state that the session is in. This will give an indication of\nif the session is currently usable or not." + }, + "session_type": { + "$ref": "#/definitions/litrpcSessionType", + "description": "The session type. The will given an indication of the restrictions applied\nto the macaroon assigned to the session." + }, + "expiry_timestamp_seconds": { + "type": "string", + "format": "uint64", + "description": "The time at which the session will automatically be revoked." + }, + "mailbox_server_addr": { + "type": "string", + "description": "The address of the mailbox server that the LNC connection should use." + }, + "dev_server": { + "type": "boolean", + "description": "If set to true, tls will be skipped when connecting to the mailbox." + }, + "pairing_secret": { + "type": "string", + "format": "byte", + "description": "The LNC pairing phrase in byte form." + }, + "pairing_secret_mnemonic": { + "type": "string", + "description": "The LNC pairing phrase in mnemonic form." + }, + "local_public_key": { + "type": "string", + "format": "byte", + "description": "The long term, local static public key used by this node for the LNC\nconnection." + }, + "remote_public_key": { + "type": "string", + "format": "byte", + "description": "The long term, remote static public key used by the remote party for the\nLNC connection." + }, + "created_at": { + "type": "string", + "format": "uint64", + "description": "The time at which the session was created." + }, + "macaroon_recipe": { + "$ref": "#/definitions/litrpcMacaroonRecipe", + "description": "The recipe used for creating a macaroon to use with this session. This will\nbe closely linked to the session type." + }, + "account_id": { + "type": "string", + "description": "If the session is for a specific account, then this will be the account ID\nit is associated with." + }, + "autopilot_feature_info": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/litrpcRulesMap" + }, + "description": "If this session is for Autopilot use, then this will be the set of features\nthat the session can be used for along with the rules for each feature." + }, + "revoked_at": { + "type": "string", + "format": "uint64", + "description": "The unix timestamp indicating the time at which the session was revoked.\nNote that this field has not been around since the beginning and so it\ncould be the case that a session has been revoked but that this field\nwill not have been set for that session. Therefore, it is suggested that\nreaders should not assume that if this field is zero that the session is\nnot revoked. Readers should instead first check the session_state field." + } + } + }, + "litrpcSessionState": { + "type": "string", + "enum": [ + "STATE_CREATED", + "STATE_IN_USE", + "STATE_REVOKED", + "STATE_EXPIRED" + ], + "default": "STATE_CREATED" + }, + "litrpcSessionType": { + "type": "string", + "enum": [ + "TYPE_MACAROON_READONLY", + "TYPE_MACAROON_ADMIN", + "TYPE_MACAROON_CUSTOM", + "TYPE_UI_PASSWORD", + "TYPE_AUTOPILOT", + "TYPE_MACAROON_ACCOUNT" + ], + "default": "TYPE_MACAROON_READONLY" + }, + "protobufAny": { + "type": "object", + "properties": { + "type_url": { + "type": "string" + }, + "value": { + "type": "string", + "format": "byte" + } + } + }, + "rpcStatus": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "format": "int32" + }, + "message": { + "type": "string" + }, + "details": { + "type": "array", + "items": { + "$ref": "#/definitions/protobufAny" + } + } + } + } + } +} diff --git a/litrpc/lit-sessions.yaml b/litrpc/lit-sessions.yaml new file mode 100644 index 00000000..39b790b5 --- /dev/null +++ b/litrpc/lit-sessions.yaml @@ -0,0 +1,14 @@ +type: google.api.Service +config_version: 3 + +http: + rules: + + # lit-sessions.proto + - selector: litrpc.Sessions.AddSession + post: "/v1/sessions" + body: "*" + - selector: litrpc.Sessions.ListSessions + get: "/v1/sessions" + - selector: litrpc.Sessions.RevokeSession + delete: "/v1/sessions/{local_public_key}" diff --git a/litrpc/proxy.pb.gw.go b/litrpc/proxy.pb.gw.go new file mode 100644 index 00000000..881e8d8d --- /dev/null +++ b/litrpc/proxy.pb.gw.go @@ -0,0 +1,232 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: proxy.proto + +/* +Package litrpc is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package litrpc + +import ( + "context" + "io" + "net/http" + + "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" + "github.com/grpc-ecosystem/grpc-gateway/v2/utilities" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" + "google.golang.org/protobuf/proto" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = metadata.Join + +func request_Proxy_GetInfo_0(ctx context.Context, marshaler runtime.Marshaler, client ProxyClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq GetInfoRequest + var metadata runtime.ServerMetadata + + msg, err := client.GetInfo(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Proxy_GetInfo_0(ctx context.Context, marshaler runtime.Marshaler, server ProxyServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq GetInfoRequest + var metadata runtime.ServerMetadata + + msg, err := server.GetInfo(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Proxy_StopDaemon_0(ctx context.Context, marshaler runtime.Marshaler, client ProxyClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq StopDaemonRequest + var metadata runtime.ServerMetadata + + newReader, berr := utilities.IOReaderFactory(req.Body) + if berr != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) + } + if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.StopDaemon(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Proxy_StopDaemon_0(ctx context.Context, marshaler runtime.Marshaler, server ProxyServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq StopDaemonRequest + var metadata runtime.ServerMetadata + + newReader, berr := utilities.IOReaderFactory(req.Body) + if berr != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) + } + if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.StopDaemon(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterProxyHandlerServer registers the http handlers for service Proxy to "mux". +// UnaryRPC :call ProxyServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterProxyHandlerFromEndpoint instead. +func RegisterProxyHandlerServer(ctx context.Context, mux *runtime.ServeMux, server ProxyServer) error { + + mux.Handle("GET", pattern_Proxy_GetInfo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/litrpc.Proxy/GetInfo", runtime.WithHTTPPathPattern("/v1/proxy/info")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Proxy_GetInfo_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Proxy_GetInfo_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("POST", pattern_Proxy_StopDaemon_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/litrpc.Proxy/StopDaemon", runtime.WithHTTPPathPattern("/v1/proxy/stop")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Proxy_StopDaemon_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Proxy_StopDaemon_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterProxyHandlerFromEndpoint is same as RegisterProxyHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterProxyHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.Dial(endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterProxyHandler(ctx, mux, conn) +} + +// RegisterProxyHandler registers the http handlers for service Proxy to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterProxyHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterProxyHandlerClient(ctx, mux, NewProxyClient(conn)) +} + +// RegisterProxyHandlerClient registers the http handlers for service Proxy +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "ProxyClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "ProxyClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "ProxyClient" to call the correct interceptors. +func RegisterProxyHandlerClient(ctx context.Context, mux *runtime.ServeMux, client ProxyClient) error { + + mux.Handle("GET", pattern_Proxy_GetInfo_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, "/litrpc.Proxy/GetInfo", runtime.WithHTTPPathPattern("/v1/proxy/info")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Proxy_GetInfo_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Proxy_GetInfo_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("POST", pattern_Proxy_StopDaemon_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, "/litrpc.Proxy/StopDaemon", runtime.WithHTTPPathPattern("/v1/proxy/stop")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Proxy_StopDaemon_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Proxy_StopDaemon_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_Proxy_GetInfo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "proxy", "info"}, "")) + + pattern_Proxy_StopDaemon_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "proxy", "stop"}, "")) +) + +var ( + forward_Proxy_GetInfo_0 = runtime.ForwardResponseMessage + + forward_Proxy_StopDaemon_0 = runtime.ForwardResponseMessage +) diff --git a/litrpc/proxy.swagger.json b/litrpc/proxy.swagger.json new file mode 100644 index 00000000..e4c9f7a3 --- /dev/null +++ b/litrpc/proxy.swagger.json @@ -0,0 +1,123 @@ +{ + "swagger": "2.0", + "info": { + "title": "proxy.proto", + "version": "version not set" + }, + "tags": [ + { + "name": "Proxy" + } + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "paths": { + "/v1/proxy/info": { + "get": { + "summary": "litcli: `proxy getinfo`\nGetInfo returns general information concerning the LiTd node.", + "operationId": "Proxy_GetInfo", + "responses": { + "200": { + "description": "A successful response.", + "schema": { + "$ref": "#/definitions/litrpcGetInfoResponse" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "#/definitions/rpcStatus" + } + } + }, + "tags": [ + "Proxy" + ] + } + }, + "/v1/proxy/stop": { + "post": { + "summary": "litcli: `proxy stop`\nStopDaemon will send a shutdown request to the interrupt handler,\ntriggering a graceful shutdown of the daemon.", + "operationId": "Proxy_StopDaemon", + "responses": { + "200": { + "description": "A successful response.", + "schema": { + "$ref": "#/definitions/litrpcStopDaemonResponse" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "#/definitions/rpcStatus" + } + } + }, + "parameters": [ + { + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/litrpcStopDaemonRequest" + } + } + ], + "tags": [ + "Proxy" + ] + } + } + }, + "definitions": { + "litrpcGetInfoResponse": { + "type": "object", + "properties": { + "version": { + "type": "string", + "description": "The version of the LiTd software that the node is running." + } + } + }, + "litrpcStopDaemonRequest": { + "type": "object" + }, + "litrpcStopDaemonResponse": { + "type": "object" + }, + "protobufAny": { + "type": "object", + "properties": { + "type_url": { + "type": "string" + }, + "value": { + "type": "string", + "format": "byte" + } + } + }, + "rpcStatus": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "format": "int32" + }, + "message": { + "type": "string" + }, + "details": { + "type": "array", + "items": { + "$ref": "#/definitions/protobufAny" + } + } + } + } + } +} diff --git a/litrpc/proxy.yaml b/litrpc/proxy.yaml new file mode 100644 index 00000000..7df90370 --- /dev/null +++ b/litrpc/proxy.yaml @@ -0,0 +1,12 @@ +type: google.api.Service +config_version: 3 + +http: + rules: + + # proxy.proto + - selector: litrpc.Proxy.StopDaemon + post: "/v1/proxy/stop" + body: "*" + - selector: litrpc.Proxy.GetInfo + get: "/v1/proxy/info"