-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from arrowhead-f/Development
Development
- Loading branch information
Showing
40 changed files
with
1,106 additions
and
583 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
__lib_name__ = 'arrowhead-client' | ||
__version__ = '0.2.0a2' | ||
__author__ = 'Jacob Nilsson' | ||
__email__ = 'jacob.nilsson@ltu.se' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from abc import abstractmethod | ||
from typing import Any, Callable | ||
try: | ||
from typing import Protocol | ||
except ImportError: | ||
from typing_extensions import Protocol # type: ignore | ||
|
||
|
||
class BaseConsumer(Protocol): | ||
@abstractmethod | ||
def consume_service( | ||
self, | ||
service_uri: str, | ||
method: str, | ||
**kwargs) -> Any: # type: ignore | ||
raise NotImplementedError | ||
|
||
@abstractmethod | ||
def extract_payload( | ||
self, | ||
service_response: Any, | ||
payload_type: str): | ||
raise NotImplementedError | ||
|
||
|
||
class BaseProvider(Protocol): | ||
@abstractmethod | ||
def add_provided_service( | ||
self, | ||
service_definition: str, | ||
service_uri: str, | ||
method: str, | ||
func: Callable, | ||
*func_args, | ||
**func_kwargs, ) -> None: | ||
pass | ||
|
||
@abstractmethod | ||
def run_forever(self) -> None: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,56 @@ | ||
""" | ||
Arrowhead Client API module | ||
=========================== | ||
This module contains the api of the :code:`arrowhead_client` module. | ||
""" | ||
from arrowhead_client.configuration import config | ||
from arrowhead_client.application import ArrowheadApplication | ||
from arrowhead_client.client import ArrowheadClient | ||
from arrowhead_client.system import ArrowheadSystem | ||
from arrowhead_client.consumer import Consumer | ||
from arrowhead_client.provider import Provider | ||
from arrowhead_client.httpconsumer import HttpConsumer | ||
from arrowhead_client.httpprovider import HttpProvider | ||
from arrowhead_client.service import Service # noqa: F401 | ||
from arrowhead_client.logs import get_logger | ||
|
||
from gevent import pywsgi # type: ignore | ||
|
||
|
||
class ArrowheadHttpClient(ArrowheadClient): | ||
""" | ||
Arrowhead client using HTTP. | ||
Args: | ||
system_name: A string to assign the system name | ||
address: A string to assign the system address | ||
port: An int to assign the system port | ||
authentication_info: A string to assign the system authentication info | ||
keyfile: A string to assign the PEM keyfile | ||
certfile: A string to assign the PEM certfile | ||
""" | ||
|
||
class ArrowheadHttpApplication(ArrowheadApplication): | ||
def __init__(self, | ||
system_name: str, | ||
address: str, | ||
port: int, | ||
authentication_info: str = '', | ||
keyfile: str = '', | ||
certfile: str = ''): | ||
logger = get_logger(system_name, 'debug') | ||
wsgi_server = pywsgi.WSGIServer( | ||
(address, port), | ||
None, | ||
keyfile=keyfile, | ||
certfile=certfile, | ||
log=logger, | ||
) | ||
super().__init__( | ||
ArrowheadSystem(system_name, address, port, authentication_info), | ||
Consumer(keyfile, certfile), | ||
Provider(), | ||
get_logger(system_name, 'debug'), | ||
HttpConsumer(), | ||
HttpProvider(wsgi_server), | ||
logger, | ||
config, | ||
keyfile=keyfile, | ||
certfile=certfile | ||
) | ||
self._logger.info(f'{self.__class__.__name__} initialized at {self.system.address}:{self.system.port}') | ||
#TODO: This line is a hack and needs to be fixed | ||
# TODO: This line is a hack and needs to be fixed |
Oops, something went wrong.