Skip to content
This repository has been archived by the owner on Mar 1, 2022. It is now read-only.

[DEPRECATED - See openxeco-core] API of openXeco

Notifications You must be signed in to change notification settings

CybersecurityLuxembourg/bo-api

Repository files navigation

logo

Bandit Workflow
Prospector Workflow
Unittest Workflow
Twitter

Outlines

All the versions mentioned are the recommended ones.

Install local mySQL server

Version 8.0.22 https://dev.mysql.com/downloads/installer/

For Windows, MySQL requires those dependencies:

MySQL configuration:

  • For a local environment, you will require a root user with the following password: DBDevSMILE20. You can also change and define an account and a password that you will need to report to config/config.py
  • For Windows only, set the lower_case_table_names=2 on the my.ini (Right value by default on Linux distribs)

Then, you can run the SQL script with the DB structure in db/structure/001_init.sql

Hint: You can use PHPMyAdmin or MySQL Workbench to administrate your server.

Install Python 3.8.6

https://www.python.org/downloads/release/python-386/

Create Python virtual environment and install dependencies

For Linux:

$ sudo apt install mysql-server python3-venv -y
$ cd ~/project/bo-api
$ python3 -m venv venv
$ source venv/bin/activate
$ pip install -U pip setuptools
$ pip install -r requirements.txt

For Windows

> cd %USERPROFILE%\project\bo-api
> python -m venv venv
> .\venv\Scripts\activate
> pip install -U pip setuptools
> pip install -r requirements.txt

Import the database structure

$ cd ~/project/bo-api
$ mysql -u root -p < ./db/sql/cyberlux_structure.sql

Run environment

You have to make sure that the python environment is active If not:

> cd %USERPROFILE%\project\bo-api
> python -m venv venv
> .\venv\Scripts\activate

Then:

# Copy and edit sample config
$ cp config/config.py.sample config/config.py
$ python application.py

Simulate SMTP server

Some resources of the API requires a SMTP server, you can simulate in local environment with this following command:

> python -m smtpd -n -c DebuggingServer localhost:1025

Run the unittests

To run a single test

> python -m unittest test/resource/company/test_get_company.py

To run the whole set Here --buffer or -b is used to discard the output on a successful test run

> python -m unittest --buffer

Run the test coverage report (with the venv activated)

> coverage run --source=resource,utils,db,decorator -m unittest discover && coverage report

Run the test coverage report and generate in HTML (with the venv activated)

> coverage run --source=resource,utils,db,decorator -m unittest discover && coverage html

Run the code analysers

npm is needed

$ sudo apt install npm -y

To run the PyCQA/prospector

> npm install prospector
> prospector -i venv/ --no-autodetect

To run the PyCQA/bandit

> sudo apt install bandit
> bandit -r .