Skip to content

Commit

Permalink
Feat/malware scanning (#120)
Browse files Browse the repository at this point in the history
* Introduce malware scanner base class

* Force malware scanner to be part of ingestor composition

* Rename property to make more sense in context

* Don't include abstract class in test coverage
  • Loading branch information
4c0n authored Jan 24, 2025
1 parent 51acb03 commit 4ae53db
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
8 changes: 7 additions & 1 deletion meldingen_core/image.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from abc import ABCMeta, abstractmethod # pragma: no cover
from typing import AsyncIterator, Generic, TypeVar

from meldingen_core.malware import BaseMalwareScanner
from meldingen_core.models import Attachment


Expand All @@ -17,6 +18,11 @@ async def __call__(self, image_path: str) -> str: ...
T = TypeVar("T", bound=Attachment)


class BaseIngestor(Generic[T], metaclass=ABCMeta):
class BaseIngestor(Generic[T], metaclass=ABCMeta): # pragma: no cover
_scan_for_malware: BaseMalwareScanner

def __init__(self, scanner: BaseMalwareScanner):
self._scan_for_malware = scanner

@abstractmethod
async def __call__(self, attachment: T, data: AsyncIterator[bytes]) -> None: ...
12 changes: 12 additions & 0 deletions meldingen_core/malware.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from abc import ABCMeta, abstractmethod


class MalwareException(Exception): ...


class MalwareFoundException(MalwareException): ...


class BaseMalwareScanner(metaclass=ABCMeta):
@abstractmethod
async def __call__(self, file_path: str) -> None: ...

0 comments on commit 4ae53db

Please sign in to comment.