Code Monkey home page Code Monkey logo

vape-sensor-inventory's Introduction

vape-sensor-inventory

About this micro service

This micro-service is powered by Flask with connexion which auto handles all HTTP request mapping
For details refer to swagger.yaml

Release Note (Feb 2, 2020)

  1. Refactored code structure to follow best practices including the use of facade, and DTO mapper, to improve code readability and maintainability.
  2. Previous Violations to Swagger contract have all been resolved.
  3. Enabled response validation in Flask App to ensure developer maintain the integrity of swagger
  4. TODO items: refer to TODO section

Setup

Install pip
Make sure to have python3
that's it

Running on Local

A script is provided to help with dev setup and running

From project root directory, run ./scripts/init_venv.sh will create a virtual env and install all dependencies

After virtual env is set up, run ./scripts/run_server.sh will boot up the server on localhost:8822

API Endpoints

Note: API testing should strictly be based on swagger file, NOT any source of documentation

Use swagger file to examine Endpoint structure click here for swagger editor

Note: To try it out in Dev environment using swagger editor, update the host to host: sensor.vibraneur.com and schemes to HTTPS. To try it out in Local environemnt using editor, udpate the host to your loopback address and schemes to HTTP, NOT HTTPS. Dev envirinment will NOT redirect HTTP call to HTTPS. It is developer's repsponsibility to ensure usage of HTTPS calls

TODO (Fed 2, 2019)

  1. Bootstrap Flask (in progress) (Done)
  2. Database provision (done)
  3. Team meeting
  4. Unit Test (Long overdue)...

Swagger

Copy and paste swagger file to online editor to view API structure here

Swagger file validation

install swagger-cli using npm: run npm i -g swagger-cli
validate file by running swagger-cli validate ./swagger/swagger.yaml Online editor also provides validation here

API Requirements:

Database implemented in no-sql in dynomoDB or mongoDB

  • Will probably have to listen to kafka pipeline
  • Heartbeat to indicate sensor is healthy
  • Sensors and bearings in the same database
  1. Ability to query a list of installed sensors
  2. Ability to query the status of each sensor
  3. Ability to query information about a sensor
  4. Query the total number of sensors
  5. Ability to add a new sensor
  6. Ability to remove a sensor
  7. Ability to check the health of a sensor

vape-sensor-inventory's People

Contributors

benxinniu avatar noahgallant-mun avatar summer0410 avatar vibraneur avatar

Watchers

 avatar  avatar

vape-sensor-inventory's Issues

Valid MongoDB connection string exposed in plaintext

Just a heads - these are sufficient to access your database on Atlas:

MONGO_CONNECTION_STRING = mongodb+srv://db-vape-sensor-inventory:theMostSecurePassword?!@cluster-vape-sensor-inventory-fcfqt.mongodb.net/test?retryWrites=true&w=majority

MONGO_CONNECTION_STRING = "mongodb+srv://db-vape-sensor-inventory:theMostSecurePassword?!@cluster-vape-sensor-inventory-fcfqt.mongodb.net/inventory?retryWrites=true&w=majority"

Tested by inserting a doc to a new db and collection:

MongoDB Enterprise cluster-vape-sensor-inventory-shard-0:PRIMARY> db.getSiblingDB("hello")["world"].find()
{ "_id" : ObjectId("5e3cb4d666f9fa4df195e6c2"), "example" : "doc" }

Doesn't look like the database itself has been used for much yet, but these credentials should be rotated as soon as is reasonable.

500 returned when query /bearing?id=some id that does not exit in db

Currently if query a bearing that does not exist in the databse, the api would return 500. Ideally the api should return 400, since it is likely the user's fault:
Suggested action is to add try block to catch ModelDoesNotExist Exceptions.
See Line 18 (return Bearing.objects.get(id=id)) in bearing_info.py

Duplicate Sensor Ids in the `sensorsId` List

This is a snapshot of what we have in the databse. It looks like whenever we are adding a sensor to bearing, it just does a simple append without deduplicate..
"sensorsId": [
"5e4c06b3df9931ea80aea288",
"5e4c06b3df9931ea80aea288",
"5e4c06b3df9931ea80aea288",
"5e4c06b3df9931ea80aea288",
"5e4c06b3df9931ea80aea288",
"5e4c06b3df9931ea80aea288",

Defensive Coding in Controller

In line 30 (post_new_bearing function) of bearing_info_controller.py

This function tries to access tags and sensorId field from body. If these fields do not exist, the API will likely throw 500 errors when it clearly is the user's fault. We should practice defensive coding for this part. Although, tags is an optional field. If tags is not found in body a default {} dict should be used.

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.