Creates a Better Dev Env
This commit is contained in:
25
docker/docker-compose.yml
Normal file
25
docker/docker-compose.yml
Normal file
@@ -0,0 +1,25 @@
|
||||
services:
|
||||
redis:
|
||||
image: bitnami/redis
|
||||
container_name: redis
|
||||
environment:
|
||||
REDIS_PASSWORD: redis
|
||||
network_mode: host
|
||||
volumes:
|
||||
- redis:/data
|
||||
|
||||
minio:
|
||||
image: bitnami/minio
|
||||
container_name: minio
|
||||
environment:
|
||||
MINIO_ROOT_USER: minio
|
||||
MINIO_ROOT_PASSWORD: minio123
|
||||
MINIO_DEFAULT_BUCKETS: default
|
||||
network_mode: host
|
||||
volumes:
|
||||
- minio:/bitnami/minio/data
|
||||
|
||||
|
||||
volumes:
|
||||
redis:
|
||||
minio:
|
||||
@@ -9,6 +9,7 @@ def get_config_s3():
|
||||
load_dotenv()
|
||||
|
||||
return {
|
||||
"aws_endpoint_url": os.environ.get("AWS_ENDPOINT_URL", None),
|
||||
"aws_access_key_id": os.environ.get("AWS_ACCESS_KEY_ID", None),
|
||||
"aws_secret_access_key": os.environ.get("AWS_SECRET_ACCESS_KEY", None),
|
||||
"region_name": os.environ.get("AWS_REGION_NAME", None),
|
||||
|
||||
@@ -11,6 +11,28 @@ import os
|
||||
from functools import cache
|
||||
|
||||
|
||||
def build_client_s3(config: dict) -> botocore.client.BaseClient:
|
||||
if "aws_endpoint_url" not in config:
|
||||
config["aws_endpoint_url"] = "https://s3.amazonaws.com"
|
||||
|
||||
if "aws_access_key_id" not in config:
|
||||
raise RuntimeError("Invalid S3 Config: Missing aws_access_key_id")
|
||||
|
||||
if "aws_secret_access_key" not in config:
|
||||
raise RuntimeError("Invalid S3 Config: Missing aws_secret_access_key")
|
||||
|
||||
if "region_name" not in config:
|
||||
raise RuntimeError("Invalid S3 Config: Missing region_name")
|
||||
|
||||
return boto3.client(
|
||||
"s3",
|
||||
endpoint_url=config["aws_endpoint_url"],
|
||||
region_name=config["region_name"],
|
||||
aws_access_key_id=config["aws_access_key_id"],
|
||||
aws_secret_access_key=config["aws_secret_access_key"],
|
||||
)
|
||||
|
||||
|
||||
@cache
|
||||
def dependency_storage_service() -> StorageService:
|
||||
load_dotenv()
|
||||
@@ -18,24 +40,8 @@ def dependency_storage_service() -> StorageService:
|
||||
if StorageType(os.environ["STORAGE_TYPE"]) == StorageType.S3_STORAGE:
|
||||
s3_config = get_config_s3()
|
||||
|
||||
if "aws_access_key_id" not in s3_config:
|
||||
raise RuntimeError("Invalid S3 Config: Missing aws_access_key_id")
|
||||
|
||||
if "aws_secret_access_key" not in s3_config:
|
||||
raise RuntimeError("Invalid S3 Config: Missing aws_secret_access_key")
|
||||
|
||||
if "region_name" not in s3_config:
|
||||
raise RuntimeError("Invalid S3 Config: Missing region_name")
|
||||
|
||||
s3_client = boto3.client(
|
||||
"s3",
|
||||
region_name=s3_config["region_name"],
|
||||
aws_access_key_id=s3_config["aws_access_key_id"],
|
||||
aws_secret_access_key=s3_config["aws_secret_access_key"],
|
||||
)
|
||||
|
||||
return AmazonS3Service(
|
||||
s3_client,
|
||||
build_client_s3(s3_config),
|
||||
s3_config["bucket_name"],
|
||||
)
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
from storage_service.config.config_virus_checker import (
|
||||
get_virus_checker_api_key,
|
||||
)
|
||||
from storage_service.service.virus_checker.virus_checker_none_service import (
|
||||
VirusCheckerNoneService,
|
||||
)
|
||||
from storage_service.service.virus_checker.virus_checker_service import (
|
||||
VirusCheckerService,
|
||||
)
|
||||
@@ -29,3 +32,5 @@ def dependency_virus_checker_service() -> VirusCheckerService:
|
||||
case VirusCheckerType.TOTAL_VIRUS:
|
||||
virus_checker = Virustotal(get_virus_checker_api_key())
|
||||
return VirusTotalService(virus_checker)
|
||||
case VirusCheckerType.NONE:
|
||||
return VirusCheckerNoneService()
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
from storage_service.service.virus_checker.virus_checker_service import (
|
||||
VirusCheckerService,
|
||||
)
|
||||
|
||||
from io import BytesIO
|
||||
|
||||
|
||||
class VirusCheckerNoneService(VirusCheckerService):
|
||||
def check_virus(self, file_data: BytesIO) -> bool:
|
||||
# No virus checker is used, so we assume the file is safe
|
||||
return True
|
||||
@@ -3,3 +3,4 @@ from enum import Enum
|
||||
|
||||
class VirusCheckerType(Enum):
|
||||
TOTAL_VIRUS = "total_virus"
|
||||
NONE = "none"
|
||||
|
||||
Reference in New Issue
Block a user