|
1 | | -from abc import abstractmethod |
2 | | -from typing import Any, Callable |
3 | | -try: |
4 | | - from typing import Protocol |
5 | | -except ImportError: |
6 | | - from typing_extensions import Protocol # type: ignore |
| 1 | +from abc import abstractmethod, ABC |
7 | 2 |
|
| 3 | +from arrowhead_client.response import Response |
| 4 | +from arrowhead_client.rules import OrchestrationRule, RegistrationRule |
8 | 5 |
|
9 | | -class BaseConsumer(Protocol): |
| 6 | + |
| 7 | +class ProtocolMixin(ABC): |
| 8 | + def __init_subclass__(cls, protocol='', **kwargs): |
| 9 | + if protocol == '': |
| 10 | + raise ValueError('No protocol specified.') |
| 11 | + elif not isinstance(protocol, str): |
| 12 | + raise TypeError('Protocol must be of type str.') |
| 13 | + cls._protocol = protocol.upper() |
| 14 | + |
| 15 | + |
| 16 | +class BaseConsumer(ProtocolMixin, ABC, protocol='<PROTOCOL>'): |
| 17 | + """Abstract base class for consumers""" |
10 | 18 | @abstractmethod |
11 | 19 | def consume_service( |
12 | 20 | self, |
13 | | - service_uri: str, |
14 | | - method: str, |
15 | | - **kwargs) -> Any: # type: ignore |
16 | | - raise NotImplementedError |
| 21 | + rule: OrchestrationRule, |
| 22 | + **kwargs) -> Response: |
| 23 | + """ |
| 24 | + Consume service according to the consumation rule and return the response. |
| 25 | +
|
| 26 | + Args: |
| 27 | + rule: Orchestration rule. |
| 28 | + Returns: |
| 29 | + A Response object. |
| 30 | + """ |
17 | 31 |
|
| 32 | + |
| 33 | +class BaseProvider(ProtocolMixin, ABC, protocol='<PROTOCOL>'): |
| 34 | + """Abstract base class for providers""" |
18 | 35 | @abstractmethod |
19 | | - def extract_payload( |
20 | | - self, |
21 | | - service_response: Any, |
22 | | - payload_type: str): |
23 | | - raise NotImplementedError |
| 36 | + def add_provided_service(self, rule: RegistrationRule, ) -> None: |
| 37 | + """ |
| 38 | + Adds the provided service to the provider according the provision rule. |
24 | 39 |
|
| 40 | + Args: |
| 41 | + rule: Provision rule. |
| 42 | + """ |
25 | 43 |
|
26 | | -class BaseProvider(Protocol): |
27 | 44 | @abstractmethod |
28 | | - def add_provided_service( |
| 45 | + def run_forever( |
29 | 46 | self, |
30 | | - service_definition: str, |
31 | | - service_uri: str, |
32 | | - method: str, |
33 | | - func: Callable, |
34 | | - *func_args, |
35 | | - **func_kwargs, ) -> None: |
36 | | - pass |
| 47 | + address: str, |
| 48 | + port: int, |
| 49 | + keyfile: str, |
| 50 | + certfile: str, |
| 51 | + ) -> None: |
| 52 | + """ |
| 53 | + Starts the provider and runs until interrupted. |
37 | 54 |
|
38 | | - @abstractmethod |
39 | | - def run_forever(self) -> None: |
40 | | - pass |
| 55 | + Args: |
| 56 | + address: system ip address. |
| 57 | + port: system port. |
| 58 | + keyfile: client keyfile. |
| 59 | + certfile: client certfile. |
| 60 | + cafile: certificate authority file |
| 61 | + """ |
0 commit comments