Metadata-Version: 2.1
Name: drf-microservice
Version: 0.7.0
Summary: 
    A REST API endpoints with Authentication and Registration.
    Read the README.md for more information.    
Home-page: http://github.com/alainivars/drf-microservice
Author: Alain IVARS
Author-email: alainivars@gmail.com
License: Apache License 2.0
Keywords: django rest auth registration rest-framework django-registration api docker cookiecuter tox pytest
Platform: UNKNOWN
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Framework :: Django :: 2.1
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: System Administrators
Classifier: Operating System :: OS Independent
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Topic :: Internet :: WWW/HTTP
Requires-Python: >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*
Description-Content-Type: text/markdown

[![Build Status](https://travis-ci.org/alainivars/drf-microservice.png?branch=master)](https://travis-ci.org/alainivars/drf-microservice)
[![PyPI version](https://badge.fury.io/py/drf-microservice.svg)](https://badge.fury.io/py/drf-microservice)
[![Documentation Status](https://readthedocs.org/projects/drf-microservice/badge/?version=latest)](http://drf-microservice.readthedocs.io/en/latest/?badge=latest)
[![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/alainivars/drf-microservice.svg)](http://isitmaintained.com/project/alainivars/drf-microservice "Average time to resolve an issue")
[![Percentage of issues still open](http://isitmaintained.com/badge/open/alainivars/drf-microservice.svg)](http://isitmaintained.com/project/alainivars/drf-microservice "Percentage of issues still open")
[![Coverage Status](https://coveralls.io/repos/github/alainivars/drf-microservice/badge.svg?branch=master)](https://coveralls.io/github/alainivars/drf-microservice?branch=master)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/Django.svg)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![PyPi wheel](https://pypip.in/wheel/drf-microservice/badge.svg)](https://pypi.python.org/pypi/drf-microservice/)


# About drf-microservice
drf-microservice is a ready-to-use API skeleton, generated by [cookiecutter-drf-microservice](https://github.com/alainivars/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
```shell
DRF_MiCROSERVICE_USERNAME_PASSWD => a client API password
SECRET_KEY => the secret key
```
### ENV required
```shell
AWS_REGION_NAME => default="eu-east-1"
AWS_DRF_MiCROSERVICE_SECRET_NAME =>The name of the secret bucket
```
## To install
todo
```shell
git clone xxx
cd xxx
python3 -m venv /pass_to/venv/drf-microservice
```
- for bash, zsh
```shell
source /pass_to/venv/drf-microservice/bin/activate
```
- for fish
```shell
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
```shell
/usr/bin/env SECRET_KEY=my_secret_key python manage.py createsuperuser
```
- then run it
```shell
SECRET_KEY=my_secret_key python manage.py runserver
```
- if you have any problem or you want enable the debug mode
```shell
ENABLE_DEBUG=1
```


## API
To see the documentation for the API
Login at
```shell
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.
```shell
{"key":"400a4e55c729ec899c9f6ac07818f2f21e3b4143"}
```

Then open to see the full auto-generated documentation of you API 
```web
curl --request GET \
  --url http://127.0.0.1:8000/docs/ \
  --header 'authorization: Basic YWRtaW46YWRtaW4='
```
or by if BasicAuthentication is disabled
```web
curl --request GET \
  --url http://127.0.0.1:8000/docs/ \
  --header 'authorization: Token 400a4e55c729ec899c9f6ac07818f2f21e3b4143'
```
![Dynamic documentation](media/docs.png)

## testing
You can run the tests by:
```shell
SECRET_KEY=my_secret_key python manage.py test
```
or by
```shell
python setup.py test
```
or by
```shell
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
```shell
SECRET_KEY=my_secret_key python manage.py check --deploy 
```
### Build and run the image with Docker

#### Build the Docker image:
````shell
#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:
````shell
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:
````shell
sudo docker run --rm -it \
                -v pg_backups:/pg_backups \
                -v /host/dir/pg_backups:/host_backups \
                alpine:latest
````
Then in the container
````shell
cp /pg_backups/* /host_backups/
````

### Build and run wit docker-compose
```shell
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

