teknologi-umum / pesto

Remote Code Execution Engine that lets you execute any piece of code on a remote server via REST API
Apache License 2.0
37 stars 7 forks source link

Registration module #2

Closed aldy505 closed 2 years ago

aldy505 commented 2 years ago

Create a new module (or service, if you prefer that) on the /registration directory, written in any language. The module is a simple HTTP server with no CORS or security middleware being attached to it (because we're handling that on the API gateway level).

Some endpoints:

POST /api/register

Register the user into the waitlist. The email format should be validated. See https://stackoverflow.com/a/13013056

Request body:

{
  "name": "John Doe", // to get to know you
  "email": "johndoe@example.com", // we'll send your token here
  "building": "Some kind of a telegram bot that executes code", // what I'm building
  "calls": 10 // How many API calls per month will they do
}

Response: just give them a status code of 200, the body is optional. It's up to you.

GET /api/pending

Shows users that are still on the waitlist. Will return an empty array if the waitlist is empty.

Empty request body.

Response body:

{
  "waitlist": [
    {
      "name": "John Doe",
      "email": "johndoe@example.com",
      "building": "Something great",
      "calls": 10
    }
  ]
}

PUT /api/approve

Approve a user from the waitlist. Remove user from the waitlist, and store a key value of: key: token, value: {"user_email":"email","revoked":false} on etcd.

Request body:

{
  "email": "johndoe@example.com",
  "token": "some secure token here"
}

Response: just give a status code of 200 if successful, and a status code of 404 if not found.

PATCH /api/revoke

Revoke a token. Change the key-value on etcd for the key token to be: {"user_email":"the original email","revoked":true}

Request body:

{
  "token": "some secure token here"
}

Response: just give a status code of 200 if successful, and a status code of 404 if not found.

Client library

The official etcd client library is here: https://github.com/etcd-io/jetcd

We will be using Sentry for error logging and tracing. But, I guess it's not really easy to implement Sentry if you haven't read the documentation and how it works, so this may come later. The documentation for it: https://docs.sentry.io/platforms/java/ (if you chose other language than Java, scroll down a bit, and on the left navigation bar, there's some other platform)

RayWP commented 2 years ago

itu yang di expose keluar cuma /api/register, endpoint yang lain ga ada yang di expose to the internet

aldy505 commented 2 years ago

How to run the etcd database on your local machine:

docker network create pesto
docker compose up -d db

Then set the etcd address to http://localhost:2379 (or maybe just localhost:2379)

RayWP commented 2 years ago

tambah satu endpoint /healthz

isinya panggil ini, cek kalo ada yang statusnya ga ok https://javadoc.io/doc/io.etcd/jetcd-core/latest/io/etcd/jetcd/Maintenance.html

RayWP commented 2 years ago