From f873e5299342137cbb6be21b28b7caa29654bac2 Mon Sep 17 00:00:00 2001 From: BigBoss Date: Mon, 1 May 2023 22:15:30 -0400 Subject: [PATCH] add mock servicer relay rpc --- Makefile | 4 ++-- app/client/cli/query.go | 27 +++++++++++++++++++++++++++ build/localnet/Tiltfile | 4 ++-- rpc/handlers_servicer.go | 26 ++++++++++++++++++++++++++ 4 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 rpc/handlers_servicer.go diff --git a/Makefile b/Makefile index bea5add4d..8352b0a0d 100644 --- a/Makefile +++ b/Makefile @@ -319,11 +319,11 @@ generate_rpc_openapi: go_oapi-codegen ## (Re)generates the RPC server and client oapi-codegen --config ./rpc/client.gen.config.yml ./rpc/v1/openapi.yaml > ./rpc/client.gen.go echo "OpenAPI client and server generated" -SWAGGER_PORT=8080 +SWAGGER_PORT=127.0.0.1:8080 .PHONY: swagger-ui swagger-ui: ## Starts a local Swagger UI instance for the RPC API echo "Attempting to start Swagger UI at http://localhost:8080" - docker run --rm -p $(SWAGGER_PORT):8080 -e SWAGGER_JSON=/v1/openapi.yaml -v $(shell pwd)/rpc/v1:/v1 swaggerapi/swagger-ui + docker run --name pocket-swagger-ui --rm -p $(SWAGGER_PORT):8080 -e SWAGGER_JSON=/v1/openapi.yaml -v $(shell pwd)/rpc/v1:/v1 swaggerapi/swagger-ui .PHONY: generate_cli_commands_docs generate_cli_commands_docs: ## (Re)generates the CLI commands docs (this is meant to be called by CI) diff --git a/app/client/cli/query.go b/app/client/cli/query.go index fd2cf32d0..770959ec0 100644 --- a/app/client/cli/query.go +++ b/app/client/cli/query.go @@ -884,6 +884,33 @@ func queryCommands() []*cobra.Command { return rpcResponseCodeUnhealthy(statusCode, resp) }, }, + { + Use: "NodeRoles", + Short: "Get current the node roles", + Long: "Queries the node RPC to returns the type of utility actor(s) running on the node", + Aliases: []string{"noderoles"}, + RunE: func(cmd *cobra.Command, args []string) error { + client, err := rpc.NewClientWithResponses(remoteCLIURL) + if err != nil { + return err + } + response, err := client.GetV1QueryNodeRoles(cmd.Context()) + if err != nil { + return unableToConnectToRpc(err) + } + statusCode := response.StatusCode + body, err := io.ReadAll(response.Body) + if err != nil { + fmt.Fprintf(os.Stderr, "❌ Error reading response body: %s\n", err.Error()) + return err + } + if statusCode == http.StatusOK { + fmt.Println(string(body)) + return nil + } + return rpcResponseCodeUnhealthy(statusCode, body) + }, + }, } return cmds } diff --git a/build/localnet/Tiltfile b/build/localnet/Tiltfile index fc55d8c48..c0276e6e0 100644 --- a/build/localnet/Tiltfile +++ b/build/localnet/Tiltfile @@ -186,7 +186,7 @@ for x in range(localnet_config["validators"]["count"]): set=[ "global.postgresql.auth.postgresPassword=LocalNetPassword", "image.repository=validator-image", - "privateKeySecretKeyRef.name=v1-localnet-validators-private-keys", + "privateKeySecretKeyRef.name=validators-private-keys", "privateKeySecretKeyRef.key=%s" % formatted_number, "genesis.preProvisionedGenesis.enabled=false", "genesis.externalConfigMap.name=v1-localnet-genesis", @@ -206,7 +206,7 @@ for x in range(localnet_config["servicers"]["count"]): set=[ "global.postgresql.auth.postgresPassword=LocalNetPassword", "image.repository=validator-image", - "privateKeySecretKeyRef.name=v1-localnet-validators-private-keys", + "privateKeySecretKeyRef.name=validators-private-keys", "privateKeySecretKeyRef.key=%s" % formatted_number, "genesis.preProvisionedGenesis.enabled=false", "genesis.externalConfigMap.name=v1-localnet-genesis", diff --git a/rpc/handlers_servicer.go b/rpc/handlers_servicer.go new file mode 100644 index 000000000..3f04570b5 --- /dev/null +++ b/rpc/handlers_servicer.go @@ -0,0 +1,26 @@ +package rpc + +import ( + "net/http" + + "github.com/labstack/echo/v4" +) + +func (s *rpcServer) PostV1ServicerRelay(ctx echo.Context) error { + + // TODO: Move to the servicer module + servicerModuleName := "servicer" + found := false + for _, am := range s.GetBus().GetUtilityModule().GetActorModules() { + if am.GetModuleName() == servicerModuleName { + found = true + break + } + } + + if !found { + return ctx.String(http.StatusInternalServerError, "node is unable to serve relays") + } + + return nil +}