Skip to content

Commit a40df5f

Browse files
xncz8hivokroskinskijp
authored
Feature/fix readme (#21)
Co-authored-by: kroskinskiis <ivo.kroskinski@tno.nl> Co-authored-by: jp <jan-paul.konijn@tno.nl>
1 parent e436ee7 commit a40df5f

File tree

8 files changed

+108
-140
lines changed

8 files changed

+108
-140
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
.vscode/settings.json
22
**/__pycache__/
3-
.env
3+
**/env/**

README.md

Lines changed: 69 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,86 @@
11
# SOARCA Fin Library
22
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.
35

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
622
- Python3
23+
- Poetry
724

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:
1028
```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}"
1531
MQTT_USERNAME = "{INSERT_USERNAME_HERE}"
1632
MQTT_PASSWD = "{INSERT_PASSWORD_HERE}"
1733
```
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+
```
1841

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:
2145
```bash
22-
python3 main.py
46+
pip3 install poetry
2347
```
2448

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+
```
3054

55+
To install the dependencies in a poetry shell or create a virtual environment, run:
56+
```bash
57+
poetry install
58+
```
3159

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+
```
3466

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+
```
3671

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+
```

examples/gettingstarted.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Getting started
2+
3+
4+
### prerequisites
5+
To install sourca-fin-library you can use the following command:
6+
7+
```bash
8+
pip install -r requirements.txt
9+
```
10+
### Quick run
11+
12+
```bash
13+
python3 pong_example.py
14+
```
Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import os
2-
import logging as log
32
from dotenv import load_dotenv
43

54
from soarca_fin_python_library.soarca_fin import SoarcaFin
@@ -16,44 +15,57 @@
1615

1716

1817
def capability_pong_callback(command: Command) -> ResultStructure:
19-
log.info("Received ping, returning pong!")
20-
out = Variable(
18+
print("Received ping, returning pong!")
19+
20+
result = Variable(
2121
type=VariableTypeEnum.string,
2222
name="pong_output",
2323
description="If ping, return pong",
2424
value="pong",
2525
constant=True,
2626
external=False)
27+
2728
context = command.command.context
29+
2830
return ResultStructure(
29-
state="success", context=context, variables={"result": out})
31+
state="success", context=context, variables={"result": result})
3032

3133

3234
def main(mqtt_broker: str, mqtt_port: int, username: str, password: str) -> None:
3335

34-
agent = AgentStructure(name="soarca-fin--123")
36+
finId = "soarca-fin--pingpong-f877bb3a-bb37-429e-8ece-2d4286cf326d"
37+
agentName = "soarca-fin-pong-f896bb3b-bb37-429e-8ece-2d4286cf326d"
38+
externalReferenceName = "external-reference-example-name"
39+
capabilityId = "mod-pong--e896aa3b-bb37-429e-8ece-2d4286cf326d"
40+
41+
# Create AgentStructure
42+
agent = AgentStructure(
43+
name=agentName)
3544

36-
external_reference = ExternalReference(name="external-reference-name")
45+
# Create ExternalReference
46+
external_reference = ExternalReference(name=externalReferenceName)
3747

48+
# Create StepStructure
3849
step_structure = StepStructure(
3950
name="step_name",
4051
description="step description",
4152
external_references=[external_reference],
42-
command="test-command",
43-
target="123456")
53+
command="pong",
54+
target=agentName)
4455

56+
# Create CapabilityStructure
4557
capability_structure = CapabilityStructure(
46-
capability_id="mod-virustotal--e896aa3b-bb37-429e-8ece-2d4286cf326d",
58+
capability_id=capabilityId,
4759
type=WorkFlowStepEnum.action,
48-
name="capability_name",
60+
name="Ping Pong capability",
4961
version="0.0.1",
5062
step={
5163
"test": step_structure},
5264
agent={
5365
"testagent": agent})
5466

5567
# Create Soarca fin
56-
fin = SoarcaFin("123456789")
68+
fin = SoarcaFin(finId)
5769
# Set config for MQTT Server
5870
fin.set_config_MQTT_server(mqtt_broker, mqtt_port, username, password)
5971
# Register Capabilities
@@ -63,8 +75,6 @@ def main(mqtt_broker: str, mqtt_port: int, username: str, password: str) -> None
6375

6476

6577
if __name__ == "__main__":
66-
log.basicConfig()
67-
log.getLogger().setLevel(log.DEBUG)
6878
load_dotenv()
6979
MQTT_BROKER = os.getenv("MQTT_BROKER", "localhost")
7080
MQTT_PORT = int(os.getenv("MQTT_PORT", "1883"))

examples/requirement.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
soarca-fin-library

img/class_overview.plantuml

Lines changed: 0 additions & 37 deletions
This file was deleted.

img/sequence_diagram_command.plantuml

Lines changed: 0 additions & 25 deletions
This file was deleted.

img/sequence_diagram_register.plantuml

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)