Merge pull request #13 from HideyoshiSolutions/updates-python

Runs Code Formater
This commit is contained in:
2024-04-02 02:46:45 -03:00
committed by GitHub
8 changed files with 31 additions and 26 deletions

View File

@@ -6,6 +6,4 @@ import os
def get_virus_checker_api_key(): def get_virus_checker_api_key():
load_dotenv() load_dotenv()
return { return {"api_key": os.environ.get("VIRUS_CHECKER_API_KEY")}
"api_key": os.environ.get("VIRUS_CHECKER_API_KEY")
}

View File

@@ -1,6 +1,6 @@
from storage_service.config.config_allowed_origins import get_allowed_origins from storage_service.config.config_allowed_origins import get_allowed_origins
from storage_service.controller.storage_controller import s3_router
from storage_service.controller.health_checker_controller import health_router from storage_service.controller.health_checker_controller import health_router
from storage_service.controller.storage_controller import s3_router
from fastapi import FastAPI from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware from fastapi.middleware.cors import CORSMiddleware

View File

@@ -1,9 +1,9 @@
from fastapi_utils.cbv import cbv from fastapi_utils.cbv import cbv
from fastapi_utils.inferring_router import InferringRouter from fastapi_utils.inferring_router import InferringRouter
health_router = InferringRouter() health_router = InferringRouter()
@cbv(health_router) @cbv(health_router)
class HealthCheckerController: class HealthCheckerController:
@health_router.get("/health", status_code=200) @health_router.get("/health", status_code=200)

View File

@@ -45,9 +45,7 @@ class StorageController:
@s3_router.delete("/file/", status_code=204) @s3_router.delete("/file/", status_code=204)
def delete_file(self, username: str, file_postfix: str): def delete_file(self, username: str, file_postfix: str):
return self.storage_service.delete_file( return self.storage_service.delete_file(file_name_hash(username, file_postfix))
file_name_hash(username, file_postfix)
)
@s3_router.post("/file/process", status_code=200) @s3_router.post("/file/process", status_code=200)
def process_file( def process_file(
@@ -56,5 +54,3 @@ class StorageController:
file_postfix: Annotated[str, Body(embed=True)], file_postfix: Annotated[str, Body(embed=True)],
): ):
self.queue.enqueue(storage_file_worker, username, file_postfix) self.queue.enqueue(storage_file_worker, username, file_postfix)

View File

@@ -1,13 +1,18 @@
import os from storage_service.config.config_virus_checker import (
from functools import cache get_virus_checker_api_key,
)
from storage_service.config.config_virus_checker import get_virus_checker_api_key from storage_service.service.virus_checker.virus_checker_service import (
from storage_service.service.virus_checker.virus_total_service import VirusTotalService VirusCheckerService,
from storage_service.service.virus_checker.virus_checker_service import VirusCheckerService )
from storage_service.service.virus_checker.virus_total_service import (
VirusTotalService,
)
from storage_service.utils.enums.virus_checker_type import VirusCheckerType
from dotenv import load_dotenv from dotenv import load_dotenv
from storage_service.utils.enums.virus_checker_type import VirusCheckerType import os
from functools import cache
@cache @cache

View File

@@ -1,6 +1,8 @@
from __future__ import annotations from __future__ import annotations
from storage_service.depends.depend_virus_checker_service import dependency_virus_checker_service from storage_service.depends.depend_virus_checker_service import (
dependency_virus_checker_service,
)
from storage_service.service.storage.storage_service import StorageService from storage_service.service.storage.storage_service import StorageService
from storage_service.utils.enums.file_type import FileType from storage_service.utils.enums.file_type import FileType
from storage_service.utils.file_handler import FILE_HANDLER from storage_service.utils.file_handler import FILE_HANDLER
@@ -12,7 +14,6 @@ from typing import Any
class AmazonS3Service(StorageService): class AmazonS3Service(StorageService):
virus_checker_service = dependency_virus_checker_service() virus_checker_service = dependency_virus_checker_service()
def __init__(self, **kwargs): def __init__(self, **kwargs):
@@ -33,7 +34,7 @@ class AmazonS3Service(StorageService):
) )
def get_temp_upload_link( def get_temp_upload_link(
self, file_name, file_type: FileType self, file_name, file_type: FileType
) -> dict[str, str | Any]: ) -> dict[str, str | Any]:
return { return {
"presigned_url": self._get_presigned_write_url(file_name, file_type), "presigned_url": self._get_presigned_write_url(file_name, file_type),
@@ -73,7 +74,9 @@ class AmazonS3Service(StorageService):
def _get_presigned_read_url(self, file_name) -> str | None: def _get_presigned_read_url(self, file_name) -> str | None:
result = self.s3.list_objects(Bucket=self.bucket_name, Prefix=file_name) result = self.s3.list_objects(Bucket=self.bucket_name, Prefix=file_name)
if "Contents" in result and file_name in map(lambda x: x["Key"], result["Contents"]): if "Contents" in result and file_name in map(
lambda x: x["Key"], result["Contents"]
):
return self.s3.generate_presigned_url( return self.s3.generate_presigned_url(
"get_object", "get_object",
Params={"Bucket": self.bucket_name, "Key": file_name}, Params={"Bucket": self.bucket_name, "Key": file_name},

View File

@@ -1,7 +1,10 @@
from io import BytesIO from storage_service.service.virus_checker.virus_checker_service import (
VirusCheckerService,
)
from virustotal_python import Virustotal from virustotal_python import Virustotal
from storage_service.service.virus_checker.virus_checker_service import VirusCheckerService from io import BytesIO
class VirusTotalService(VirusCheckerService): class VirusTotalService(VirusCheckerService):
@@ -26,10 +29,10 @@ class VirusTotalService(VirusCheckerService):
@staticmethod @staticmethod
def _is_valid_file(file_stats: dict) -> bool: def _is_valid_file(file_stats: dict) -> bool:
if 'malicious' in file_stats and file_stats['malicious'] > 0: if "malicious" in file_stats and file_stats["malicious"] > 0:
return False return False
if 'suspicious' in file_stats and file_stats['suspicious'] > 0: if "suspicious" in file_stats and file_stats["suspicious"] > 0:
return False return False
return True return True