This is an API built using FastAPI to work with MongoDB and the data stored as part of the OperationsGateway project.
Assuming default configuration, the API will exist on 127.0.0.1:8000. You can visit /docs
in a browser which will give an OpenAPI interface detailing each of the endpoints and an option to send requests to them. Alternatively, you can send requests to the API using a platform such as Postman to construct and save specific requests.
If not already present, you may need to install development tools for the desired Python version using the appropriate package manager for your OS. For example, for Python3.8 on Fedora or RHEL:
sudo dnf install "@Development Tools" python38 python38-pip python38-setuptools python38-devel openldap-devel git
Poetry is used to manage the dependencies of this API. To install Poetry, follow the instructions from their documentation.
To install the project's dependencies, execute poetry install
. The dependencies and the code in this repo are compatible with Python >=3.8, <3.12.
Like DataGateway API, this repository contains a Nox file (noxfile.py
) which exists in the root level of this repository. There are a handful of sessions which help with repetitive tasks during development To install Nox, use the following command:
pip install --user --upgrade nox
To run a specific Nox session, use the following:
nox -s [SESSION NAME]
Currently, the following Nox sessions have been created:
black
- this uses Black to format Python code to a pre-defined style.lint
- this uses flake8 with a number of additional plugins (see the includednoxfile.py
to see which plugins are used) to lint the code to keep it Pythonic..flake8
configuresflake8
and the plugins.safety
- this uses safety to check the dependencies (pulled directly from Poetry) for any known vulnerabilities. This session gives the output in a full ASCII style report.tests
- this uses pytest to execute the automated tests intest/
. There are currently no automated tests written for this repository however.
In operationsgateway_api/
, there is an example config file (config.yml.example
). Copy this example so config.yml
exists in the same directory level and edit the configuration as needed for your system. There is also a logging configuration file (logging.ini.example
). Follow the same procedure as the config file as to set up the logging.
The authentication system uses JSON Web Tokens (JWTs) which require a private and public key pair to encrypt and decrypt the tokens. The keys can be generated by navigating to a directory and typing the command:
ssh-keygen -b 2048 -t rsa
Enter the path for the file as id_rsa
to create the keys in the current directory rather than in your home directory.
Press enter twice when prompted for the password so as not to set one.
The key should be OpenSSH encoded - this format is generated by default in Rocky 8. You can check whether your key is in the correct format by checking the start of the private key; it should be -----BEGIN OPENSSH PRIVATE KEY-----
.
Then edit the private_key_path
and public_key_path
settings in the auth
section of the config.yml
file to reflect the location where these keys have been created.