Skip to content

Instantly share code, notes, and snippets.

@nully0x
Last active October 25, 2023 17:40
Show Gist options
  • Save nully0x/5030a296571d780ede8a536ed1d50832 to your computer and use it in GitHub Desktop.
Save nully0x/5030a296571d780ede8a536ed1d50832 to your computer and use it in GitHub Desktop.
Implementing user interaction with Warnet

Task

Unify the client and server api

Refactor the api endpoints to just three:

  • Account creation
  • Signin Action (to return api key for authorisation)
  • Json-Rpc method call (authenticatied request).

Flow

On implementation, we want users to be able to interact with the warnet service from a controlled and secured api call when the service finally gets deployed on our cloud instances to avoide overloading.

We are creating a seperate API service that will hook up to the warnet service and execute the warnet json-rpc call instead of calling them directly from the terminal (which might not be intuitive for a all users)

We have setup auth module that creates an account for the user which gets saved to a postgres db so that we can generate an api key to allow for authorisation when accessing warnet service.

On signin with the resgistered details, user gets a apikey (token) to allow access to calling warnet service.

We are aggregating all warnet json-rpc call into one route such that when a user needs to call the warnet service they only provide a method to call not the entire json-rpc object.

For example: To list all scenarios, currently user have to pass in - { "jsonrpc": "2.0", "id": 1, "method": "list" } we are implementing this such that user only need to hit a route say: localhost:8000/warnet and pass in the apikey and the method only which will be { "apikey":string, "method": "list" }

this also works for other commands to be executed again warnet service, for example to list all active scenarios will be

{ "apikey":string, "method": "list_running_scenarios" }

To allow for easy interaction, we will provide all available warnet service in the doc so user don't have to check which command/method to execute.

All arguments will be passed as a body request and we handle all other process on the logic. For example a simple curl will look like curl -X POST -H "Content-Type: application/json" -d '{ "apikey": "your_api_key_here", "method": "list" }' http://localhost:8000/warnet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment