Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions servc/svc/com/http/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class HTTPInterface(Middleware):

_consumer: Process

_components: List[type[Middleware]]
_components: List[Middleware]

_info: ServiceInformation

Expand All @@ -57,7 +57,7 @@ def __init__(
consumerthread: Process,
resolvers: RESOLVER_MAPPING,
eventResolvers: RESOLVER_MAPPING,
components: List[type[Middleware]],
components: List[Middleware],
):
super().__init__(config)
self._port = int(config.get("port"))
Expand Down
9 changes: 3 additions & 6 deletions servc/svc/com/http/blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from servc.svc.config import Config
from servc.svc.io.output import ResponseArtifact, StatusCode
from servc.svc.io.response import getErrorArtifact
from servc.util import findType


def returnError(message: str, error: StatusCode = StatusCode.METHOD_NOT_FOUND):
Expand All @@ -35,17 +36,13 @@ def __init__(
consumerthread: Process,
resolvers: RESOLVER_MAPPING,
eventResolvers: RESOLVER_MAPPING,
components: List[type[Middleware]],
components: List[Middleware],
):
super().__init__(
config, bus, cache, consumerthread, resolvers, eventResolvers, components
)

blobs = [x for x in components if x.name == "blob"]
if len(blobs) == 0:
raise Exception("Blob storage component not found in components list")
self._blobStorage = blobs[0] # type: ignore[assignment]

self._blobStorage = findType(components, BlobStorage)
self._uploadcontainer = config.get("uploadcontainer") or "uploads"

def get_upload_file_path(self, extra_params: Dict, fname: str) -> Tuple[str, str]:
Expand Down
12 changes: 12 additions & 0 deletions servc/util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from typing import List, TypeVar

from servc.svc import Middleware

T = TypeVar("T", bound=Middleware)


def findType(c: List[Middleware], type: type[T]) -> T:
cf = [x for x in c if isinstance(x, type)]
if len(cf) == 0:
raise ValueError(f"Middleware {type} not found")
return cf[0]