Giter VIP home page Giter VIP logo

iot-database-endpoint's Introduction

iot-database-endpoint

This is a general repository capable of spinning up a highly flexible endpoint for IoT devices.

Routes

Table Route Methods
data /api/v1/data POST

Swagger Documentation

Once deployed, FastApi automatically renders a Swagger API documentation at https://<your_domain>/docs for developers to read.

Configuration

For the email Templates to render successfully, copy logo/logo_green.png to /datso it can be loaded from the web. All configurations are done using the .env file. It can be copied from sampledotenv.

POSTGRES_NAME=postgres
POSTGRES_USER=postgres
POSTGRES_PASSWORD=
POSTGRES_HOST=db
POSTGRES_PORT=5432
BASEAUTH_USERNAME=root
BASEAUTH_PASSWORD=

SSL

This project contains a pair of microservices that enable automated SSL encryption. The NGINX reverse proxy labelded webserver can be fed with configuration files that can be genenerated with the nginx/apps.json and the nginx/config_generator.py files.

Whenever a new certificate file has to be generated due to a domain migration, the nginx config files have to modified accordingly and the script init-letsencrypt.sh has to be run. Only one service can be encrypted at a time. Thus, only one config file can be modified at a time aswell.

Security

The API is protected with http BaseAuth, using the username root and a password. This ensures that only authorized IoT devices can post to the database.

Deployment

All components are deployed using docker-compose.

docker-compose up -d --build

If you want to run the application without docker-compose, the .env vars have to be set manually using the following command:

export $(echo $(cat ../.env | sed 's/#.*//g' | sed 's/\r//g' | xargs) | envsubst)

Tests

โš ๏ธ Environment Variables: Make sure to use diffrent variables for the test databases, as located in test/__init__.py.

All have been developed in a test-driven development (TDD) style. This makes the entire application testable and easy to maintain. In order to run the tests, you must first install the dependencies:

pip install -r requirements.txt

Just like when deploying the app manually, the .env vars have to be set manually using the following command:

export $(echo $(cat ../.env.test | sed 's/#.*//g' | sed 's/\r//g' | xargs) | envsubst)

The tests are located in the test directory. Run them using:

python3 -m pytest

Backup & restore

Backup

To get a backup of the Postgres database, run the command below after inserting the correct password.

sudo docker exec -i iot-database-endpoint_db_1 /bin/bash -c "PGPASSWORD=password pg_dump --username postgres postgres" > dump.sql

SSL certificates are stored in ./certbot folder, they are automatically renewed from LetsEncrypt every month.

Restore

In order to load a backup run the command below after inserting the right password

sudo docker-compose up -d db
sudo docker exec -i iot-database-endpoint_db_1 /bin/bash -c "PGPASSWORD=password psql --username postgres postgres" < dump.sql
sudo docker-compose up -d--build

iot-database-endpoint's People

Contributors

joengelh avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.