This project enables a JWT access key generator in an HTTP proxy written in Python 3.6 with Flask framework.
- If you prefer to run the proxy manually, install the requirements and run the proxy server.
- For automatic tests, install requirements and skip to Automatic tests.
- To use the JWT Generator class, install requirements and skip to class that generates Tokens.
- If you prefer Docker, go to Containerise with Dockerfile.
- To run Docker compose, skip to Docker compose instructions.
- About logs, please move to the corresponding topic, Logs.
- Instructions on advanced/technical documentation, go to Documentation.
- Or click to skip to the To do list.
I recommend using virtualenv to run py manually.
Install the requirements:
$ python3 -m pip install -r requirements.txt
Note: The proxy/config.py file should not be in a public repo, but once the secret key is public, I kept the file to facilitate the review. Normally, I would instruct copying and editing proxy/config.py.tpl.
By default, the proxy runs on port 5000. This can be changed in the config file.
$ python3 -m proxy
At this point, we should be able to browse: http://localhost:5000/
Please remember to hit Ctrl+c to stop the web server when done.
Python tests are available using unittest/PyUnit via Makefile or manually.
Note: depending on how the proxy was started, may require sudo chmod o+w logs/*
(not if in production).
- Run
make test
to install requirements and run the tests. - Or install requirements and manually run
python3 -m unittest tests/test_*
.
An extra basic test is available in Bash script using curl and it tests proxy running manually, containerised or composed:
$ bash tests/curl-post.bash
With the python console and the class that generates JWT, we can get a Token:
$ python3
>>> from proxy.Token import Token
>>> user = 'fernando@github.com'
>>> t = Token(user)
>>> t.jwt
I assume that you have docker engine running. If not, please see Get Docker.
If you rather run the proxy in a single container, run:
$ docker run --rm -d -p 5000:5000 --name proxy $(docker build -f Dockerfile -t proxy . -q)
To know IP and Port to the containerised app:
$ docker inspect proxy | grep -e IPAddr.*[0-9] -e HostPort | sed 's/[^0-9\.]//g' | sort -u
After this, we should be able to browse: http://<container IP>:5000/
To stop container and clean image, use:
$ docker stop proxy && docker image rm proxy
I assume that you have docker compose installed. If not, please see Install Docker Compose.
There are Makefile rules to simplify this option. See the list of commands:
$ make
to build and run (up) the application.- or run
$ make build; make run
(note: run already calls build).
- or run
$ make stop
andmake start
to start the container.$ make rm
to remove compose service, container, image.
The default HTTP proxy PORT is 5000 and set in .env. The port can be changed:
$ HTTP_PORT=8080 make up
By default, logs are recorded in the 'logs' directory in the project's root. However, if you containerise the proxy, logs will be inside the container. And if you docker compose, the container will use the hosts' dirs as in Running the proxy.
Please see docs/logs if you wish to access samples of the generated logs.
Please try from python console:
$ python3
>>> import proxy
>>> help(proxy)
Or try from command line:
$ python3 -c "import proxy; help(proxy.config)"
All documentation can be found in docs.
- Document separation of server from proxy._main_
- Configure rotation of log files.
- Review docstring in db.py.