SaaS file storage API implementation using Python and Flask. Cloud Computing Class Final Project.
- Authentication
- Create file
- Delete file
- Open file content
- List of files
- Make directory
- Delete directory
- List of directories
- Move file location
- Move directory
- Python 2.7.* or Python 3
- Python packages:
pip install bcrypt pyjwt flask flask_restful gevent pickledb uuid
python main.py
- AuthController.py: Authentication and registration controller
- AuthRoutes.py: Contains Login and Register API
- FileController.py: File operations controller
- FileRoutes.py: Contains file operations API
- main.py: Main execution file
- UsersModel.py: Model interacting with 'users.db' file
- requirements.txt: List of required python packages
*tested in Windows 10
- Register
curl http://localhost:5000/register -X POST -d "{\"username\": \"admin\", \"password\": \"123456\"}"
- Login
curl http://localhost:5000/login -X POST -d "{\"username\": \"admin\", \"password\": \"123456\"}"
- Create file
curl http://localhost:5000/create -X POST -H "Authorization:<token>" -d "{\"file_path\": \"test1.txt\", \"file_content\": \"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\"}"
- Open file
curl http://localhost:5000/open -X POST -H "Authorization:<token>" -d "{\"file_path\": \"test1.txt\"}"
- Delete file
curl http://localhost:5000/delete -X POST -H "Authorization:<token>" -d "{\"file_path\": \"test1.txt\"}"
- List files
curl http://localhost:5000/lsfile -X POST -H "Authorization:<token>" -d "{\"folder_path\": \"\"}"
- Create directory
curl http://localhost:5000/mkdir -X POST -H "Authorization:<token>" -d "{\"folder_path\": \"new_folder_1\"}"
- Delete directory
curl http://localhost:5000/rmdir -X POST -H "Authorization:<token>" -d "{\"folder_path\": \"new_folder_1\"}"
- List directories
curl http://localhost:5000/lsdir -X POST -H "Authorization:<token>" -d "{\"folder_path\": \"\"}"
- Move files
curl http://localhost:5000/mvfile -X POST -H "Authorization:<token>" -d "{\"src\": \"test1.txt\", \"des\": \"new_folder_1\"}"
- Move dirs
curl http://localhost:5000/mvdir -X POST -H "Authorization:<token>" -d "{\"src\": \"new_folder_1\", \"des\": \"new_folder_2\"}"
- Check Storage Status
curl http://localhost:5000/status -H "Authorization:<token>"
Make sure you have docker and docker-compose installed.
Build storageservice and reverseproxy image
docker build -t storage-service .
docker build -t reverseproxy reverseproxy
Run docker-compose
docker-compose up --scale storageservice=3 -d
This will make 3 storageservice containers and add reverse proxy as load balancer. Reverse proxy is mapped to localhost:5000, so you can use above url example. Feel free to change it.