The source code of this API is written using the Flask framework for Python 3. It depends on standard libreries, plus the ones declared in requirements.txt.
-
In order to install the dependencies you need
pip3
andvenv
Python modules. -pip3
is available in many Linux distributions (Ubuntu packagepython3-pip
, CentOS EPEL packagepython3-pip
), and also as pip Python package.sudo apt-get install python3-pip python-dev build-essential
- `venv` for Python 3 can be installed with:
sudo apt-get install python3-venv
-
The creation of a virtual environment and installation of the dependencies in that environment is done running:
python3 -m venv .pyenv
source .pyenv/bin/activate
pip install --upgrade pip wheel
pip install -r requirements.txt -c constraints.txt
As the API can be used both for development and production, this code looks for the configuration file flask_app.py.json
at the very same directory as it is installed. There are a couple of pre-configured files flask_app.py.json.dev
and flask_app.py.json.prod
which can be symlinked to flask_app.py.json
.
Also, as the API queries collection TestActions, which has controlled access, a configuration file flask_app.py.json.auth
is also needed.
There is a template of this file at flask_app.py.json.auth.template.
This API can be integrated into an Apache instance. The instance must have the module WSGI installed (package libapache2-mod-wsgi-py3
in Ubuntu).
sudo apt-get install libapache2-mod-wsgi-py3
sudo a2enmod wsgi
sudo service apache2 restart
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /home/<USERNAME>/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# Added to ensure Apache forwards authentication headers to Flask
WSGIPassAuthorization On
WSGIDaemonProcess flask_app python-path=/path/to/bench_event_api python-home=/path/to/bench_event_api/.pyenv
WSGIProcessGroup flask_app
WSGIApplicationGroup %{GLOBAL}
Alias /rest/bench_event_api /path/to/bench_event_api/flask_app.wsgi/
<Location /rest/bench_event_api>
Require all granted
SetHandler wsgi-script
Options +ExecCGI
</Location>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>