Skip to content

Commit

Permalink
Merge pull request #29 from arrowhead-f/Development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
ajoino authored Apr 13, 2021
2 parents 2a02e4e + 78000c2 commit 6e133f0
Show file tree
Hide file tree
Showing 103 changed files with 2,850 additions and 1,077 deletions.
2 changes: 2 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[run]
source = ./arrowhead_client/
33 changes: 33 additions & 0 deletions .github/workflows/code_quality.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

name: Code quality check with flake8 and mypy

on:
push:
branches: [Development]
pull_request:
branches: [Development, master]

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python: [3.8]

steps:
- uses: actions/checkout@v2
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}
- name: Install flake8 and mypy
run:
pip install flake8 mypy -r requirements.txt
- name: Run flake8
run:
flake8 --ignore=E501,E126,E127 arrowhead_client/ examples/
- name: Run mypy
if: ${{ always() }}
run:
mypy arrowhead_client/
36 changes: 36 additions & 0 deletions .github/workflows/tox.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

name: Tox testing

on:
push:
branches: [Development]
pull_request:
branches: [Development, master]

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python: [3.7, 3.8, 3.9]

steps:
- uses: actions/checkout@v2
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}
- name: Install Tox and any other packages
run: |
python -m pip install --upgrade pip
pip install tox tox-gh-actions setuptools wheel
- name: Build library
run: |
python setup.py sdist bdist_wheel
pip install -e .
- name: Run Tox
# Run tox using the version of Python in `PATH`
run: tox
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
24 changes: 7 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,22 @@
# ARROWHEAD CLIENT PYTHON LIBRARY
This is a library for the creation of client service providers and consumer for the [Arrowhead Framework](www.arrowhead.eu), a service-oriented framework developed for industrial automation.
To read more about the library, please go to the [documentation](https://arrowhead-client-python-library.readthedocs.io/en/latest/).

## About
The Arrowhead Client Python Library is a library to make it easy to create your own Arrowhead Framework systems and services in Python.
This library provides classes that interface with the [Arrowhead Core Systems](https://github.com/arrowhead-f/core-java-spring), and uses Flask to provide services.
This library provides interfaces to connect Python with the [Arrowhead Core Systems](https://github.com/arrowhead-f/core-java-spring).

### Development status
This library has not yet reached a stable development version, and a lot will change.
Currently, it is working, but it's still missing many crucial features, such as:
- Error handling
- Logging
- Testing
- Support for the following core services
- Eventhandler
- Support for the TOKEN security modes (access policy):
This library is still in the Alpha stage of development, this means that the APIs haven't yet matured and may change at any time.

As more Arrowhead Core Systems mature and are added to the official docker container, those will be added to this list.
The library currently supports the http and websockets protocols for service consumption.

The library only provides interfaces for he mandatory core systems at the moment, but inferfaces for the other core systems is planned.

### External Depencies
To run an Arrowhead system you need to have the Arrowhead core systems up and running, and the correct certificates need to be provided.
A guide on how to create your own certificates can be found on the [Arrowhead github](https://github.com/arrowhead-f/core-java-spring/blob/master/documentation/certificates/create_client_certificate.pdf).

### Requirements
- Python 3.7 or higher
- Requests
- Flask
- Gevent

## How To Use
Install the library with `pip install arrowhead-client`.
See the [quickstart guide](https://arrowhead-client-python-library.readthedocs.io/en/latest/quickstart.html).

2 changes: 1 addition & 1 deletion _version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__lib_name__ = 'arrowhead-client'
__version__ = '0.3.0a'
__version__ = '0.4.2a'
__author__ = 'Jacob Nilsson'
__email__ = 'jacob.nilsson@ltu.se'
64 changes: 9 additions & 55 deletions arrowhead_client/abc.py
Original file line number Diff line number Diff line change
@@ -1,61 +1,15 @@
from abc import abstractmethod, ABC

from arrowhead_client.response import Response
from arrowhead_client.rules import OrchestrationRule, RegistrationRule
from abc import ABC


class ProtocolMixin(ABC):
def __init_subclass__(cls, protocol='', **kwargs):
if protocol == '':
raise ValueError('No protocol specified.')
elif not isinstance(protocol, str):
raise TypeError('Protocol must be of type str.')
cls._protocol = protocol.upper()


class BaseConsumer(ProtocolMixin, ABC, protocol='<PROTOCOL>'):
"""Abstract base class for consumers"""
@abstractmethod
def consume_service(
self,
rule: OrchestrationRule,
**kwargs) -> Response:
"""
Consume service according to the consumation rule and return the response.
Args:
rule: Orchestration rule.
Returns:
A Response object.
"""


class BaseProvider(ProtocolMixin, ABC, protocol='<PROTOCOL>'):
"""Abstract base class for providers"""
@abstractmethod
def add_provided_service(self, rule: RegistrationRule, ) -> None:
"""
Adds the provided service to the provider according the provision rule.
Args:
rule: Provision rule.
"""

@abstractmethod
def run_forever(
self,
address: str,
port: int,
keyfile: str,
certfile: str,
) -> None:
"""
Starts the provider and runs until interrupted.
Args:
address: system ip address.
port: system port.
keyfile: client keyfile.
certfile: client certfile.
cafile: certificate authority file
"""
elif isinstance(protocol, set):
if not all(isinstance(prot, str) for prot in protocol):
raise ValueError('All protocols specified must be of type str')
cls._protocol = set(prot.upper() for prot in protocol)
elif isinstance(protocol, str):
cls._protocol = {protocol.upper()}
else:
raise TypeError('protocol must be of type str or set')
53 changes: 0 additions & 53 deletions arrowhead_client/api.py

This file was deleted.

14 changes: 12 additions & 2 deletions arrowhead_client/client/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
from .client_core import ArrowheadClient, provided_service
"""
Client module
"""
from .client_core import provided_service, ArrowheadClient
from .client_async import ArrowheadClientAsync
from .implementations import AsyncClient

__all__ = ['ArrowheadClient', 'provided_service']
__all__ = [
'provided_service',
'ArrowheadClient',
'ArrowheadClientAsync',
'AsyncClient',
]
Loading

0 comments on commit 6e133f0

Please sign in to comment.