From 72c341aaacda0cde3f69c650de7a07c7d3baf154 Mon Sep 17 00:00:00 2001 From: Devoalda Date: Wed, 1 Nov 2023 15:48:47 +0800 Subject: [PATCH] Update Readme and redis deployment --- README.md | 41 ++++++++++++++++++++++++++- safeshare/K8s/redis_deployment.yaml | 25 +--------------- safeshare/safeshare_app/views/file.py | 13 +++------ 3 files changed, 45 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index a894f71..49f665a 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,16 @@ pip install -r requirements.txt ## Usage ### Running Backend & Frontend Together (Using Docker Compose) + +A sample docker compose file is provided in the root directory. You can use it to run the backend and frontend together. + +> Please modify the environment variables in the docker-compose.yml file before running it. + +APIs: +- [VirusTotal](https://developers.virustotal.com/v3.0/reference) +- [AWS DynamoDB](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Introduction.html) +- [AWS](https://aws.amazon.com/) + ```bash # Run backend & frontend using docker-compose docker-compose up @@ -37,6 +47,8 @@ kubectl apply -f backend_service.yaml ``` ### For development +Copy the `env` file to `.env` and modify the environment variables accordingly. + ```bash # Run frontend locally cd ../safeshare-frontend @@ -72,4 +84,31 @@ python post_and_get_files.py # stressTest.py # Uploads multiple files in multiple threads (upload/download) python stressTest.py -``` \ No newline at end of file +``` + +## Features + +## React App + +Frontend is built using ReactJS and TailwindCSS. It is Containerised using Docker. + +An image is here [amusement3004/safeshare-frontend:latest](https://hub.docker.com/repository/docker/amusement3004/safeshare-frontend) + +## Django App + +Backend is built using Django REST Framework. It is Containerised using Docker. + +An image is here [amusement3004/safeshare:latest](https://hub.docker.com/repository/docker/amusement3004/safeshare) + +## Virus Scanning Microservice + +Virus Scanning microservice is built using [gRPC](https://grpc.io/), [Protocol Buffers](https://developers.google.com/protocol-buffers) +and [VirusTotal API](https://developers.virustotal.com/v3.0/reference). It is included in the Django App. + +## Trash Cleaning Microservice + +The application provides an automated cleaning service for the files that are uploaded to the server. +The files are deleted after a certain period of time (ttl). +The time period can be set in the `.env` file. (`TRASH_TIMEOUT`) + +This service will periodically check redis for the files that have expired and delete them from the server's storage. \ No newline at end of file diff --git a/safeshare/K8s/redis_deployment.yaml b/safeshare/K8s/redis_deployment.yaml index d9fc105..729fa4a 100644 --- a/safeshare/K8s/redis_deployment.yaml +++ b/safeshare/K8s/redis_deployment.yaml @@ -80,27 +80,4 @@ spec: volumes: - name: redis-persistent-storage persistentVolumeClaim: - claimName: redis-pv-claim - ---- - -apiVersion: autoscaling/v1 -kind: HorizontalPodAutoscaler -metadata: - name: safeshare-redis-hpa - labels: - app: safeshare -spec: - scaleTargetRef: - apiVersion: apps/v1 - kind: Deployment - name: safeshare-redis - minReplicas: 3 - maxReplicas: 6 - metrics: - - type: Resource - resource: - name: cpu - target: - type: Utilization - averageUtilization: 50 \ No newline at end of file + claimName: redis-pv-claim \ No newline at end of file diff --git a/safeshare/safeshare_app/views/file.py b/safeshare/safeshare_app/views/file.py index 3e5ac89..32dbec7 100644 --- a/safeshare/safeshare_app/views/file.py +++ b/safeshare/safeshare_app/views/file.py @@ -173,23 +173,18 @@ PRIVATE_IPS_PREFIX = ('10.', '172.', '192.') def get_client_ip(request): - """get the client ip from the request """ - # remote_address = request.META.get('REMOTE_ADDR') + Get Client's IP + """ remote_address = request.META.get('HTTP_X_FORWARDED_FOR') or request.META.get('REMOTE_ADDR') - # set the default value of the ip to be the REMOTE_ADDR if available - # else None ip = remote_address - # try to get the first non-proxy ip (not a private ip) from the - # HTTP_X_FORWARDED_FOR + x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR') + if x_forwarded_for: proxies = x_forwarded_for.split(',') - # remove the private ips from the beginning while len(proxies) > 0 and proxies[0].startswith(PRIVATE_IPS_PREFIX): proxies.pop(0) - # take the first ip which is not a private one (of a proxy) if len(proxies) > 0: ip = proxies[0] - print(ip) return ip