Skip to content

Commit 66b3aa3

Browse files
author
ajoino
authored
Merge pull request #21 from arrowhead-f/Development
Development
2 parents dc61232 + 649c46f commit 66b3aa3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+4288
-876
lines changed

.gitignore

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
*.vim
2+
start_insecure_coresystems.sh
3+
stop_coresystems.sh
4+
*.crt
5+
*.key
6+
*.p12
7+
docs/build/
8+
__pycache__/
9+
.mypy_cache/
10+
logs/
11+
build/
12+
dist/
13+
tags
14+
arrowhead_client.egg-info/
15+
.tox/
16+
.idea/
17+
venv*
18+
*/__pycache__/*
19+
.coverage
20+
htmlcov/*

_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
__lib_name__ = 'arrowhead-client'
2-
__version__ = '0.2.0a2'
2+
__version__ = '0.3.0a'
33
__author__ = 'Jacob Nilsson'
44
__email__ = '[email protected]'

arrowhead_client/abc.py

Lines changed: 49 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,61 @@
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
72

3+
from arrowhead_client.response import Response
4+
from arrowhead_client.rules import OrchestrationRule, RegistrationRule
85

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"""
1018
@abstractmethod
1119
def consume_service(
1220
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+
"""
1731

32+
33+
class BaseProvider(ProtocolMixin, ABC, protocol='<PROTOCOL>'):
34+
"""Abstract base class for providers"""
1835
@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.
2439
40+
Args:
41+
rule: Provision rule.
42+
"""
2543

26-
class BaseProvider(Protocol):
2744
@abstractmethod
28-
def add_provided_service(
45+
def run_forever(
2946
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.
3754
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+
"""

arrowhead_client/api.py

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,22 @@
22
Arrowhead Client API module
33
===========================
44
5-
This module contains the api of the :code:`arrowhead_client` module.
5+
This module contains the public api of the :code:`arrowhead_client` module.
66
"""
7-
from arrowhead_client.configuration import config
8-
from arrowhead_client.client import ArrowheadClient
7+
from typing import Dict
8+
from arrowhead_client.client import ArrowheadClient, provided_service
99
from arrowhead_client.system import ArrowheadSystem
10-
from arrowhead_client.httpconsumer import HttpConsumer
11-
from arrowhead_client.httpprovider import HttpProvider
10+
from arrowhead_client.implementations.httpconsumer import HttpConsumer
11+
from arrowhead_client.implementations.httpprovider import HttpProvider
1212
from arrowhead_client.service import Service # noqa: F401
1313
from arrowhead_client.logs import get_logger
1414

15-
from gevent import pywsgi # type: ignore
16-
1715

1816
class ArrowheadHttpClient(ArrowheadClient):
1917
"""
2018
Arrowhead client using HTTP.
2119
22-
Args:
20+
Attributes:
2321
system_name: A string to assign the system name
2422
address: A string to assign the system address
2523
port: An int to assign the system port
@@ -32,25 +30,24 @@ def __init__(self,
3230
system_name: str,
3331
address: str,
3432
port: int,
35-
authentication_info: str = '',
33+
config: Dict = None,
3634
keyfile: str = '',
37-
certfile: str = ''):
35+
certfile: str = '',
36+
cafile: str = ''):
3837
logger = get_logger(system_name, 'debug')
39-
wsgi_server = pywsgi.WSGIServer(
40-
(address, port),
41-
None,
42-
keyfile=keyfile,
43-
certfile=certfile,
44-
log=logger,
38+
system = ArrowheadSystem.with_certfile(
39+
system_name,
40+
address,
41+
port,
42+
certfile,
4543
)
4644
super().__init__(
47-
ArrowheadSystem(system_name, address, port, authentication_info),
48-
HttpConsumer(),
49-
HttpProvider(wsgi_server),
45+
system,
46+
HttpConsumer(keyfile, certfile, cafile),
47+
HttpProvider(cafile),
5048
logger,
51-
config,
49+
config=config,
5250
keyfile=keyfile,
5351
certfile=certfile
5452
)
5553
self._logger.info(f'{self.__class__.__name__} initialized at {self.system.address}:{self.system.port}')
56-
# TODO: This line is a hack and needs to be fixed

arrowhead_client/client/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
from .client_core import ArrowheadClient
1+
from .client_core import ArrowheadClient, provided_service
22

3-
__all__ = ['ArrowheadClient']
3+
__all__ = ['ArrowheadClient', 'provided_service']

0 commit comments

Comments
 (0)