Code Monkey home page Code Monkey logo

python-file-deamon's Introduction

Dr.Hash

This is a Flask application which provides a RESTful API to your service

Setup

Docker

Build the Docker image:

docker-compose build

Run the docker-compose environment

docker-compose up -d

This application comes with the unit tests. To run the tests do

docker-compose run --rm file_daemon py.test --cov=filedaemon

Supervisor

As the root user, run the following command to install the Supervisor package

apt-get install supervisor -y
service supervisor restart

Edit daemon.conf in a root directory changing YOUR_PATH_TO_PYTHON with path to python on your system (you should consider using virtual environment since an application requires dependencies to be installed) and GIT_REPO_DIRECTORY to the directory you cloned this repository

Run deamonizing script

. daemonize.sh

Then you can check that the daemon is running with

supervisorctl status filedaemon

When you want to stop it, call

supervisorctl stop filedaemon

Read more about supervisor at the official page

Standalone

Clone this repository on your local machine

git clone https://github.com/antibagr/python-file-deamon

Create and activate new virtual environment

python3 -m venv venv
. venv/bin/activate

Install dependencies

cd python-file-deamon
python -m pip install --upgrade pip
python -m pip install -r requirements.txt

Finally, you're able to run server with both

python filedaemon

and

python filedaemon/app.py

Run tests with the following command

py.test

Configuration

In filedaemon folder you can find config.py where you can set desired hasing method, max file size which can accept a server and also various directories.

By default all recevied files stored in filedaemon/files

You can change this behavior updating STORAGE_DIR in config.py

Configuration settings works only in standalone and supervisor mode Because I didn't have time to set container so it can accept host, port and debug parameters. Stay tuned, though

API References

  • /api/v1/upload - uploading new file. Requires: a file filed in a body request Returns: JSON response with filed hashed that contains hash of the stored file
  • /api/v1/download - download a stored file Requires: Hash of previously uploaded file in hash field Returns: Stored file if file exists and 404 response if file was not found
  • /api/v1/delete- delete a stored file Requires: Hash of previously uploaded file in hash field Returns: 200 response if file was deleted and 404 reponse if file was not found

API always returns a JSON response which contains a status_code filed and message field. Please notice that not all HTTP method is allowed i.e. /api/v1/download only accept GET method. If a request with invalid method was received, a 405 response will be returned.

If required filed is not provided server wiil anwser with 400 status code.

To see full status code list please refer to docstings of api clases in api.py

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.