Skip to main content

A REST API endpoints with Authentication and Registration. Read the README.md for more information.

Project description

Build Status PyPI version Documentation Status Average time to resolve an issue Percentage of issues still open Coverage Status PyPI - Python Version License PyPi wheel

About drf-microservice

drf-microservice is a ready-to-use API skeleton, generated by cookiecutter-drf-microservice, add your endpoints, test it, package it, validate it on stage and deploy it. It sounds simple and it is. Something disturb you in the code? Don't hesitate to submit a pull request and contribute.

Releases Notes

- 0.7.0: restore original struct and move cookiecutter in cookiecutter-drf-microservice
- 0.6.1: Update dependencies 
- 0.6.0: start to productionize and add cookiecutter 
- 0.5.2: fix dendencies security alert
- 0.5.1: fix some document presentation on github and pypi
- 0.5.0: Initial publication version

AWS secret required

DRF_MiCROSERVICE_USERNAME_PASSWD => a client API password
SECRET_KEY => the secret key

ENV required

AWS_REGION_NAME => default="eu-east-1"
AWS_DRF_MiCROSERVICE_SECRET_NAME =>The name of the secret bucket

To install

todo

git clone xxx
cd xxx
python3 -m venv /pass_to/venv/drf-microservice
  • for bash, zsh
source /pass_to/venv/drf-microservice/bin/activate
  • for fish
source /pass_to/venv/drf-microservice/bin/activate.fish

python setup.py test python manage.py migrate

- for bash, zsh
```shell
SECRET_KEY=my_secret_key python manage.py test
  • for fish
/usr/bin/env SECRET_KEY=my_secret_key python manage.py createsuperuser
  • then run it
SECRET_KEY=my_secret_key python manage.py runserver
  • if you have any problem or you want enable the debug mode
ENABLE_DEBUG=1

API

To see the documentation for the API Login at

curl --request POST \
  --url http://127.0.0.1:8000/api-auth/login/ \
  --header 'content-type: application/json' \
  --data '{
	"username": "admin",
	"password": "admin"
	}'

Actually the default mode is "development" (same to the state of this project) in that mode a default login is the the db with username='admin' password='admin' you will get back in return your token.

{"key":"400a4e55c729ec899c9f6ac07818f2f21e3b4143"}

Then open to see the full auto-generated documentation of you API

curl --request GET \
  --url http://127.0.0.1:8000/docs/ \
  --header 'authorization: Basic YWRtaW46YWRtaW4='

or by if BasicAuthentication is disabled

curl --request GET \
  --url http://127.0.0.1:8000/docs/ \
  --header 'authorization: Token 400a4e55c729ec899c9f6ac07818f2f21e3b4143'

Dynamic documentation

testing

You can run the tests by:

SECRET_KEY=my_secret_key python manage.py test

or by

python setup.py test

or by

DJANGO_SETTINGS_MODULE=drf-microservice.config.local SECRET_KEY=my_secret_key pytest

Security check

Before dockerization for deployment to production, don't forget to check if by

SECRET_KEY=my_secret_key python manage.py check --deploy 

Build and run the image with Docker

Build the Docker image:

#docker build -t drf-microservice-db -v db_volume:/var/lib/postgresql/data postgres:9.6
docker build -t drf-microservice -f Dockerfile.drf-microservice .
docker-compose up
#docker build -t my-nginx -f Dockerfile.nginx .

Run the container:

docker network create my-network
docker run -d --name drf --net my-network -v /app my-drf
docker run -d --name nginx --net my-network -p "5000:80" my-nginx

If you want to change the port binding, it's here...

Backup your db:

sudo docker run --rm -it \
                -v pg_backups:/pg_backups \
                -v /host/dir/pg_backups:/host_backups \
                alpine:latest

Then in the container

cp /pg_backups/* /host_backups/

Build and run wit docker-compose

docker-compose up

DONE

- support basic auth removed
- support token auth
- endpoint json file POST,GET
- endpoint login/logout
- endpoint get tocken

TODO

- AWS ssm secret and Kms
- add getSentry support
- endpoint json file DELETE, PUT?
- add some strong auth
- create differents version:
    - S3
    - RDS
    - postgreSQL
    - Redis
    - Aerospike
    - ... 

for different use-case

- create the docker-image file
- create the ansible file
- create the terraform file
- create the kubertes file
- create the Juju file

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

drf-microservice-0.7.0.tar.gz (13.9 kB view details)

Uploaded Source

Built Distribution

drf_microservice-0.7.0-py3-none-any.whl (20.4 kB view details)

Uploaded Python 3

File details

Details for the file drf-microservice-0.7.0.tar.gz.

File metadata

  • Download URL: drf-microservice-0.7.0.tar.gz
  • Upload date:
  • Size: 13.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.19.1 setuptools/41.0.1 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.7

File hashes

Hashes for drf-microservice-0.7.0.tar.gz
Algorithm Hash digest
SHA256 b1f5e30a4d2686355e6227444723f75db8d3bc3244d7b3e9efed7813998903ab
MD5 229106a711902c21dc7d0f0fcf1336b3
BLAKE2b-256 bc94bd26ad4fab856170ed2a0cb86e681cb6c447e1778f502fa9b55d4af3f8ce

See more details on using hashes here.

File details

Details for the file drf_microservice-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: drf_microservice-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 20.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.19.1 setuptools/41.0.1 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.7

File hashes

Hashes for drf_microservice-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a487e94e217750be04d9623d3db3452ff8cbb5d0817d599602b303a1d587185e
MD5 3d8bbb87012e13cadbaa773d47d32dcd
BLAKE2b-256 775e64181f4049cb5a5642ea0504cc45ada5b1a2adf072a2ad1fe1a2e29bf583

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page