|
1 | 1 | # SOARCA Fin Library |
2 | 2 | A Python implementation for the SOARCA FIN, compatible with: SOARCA the TNO orchestrator for Open-C2, CACAO and STIX |
| 3 | +For more information about the SOARCA, we refer the reader to the [website](https://cossas.github.io/SOARCA/) of the SOARCA project. |
| 4 | +For more in depth documentation, see the documentation page on here. |
3 | 5 |
|
4 | | -## building / starting / stopping |
5 | | -### Requirements |
| 6 | +## Quick Use |
| 7 | + |
| 8 | +Usage of this SOARCA Fin Library is described [here](https://cossas.github.io/SOARCA/docs/soarca-extensions/fin-python-library/). |
| 9 | + |
| 10 | +## Example |
| 11 | + |
| 12 | +An example is given in this project in the file `examples/pong_example.py` |
| 13 | + |
| 14 | +## Contributing |
| 15 | +Want to contribute to this project? Please keep in mind the following [rules](https://cossas.github.io/SOARCA/docs/contribution-guidelines/): |
| 16 | +- This repository uses git **rebase** strategy |
| 17 | +- For each PR, there should be at least one issue |
| 18 | +- Make sure all tests pass (including lint errors) |
| 19 | + |
| 20 | +### Running this repository |
| 21 | +#### Requirements |
6 | 22 | - Python3 |
| 23 | + - Poetry |
7 | 24 |
|
8 | | -### Setup |
9 | | -Install requirements |
| 25 | +#### Setup |
| 26 | +##### Env File |
| 27 | +In order to run the project, create an `.env` file in the root of the project with the following entries: |
10 | 28 | ```bash |
11 | | -pip3 install -r requirements.txt |
12 | | -``` |
13 | | -Create .env file with the following entries: |
14 | | -``` |
| 29 | +MQTT_BROKER = "{INSERT_MQTT_BROKER_URL_HERE}" |
| 30 | +MQTT_PORT = "{INSERT_MQTT_PORT_HERE}" |
15 | 31 | MQTT_USERNAME = "{INSERT_USERNAME_HERE}" |
16 | 32 | MQTT_PASSWD = "{INSERT_PASSWORD_HERE}" |
17 | 33 | ``` |
| 34 | +If no `.env` file is specified, the following default values will be used: |
| 35 | +```bash |
| 36 | +MQTT_BROKER = "localhost" |
| 37 | +MQTT_PORT = "1883" |
| 38 | +MQTT_USERNAME = "soarca" |
| 39 | +MQTT_PASSWD = "password" |
| 40 | +``` |
18 | 41 |
|
19 | | - |
20 | | -### Quick Run |
| 42 | +##### Dependencies |
| 43 | +To handle dependencies in this project, the package Poetry is used. |
| 44 | +To install Poetry execute the following command: |
21 | 45 | ```bash |
22 | | -python3 main.py |
| 46 | +pip3 install poetry |
23 | 47 | ``` |
24 | 48 |
|
25 | | -### Setup SOARCA Capabilities |
26 | | -To register a fin to SOARCA, first create a SoarcaFin object pass the fin_id in the constructor. |
27 | | -Call `set_config_MQTT_server()` to set the required configurations for the fin to connect to the MQTT broker. |
28 | | -For each capability to be registered, call `create_fin_capability()`. The capability callback funtion should return an object of type `ResultStructure`. |
29 | | -When all capabilities are initialized, call `start_fin()` for the SOARCA Fin to connect to the MQTT broker and register itself to SOARCA. |
| 49 | +To install the dependencies from the `pyproject.toml` either enter a poetry shell, create a virtual environment or use poetry run. |
| 50 | +To enter a poetry shell execute the following command in the root of the project: |
| 51 | +```bash |
| 52 | +poetry shell |
| 53 | +``` |
30 | 54 |
|
| 55 | +To install the dependencies in a poetry shell or create a virtual environment, run: |
| 56 | +```bash |
| 57 | +poetry install |
| 58 | +``` |
31 | 59 |
|
32 | | -## Documentation |
33 | | -For documentation about the fin protocol we refer the reader to de documention page of [SOARCA](https://cossas.github.io/SOARCA/docs/soarca-extensions/fin-protocol/) |
| 60 | +### Quick Run |
| 61 | +To quick run the project, either run it through poetry run or a poetry shell. |
| 62 | +#### Poetry Run |
| 63 | +```bash |
| 64 | +poetry run python examples/pong_example.py |
| 65 | +``` |
34 | 66 |
|
35 | | -For class diagrams and example sequence diagrams of the Fin implementation [plantUML](https://plantuml.com/) is used. |
| 67 | +#### Poetry Shell |
| 68 | +```bash |
| 69 | +python examples/pong_example.py |
| 70 | +``` |
36 | 71 |
|
37 | | -### Application Layout |
38 | | -The main object of the application is the `SoarcaFin` object, which is responsible for configuring and creating and controlling the capabilities. |
39 | | -The SoarcaFin creates `MQTTClient`s for each capability registered, plus one for registering, unregistering and controlling the fin. |
40 | | -`MQTTClient`s each have their own connection to the MQTT Broker and own `Parser` and `Executor` objects. |
41 | | -The `Parser` object parsers the raw MQTT messages and tries to convert them to one of the objects in `src/models`. |
42 | | -The `Executor` runs in their own thread and handles the actual execution of the messages. |
43 | | -The `Executor` polls a thread-safe queue for new messages and performs IO operations, such as sending messages to the MQTT broker and calling capability callbacks. |
| 72 | +### Running tests |
| 73 | +To run the tests in this repository use: |
| 74 | +```bash |
| 75 | +poetry run python -m unittest |
| 76 | +``` |
| 77 | +To run python linter, first install pylint and then run pylint with the following arguments: |
| 78 | +```bash |
| 79 | +poetry add pylint && |
| 80 | +poetry run pylint --disable=R,C $(git ls-files '*.py') |
| 81 | +``` |
| 82 | +To format the code base, first install ruff and then run ruff: |
| 83 | +```bash |
| 84 | +poetry add ruff && |
| 85 | +poetry run ruff format |
| 86 | +``` |
0 commit comments