feat: implements a better kubernetes deployment setup
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
from storage_service.config.config_allowed_origins import get_allowed_origins
|
||||
from storage_service.controller import health_router, storage_router
|
||||
from storage_service.utils.exception_handler import (
|
||||
http_exception_handler,
|
||||
@@ -7,7 +6,6 @@ from storage_service.utils.exception_handler import (
|
||||
|
||||
from fastapi import FastAPI, HTTPException
|
||||
from fastapi.exceptions import RequestValidationError
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
@@ -15,14 +13,5 @@ app = FastAPI()
|
||||
app.add_exception_handler(HTTPException, http_exception_handler)
|
||||
app.add_exception_handler(RequestValidationError, validation_exception_handler)
|
||||
|
||||
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=get_allowed_origins(),
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
app.include_router(storage_router)
|
||||
app.include_router(health_router)
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
from dotenv import load_dotenv
|
||||
|
||||
import os
|
||||
|
||||
|
||||
def get_allowed_origins():
|
||||
load_dotenv()
|
||||
|
||||
origins = os.environ.get("ALLOWED_ORIGINS", None)
|
||||
|
||||
if origins is None:
|
||||
return []
|
||||
|
||||
return origins.split(",")
|
||||
@@ -1,5 +1,3 @@
|
||||
from storage_service.utils.enums.storage_type import StorageType
|
||||
|
||||
from dotenv import load_dotenv
|
||||
|
||||
import os
|
||||
@@ -14,5 +12,5 @@ def get_config_s3():
|
||||
"aws_secret_access_key": os.environ.get("AWS_SECRET_ACCESS_KEY", None),
|
||||
"region_name": os.environ.get("AWS_REGION_NAME", None),
|
||||
"bucket_name": os.environ.get("AWS_BUCKET_NAME", None),
|
||||
"expires_in": os.environ.get("EXPIRES_IN", 3600),
|
||||
"expires_in": os.environ.get("EXPIRES_IN", "3600"),
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ from storage_service.utils.exceptions.file_not_found_exception import (
|
||||
from storage_service.utils.file.file_hash_generator import generate_file_hash
|
||||
from storage_service.worker.storage_file_worker import storage_file_worker
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from fastapi import APIRouter, Depends
|
||||
from fastapi_utils.cbv import cbv
|
||||
from rq import Queue
|
||||
|
||||
|
||||
@@ -37,12 +37,15 @@ def build_client_s3(config: dict) -> botocore.client.BaseClient:
|
||||
def dependency_storage_service() -> StorageService:
|
||||
load_dotenv()
|
||||
|
||||
if StorageType(os.environ["STORAGE_TYPE"]) == StorageType.S3_STORAGE:
|
||||
s3_config = get_config_s3()
|
||||
storage_type = StorageType(os.environ.get("STORAGE_TYPE", "s3"))
|
||||
|
||||
return AmazonS3Service(
|
||||
build_client_s3(s3_config),
|
||||
s3_config["bucket_name"],
|
||||
)
|
||||
match storage_type:
|
||||
case StorageType.S3_STORAGE:
|
||||
s3_config = get_config_s3()
|
||||
|
||||
raise RuntimeError("Invalid Storage Type")
|
||||
return AmazonS3Service(
|
||||
build_client_s3(s3_config),
|
||||
s3_config["bucket_name"],
|
||||
)
|
||||
case _:
|
||||
raise RuntimeError("Invalid Storage Type")
|
||||
|
||||
@@ -23,12 +23,9 @@ from functools import cache
|
||||
def dependency_virus_checker_service() -> VirusCheckerService:
|
||||
load_dotenv()
|
||||
|
||||
try:
|
||||
type = VirusCheckerType(os.environ["VIRUS_CHECKER_TYPE"])
|
||||
except ValueError:
|
||||
raise RuntimeError("Invalid Virus Checker Type")
|
||||
checker_type = VirusCheckerType(os.environ.get("VIRUS_CHECKER_TYPE", "total_virus"))
|
||||
|
||||
match type:
|
||||
match checker_type:
|
||||
case VirusCheckerType.TOTAL_VIRUS:
|
||||
virus_checker = Virustotal(get_virus_checker_api_key())
|
||||
return VirusTotalService(virus_checker)
|
||||
|
||||
Reference in New Issue
Block a user