This is a simple GO CRUD REST API with microservice implementation written as a part of hiring process for the Site Reliability Enginneer Role at Deall.
Normally, each microservice would be pushed to different repositories, but for simplicity sake this repository will contain all the microservices used in the API.
This REST API is meant to be deployed to Kubernetes using Jenkins. But you could also simply install each microservice using Helm to Kubernetes.
Please do note that the following instructions was made to Install the API on a Google Kubernetes Engine
git clone https://github.com/kdknive/deall-coding-test
helm install ms-go-auth ms-go-auth/helm/ms-go-auth -n coding-test --create-namespace
helm install ms-go-crud ms-go-crud/helm/ms-go-crud -n coding-test
If the following command resulted an Error you probably haven't installed NGINX Ingress Controller on your Kubernetes. (see NGINX Ingress GKE for reference)
export NGINX_INGRESS_IP=$(kubectl get service nginx-ingress-ingress-nginx-controller -n nginx -ojson | jq -r '.status.loadBalancer.ingress[].ip')
echo $NGINX_INGRESS_IP
ping $NGINX_INGRESS_IP
Below are the detailed information of the REST API's endpoints to be tested using Postman.
This is the default credentials for the first Admin
username : admin
password : admin123
| Method | Endpoint | Header | Body | Description |
|---|---|---|---|---|
| POST | /admin/first | None | None | Can only be used once to create the first Admin |
| POST | /admin | Authorization : <JWT Token> |
{
"name": "example admin",
"username": "exampleadmin",
"email": "[email protected]",
"password": "exampleadmin"
} |
Create Admin Requires Admin's JWT Token |
| POST | /user | None |
{
"name": "example",
"username": "example",
"email": "[email protected]",
"password": "example"
} |
Create User Can be done without any Token Can't use the same username and email as other users |
| GET | /user/<username> | Authorization : <JWT Token> | None | Get user data Admin's JWT Token can get any user data User's JWT Token can only get their own data |
| PUT | /user/<username> | Authorization : <JWT Token> |
{
"role": "user", //only applicable for Admins
"name": "example edited",
"username": "example",
"email": "[email protected]",
"password": "example"
} |
Update user data Admin's JWT Token can update any user data User's JWT Token can only update their own data Can't update if the username and email is the same as other users Updating the role is only applicable for Admins, the API won't read the "role" key if the JWT Token belongs to a user |
| DELETE | /user/<username> | Authorization : <JWT Token> | None | Delete user data Admin's JWT Token can delete any user data User's JWT Token can only delete their own data |
| GET | /users | Authorization : <JWT Token> | None | Get all user data Only Admin's JWT Token can get all user data |
| POST | /login | None |
{
"username": "example",
"password": "example"
} |
Admin/User Login Login to get JWT Token |
| GET | /auth | Authorization : <JWT Token> | None | Validate Token Check the validity of JWT Token |
The flow of this REST API is fairly simple. Clients can make requests to the API, and based on the Endpoint, the API will require you to provide JWT Token that can be acquired by using the /login endpoint.
The /login and /auth endpoint will be handled by ms-go-auth microservice while the others will be handled by ms-go-crud.
When an endpoint require the client to provide a JWT Token, ms-go-crud will access the /auth endpoint on ms-go-auth to authenticate the client. And if ms-go-auth responded with Status 200, the API will respond with the approriate response.
Here is the diagram of the CI/CD Pipeline used to deploy this REST API. The platform used for this pipeline is GCP with Google Kubernetes Engine (GKE) as the Kubernetes cluster.
Jenkins is used to automate the delivery of the microservices and was deployed on Kubernetes using Helm.
First when a developer pushed some changes to GitHub, it will send a webhook to Jenkins which will then start the building process of the microservice using the Jenkinsfile on the repository.
The Jenkinsfile will then create a Jenkins Agent pod on Kubernetes that will have Google Cloud Build container and Helm container. The Google Cloud Build container will be used to build the Dockerfile of the microservice and then push it to the Artifact Registry on GCP.
After that, the Helm container will use the Helm Chart of the microservice and use the Docker Image previously pushed to the Artifact Registry to finally install the microservice on Kubernetes.

