|
1 | | -from abc import abstractmethod, ABC |
2 | | - |
3 | | -from arrowhead_client.response import Response |
4 | | -from arrowhead_client.rules import OrchestrationRule, RegistrationRule |
| 1 | +from abc import ABC |
5 | 2 |
|
6 | 3 |
|
7 | 4 | class ProtocolMixin(ABC): |
8 | 5 | def __init_subclass__(cls, protocol='', **kwargs): |
9 | 6 | if protocol == '': |
10 | 7 | 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""" |
18 | | - @abstractmethod |
19 | | - def consume_service( |
20 | | - self, |
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 | | - """ |
31 | | - |
32 | | - |
33 | | -class BaseProvider(ProtocolMixin, ABC, protocol='<PROTOCOL>'): |
34 | | - """Abstract base class for providers""" |
35 | | - @abstractmethod |
36 | | - def add_provided_service(self, rule: RegistrationRule, ) -> None: |
37 | | - """ |
38 | | - Adds the provided service to the provider according the provision rule. |
39 | | -
|
40 | | - Args: |
41 | | - rule: Provision rule. |
42 | | - """ |
43 | | - |
44 | | - @abstractmethod |
45 | | - def run_forever( |
46 | | - self, |
47 | | - address: str, |
48 | | - port: int, |
49 | | - keyfile: str, |
50 | | - certfile: str, |
51 | | - ) -> None: |
52 | | - """ |
53 | | - Starts the provider and runs until interrupted. |
54 | | -
|
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 | | - """ |
| 8 | + elif isinstance(protocol, set): |
| 9 | + if not all(isinstance(prot, str) for prot in protocol): |
| 10 | + raise ValueError('All protocols specified must be of type str') |
| 11 | + cls._protocol = set(prot.upper() for prot in protocol) |
| 12 | + elif isinstance(protocol, str): |
| 13 | + cls._protocol = {protocol.upper()} |
| 14 | + else: |
| 15 | + raise TypeError('protocol must be of type str or set') |
0 commit comments