Refactors Services and API Endpoints

This commit is contained in:
2024-05-20 22:36:42 -03:00
parent aeaa45bde6
commit 83f531c2d7
16 changed files with 172 additions and 120 deletions

View File

@@ -3,6 +3,8 @@ from storage_service.service.storage.amazon_s3_service import AmazonS3Service
from storage_service.service.storage.storage_service import StorageService
from storage_service.utils.enums.storage_type import StorageType
import boto3
import botocore.client
from dotenv import load_dotenv
import os
@@ -14,6 +16,27 @@ def dependency_storage_service() -> StorageService:
load_dotenv()
if StorageType(os.environ["STORAGE_TYPE"]) == StorageType.S3_STORAGE:
return AmazonS3Service(**get_config_s3())
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,
s3_config["bucket_name"],
)
raise RuntimeError("Invalid Storage Type")

View File

@@ -10,6 +10,7 @@ from storage_service.service.virus_checker.virus_total_service import (
from storage_service.utils.enums.virus_checker_type import VirusCheckerType
from dotenv import load_dotenv
from virustotal_python import Virustotal
import os
from functools import cache
@@ -19,13 +20,12 @@ from functools import cache
def dependency_virus_checker_service() -> VirusCheckerService:
load_dotenv()
virus_checker_config = get_virus_checker_api_key()
try:
type = VirusCheckerType(os.environ["VIRUS_CHECKER_TYPE"])
except ValueError:
raise RuntimeError("Invalid Virus Checker Type")
if not virus_checker_config["api_key"]:
raise RuntimeError("Virus Checker API Key not found")
virus_checker_type_var = os.environ.get("VIRUS_CHECKER_TYPE")
if VirusCheckerType(virus_checker_type_var) == VirusCheckerType.TOTAL_VIRUS:
return VirusTotalService(**get_virus_checker_api_key())
raise RuntimeError("Invalid Virus Checker Type")
match type:
case VirusCheckerType.TOTAL_VIRUS:
virus_checker = Virustotal(get_virus_checker_api_key())
return VirusTotalService(virus_checker)