Skip to content
Snippets Groups Projects

CAPICE Data Backend Module

CI Code coverage Latest Release

Code style: black Imports: isort PEP8 Checked with mypy

DASF data backend for file transfer

Installation

Clone the source code from gitlab and install in a dedicated python environment using pip

git clone https://git.rwth-aachen.de/nfdi4earth/pilotsincubatorlab/pilots/capice/capice-data-backend
python -m venv venv
source ven/bin/activate
pip install ./capice-data-backend/

To use this in a development setup, clone the source code from gitlab, start the development server and make your changes::

git clone https://git.rwth-aachen.de/nfdi4earth/pilotsincubatorlab/pilots/capice/capice-data-backend
cd capice-data-backend
python -m venv venv
source venv/bin/activate
make dev-install

More detailed installation instructions my be found in the docs.

Setup and run the backup

To setup the communication to the DASF message broker, it is recommended to generate an .env file. This .env file has to contain information in the following form.

export DE_BACKEND_TOPIC="<message-broker-topic>"
export DE_BACKEND_WEBSOCKET_URL="<websocket-url>"
export DE_BACKEND_HEADER='{ "authorization": "Token <consumer-secret-token>" }'

Where

  • <message-broker-topic> is the topic at the message broker that the backend subscribes to
  • <websocket-url> is the URL of the websocket the backend connects to
  • <consumer-secret-token> is the secret token to authenticate at the message broker.

Then export the environment variable DE_MESSAGING_ENV_FILE to point to your .env file, for exmaple located in your home directory

export DE_MESSAGING_ENV_FILE="${HOME}/.capice_data_env"

With this setup you should be able run the backend via

./capice-data-backend/app.sh

The output should look something like this

2024-12-16 15:11:50,101 - INFO - [demessaging.messaging.consumer]: waiting for incoming request
2024-12-16 15:11:50,791 - INFO - [websocket]: Websocket connected
2024-12-16 15:11:51,233 - INFO - [websocket]: Websocket connected

Send a request to the backend

To send a request to the backend, for example from your local machine, you have to install this package in the same way than before on the remote machine.

git clone https://git.rwth-aachen.de/nfdi4earth/pilotsincubatorlab/pilots/capice/capice-data-backend
python -m venv venv
pip install ./capice-data-backend/

Then again create an .env file, with the following contents

export DE_BACKEND_TOPIC="<message-broker-topic>"
export DE_BACKEND_WEBSOCKET_URL="<websocket-url>"
export DE_BACKEND_HEADER='{ "authorization": "<producer-secret-token>" }'

DE_BACKEND_TOPIC and DE_WEBSOCKET_URL are the same as before for the backend. However, the DE_BACKEND_HEADER now contains the <producer-secret-token>. The secret token for authorization differ whether the backend authenticates to the message broker, or the API side.

Then source the .env file

source .env

A minimal example could look like this

from capice_data.api import version_info
print(version_info())

If everything is setup correct. The script on your local machine should request the software's version from the backend. The output should look something like this

2024-12-16 16:14:58,446 - INFO - [websocket]: Websocket connected
2024-12-16 16:14:58,450 - INFO - [websocket]: Websocket connected
2024-12-16 16:14:58,460 - INFO - [demessaging.messaging.producer]: start waiting for message
{'capice-data-backend': '0+untagged.21.g8494d7f'}

In this case the version of 'capice-data-backend' is '0+untagged.21.g8494d7f'.

Technical note

This package has been generated from the template https://codebase.helmholtz.cloud/dasf/templates/dasf-backend-template.git.

See the template repository for instructions on how to update the skeleton for this package.

License information

Copyright © 2024 Helmholtz-Zentrum hereon GmbH

All rights reserved.

License management

License management is handled with reuse. If you have any questions on this, please have a look into the contributing guide or contact the maintainers of capice-data-backend.