Skip to content

Commit

Permalink
[LD-19] restructure Python SDK (#32)
Browse files Browse the repository at this point in the history
* [WiP] first changes to restructure the SDK

* The currently written tests work properly

* Necessary changes made according to the comments

* Changes made to the constants.py, since the tests were ran again, recipient.json is also changed

* Changes made to the constants.py, since the tests were ran again, recipient.json is also changed

* Onboarding Responses for MQTT

* Changed made to the code according to the comments. Identifer class added , test script changed

* Add exception during onboarding

* fix merging mistakes

* Added some comments.
Format the file.
Rename the "WrongGateWay" to "WrongGateWayType" to match the related exception.

* Changes made to Identifier and test script

Changes made to the test script since Identifier class was changed. The tests were ran again to check if everything works, hence the registration codes are changed. Under MQTT there are 2 folders P12 and PEM, each containing a Sender and a Recipient.

* Adapt comments.

* Add comments.
Fix code smells.

* Add comments.
Fix code smells.

* Change folders.

* mqtt capabilities service test with one technical message type

* updated the onboard response

The previously created onboard response is used

* SequenceNumberService Class added and test cleaned up according to the comments

* Add new type for direction.
Add comments.
Rename type.

* Remove typos.
Add comments.
Refactoring to avoid literals.

* Added tests with SEND and RECEIVE directions

* Docstrings should be defined outside the dict

The docstrings defined in the dictionary. It should be defined outside.

* SequenceNumberService class improved

SequenceNumberService Class improved

test_capability_service improved by making the methods static and adding the tests with SEND and RECEIVE directions

* Format files.

* remove typos.

* Update test names.

* Use existing sleeper methods.
Refactor constant names.
Adapt comments.

* PEP-8 | Constants should be uppercase

* Added Subscription Service Tests (#40)

* Added Subscription Service Tests

* Add comments.

* Necessary Changes made to the test script

1. Subscription Service Tests shifted to another folder
2. Name of the test function changed
3. Removed the redundant load_onboard_response() staticmethod.

---------

Co-authored-by: Sascha Doemer <[email protected]>

* SendMessageService and SendMessageParameters added (#41)

* SendMessageService and SendMessageParameters written

* Added a test script to send message along with DataProvider Class.

* Sending direct message with push notifications turned on

Test code refactored compared to previous commits

* Fix format.

* Fix format.

* Fix format.

* Fix format.

* Push Notification decoded

* Fix format.

* Add missing comments.

* Add missing comments.

* Fix format.

* Remove unused methods.
Add comments.
Move static method.

* Move function.
Adapt calls.

---------

Co-authored-by: Sascha Doemer <[email protected]>

* Test for QueryHeaderService (#42)

* Test for QueryHeaderService

* 3 tests for QueryheaderService with different attributes

* Test for incomplete attributes passed to the QueryHeaderParameters should return 400

* Few more tests added and the clean setup is done and messages within the feed are now deleted using FeedDeleteService

* Fix format.

* Update test structure.
Add fixture to create sender and recipient.
Fix typo in `GateWays`.

* Update application ID.
Update certification version ID.

* Setup between the Sender and Recipient. Query Header Service tests with different scenarios

* Fix naming.
Fix variable names.
Fix typos.

* Add common package for onboarding.
Adapt test structure.
Add missing response checking for onboarding.
Add missing requirement in `requirements.txt`.
Fix method calls.

* Adapt method name.

* Fix comment length.

* Fix naming.

* Decrease time interval.

* Adapt naming.

* Remove unused parameters.

* Remove useless waiting since the response is already there.

* Remove unused parameters.

* Remove useless waiting.

* Optimize imports.

* Optimize imports.

* Move data to the data package.

* Add missing comments.

* Remove unused data.

* Fix identifiers.
Remove unused functions and data.
Remove unused parameters.

* Optimize imports.

* Adapt waiting intervall.

* Remove unused parameters.

* Remove useless waiting time.

* Remove typo.

* Remove typo.

* Fix compile error.

* Adapt test cases to check if the callback is called.

* Use default interval.

* Adapt test to use the right framework.

* Adapt test structure.
Update recipient.
Adapt test intervall.
Adapt naming.

* Replace if with an assertion.

* Adapt reading of onboard responses.

* Adapt test case to run with the correct framework.

* Adapt sleep time.
Adapt callbacks.

* Remove messages after successful testing.

* Update log messages.

* Add comment.

* Feed Delete Service callback

* Fix coding error.

* Adapt wait time.

* Update reference.

* Update PEM recipient.

* Update ´skip` option.

* Test Structure fixed for subscription tests

* Disconnect client, before reconnecting it.

* Disconnect client, before performing tear down.

* Disconnect client, before performing tear down.

* Adapt logging.

* Fix test case structure.

* Update test fixture.
Fix test structure.

* Remove unused folder.

* Move common classes to dedicated package.

* Code bugfix in delete_all_messages_within_the_feed

* FeedDeleteService callback assertions fix

* Fix callback name

* Revert changes.

* Remove validity period.

* Adapt implementation.

* QueryHeaderService Tests code refactored

* Validity Period bugfix

* Remove test function usage in official SDK outside of tests.
Adapt implementation regarding DRY.

* No setup outside the test case or the fixture to ensure failing test cases.

* Reformat file.

* Variable names updated

* Adapt implementation.

* Fixture messaging services and callback bugfix

* bugfix in test for valid validity period

* Addtional logging.

---------

Co-authored-by: Sascha Doemer <[email protected]>

* Test for sending chunked messages (#43)

* Test for QueryHeaderService

* 3 tests for QueryheaderService with different attributes

* Test for incomplete attributes passed to the QueryHeaderParameters should return 400

* Few more tests added and the clean setup is done and messages within the feed are now deleted using FeedDeleteService

* Fix format.

* Update test structure.
Add fixture to create sender and recipient.
Fix typo in `GateWays`.

* Update application ID.
Update certification version ID.

* Setup between the Sender and Recipient. Query Header Service tests with different scenarios

* Test for sending chunked messages

* Fix naming.
Fix variable names.
Fix typos.

* Add common package for onboarding.
Adapt test structure.
Add missing response checking for onboarding.
Add missing requirement in `requirements.txt`.
Fix method calls.

* Adapt method name.

* Fix comment length.

* Fix naming.

* Decrease time interval.

* Adapt naming.

* Remove unused parameters.

* Remove useless waiting since the response is already there.

* Remove unused parameters.

* Remove useless waiting.

* Optimize imports.

* Optimize imports.

* Move data to the data package.

* Add missing comments.

* Remove unused data.

* Fix identifiers.
Remove unused functions and data.
Remove unused parameters.

* Optimize imports.

* Adapt waiting intervall.

* Remove unused parameters.

* Remove useless waiting time.

* Remove typo.

* Remove typo.

* Fix compile error.

* Adapt test cases to check if the callback is called.

* Use default interval.

* Adapt test to use the right framework.

* Adapt test structure.
Update recipient.
Adapt test intervall.
Adapt naming.

* Replace if with an assertion.

* Adapt reading of onboard responses.

* Adapt test case to run with the correct framework.

* Adapt sleep time.
Adapt callbacks.

* Remove messages after successful testing.

* Update log messages.

* Add comment.

* Feed Delete Service callback

* Fix coding error.

* Adapt wait time.

* Update reference.

* Update PEM recipient.

* Update ´skip` option.

* Test Structure fixed for subscription tests

* Disconnect client, before reconnecting it.

* Disconnect client, before performing tear down.

* Disconnect client, before performing tear down.

* Adapt logging.

* Fix test case structure.

* Update test fixture.
Fix test structure.

* Remove unused folder.

* Move common classes to dedicated package.

* Code bugfix in delete_all_messages_within_the_feed

* FeedDeleteService callback assertions fix

* Fix callback name

* Revert changes.

* Remove validity period.

* Adapt implementation.

* QueryHeaderService Tests code refactored

* Validity Period bugfix

* Remove test function usage in official SDK outside of tests.
Adapt implementation regarding DRY.

* No setup outside the test case or the fixture to ensure failing test cases.

* Reformat file.

* Variable names updated

* Adapt implementation.

* Adapted test structure for chunked message service test

* Test for receiving chunked messages using Query Header Sevice, i.e. within the feed of an endpoint

* Adapt test structure and improve coding style

* Change the name of the test script for better readability

* Adapt code structure for maximum length for raw message content required for chunking

* Fixture messaging services and callback bugfix

* Move messaging services from fixture to test method codefix

* Fix naming for the recipient_callback

* Fix sender callback naming convention

* Remove unnecessary class variables and callback bugfix

* Remove unnecessary class variables and update flag in recipient callback

* Update sender callback to non checking callback

* Update the name of the recipient callback

* bugfix in test for valid validity period

* Additional logging

* Restructure code.
Remove constant from external class.

* Adapt wait time to send messages.

* Add assertion for number of chunks

* Return raw data for large contents that need chunking

* Update doc strings

* Reformat code.

* Removed redundant test files and fixed newline error

Deleted unnecessary test files, 'test_onboard_response_integration_service.py' and 'test_update_onboard_responses.py', to improve the simplicity and readability of the project. Also fixed the absence of a newline issue at the end of file in 'identifier.py' to adhere to code style guidelines.

---------

Co-authored-by: Sascha Doemer <[email protected]>

* Feature/update onboarding responses (#44)

* Update communication unit and capabilities for HTTP, add tests

Updated communication unit identifiers to use HTTP and encryption type to use `PEM`. Renamed sensor types in messaging enums for clarity and added test cases for HTTP recipient update. Changes are to aid development and testing. The reason for the change from P12 to PEM in communication unit is currently not specified. More information might be required here.

* Remove redundant test data and update onboard tests

The redundant test data, 'Recipient.json' and 'Sender.json' under 'CommunicationUnit', were removed and the onboard tests were updated accordingly. It improves manageability by eliminating unnecessary test resources. The replaced 'test_update_http_cu_recipient' and 'test_update_http_cu_sender' methods update onboarding with a specific device id and save the onboard response. Lastly, added 'Recipient.json' under 'PEM' in 'CommunicationUnit' containing new authentication data - useful for upcoming tests.

* Remove outdated test fixtures and update onboarding

This commit removes outdated test fixtures related to message sending and recipient in MQTT protocol. These were too specific and had hardcoded QA environments and registration codes.

In its place, the 'onboard_response_update.py' is renamed to 'update_http_onboard_responses.py' and updated to use function 'onboard_communication_unit'. This is to align with the practice of using widely generic onboarding function which will provide more flexibility for testing.

Importantly, the new testing functions are currently marked to be skipped unless the registration code is changed. This is to avoid breaking the tests with invalid registration codes. It should be updated with valid codes when used.

* Update PEM certificate and secret for MQTT messages sender and recipient

PEM certificates and secrets for both the MQTT messages sender and recipient have been updated to accommodate new secure communication requirements. This change is mirrored in the corresponding test fixtures used to simulate the onboarding response during testing. The original hard-coded registration codes have also been updated to simulate the new onboarding process.

* Remove setup.py and update dependencies

Setup.py was removed as it's unnecessary in the project. Dependencies in requirements.txt were updated to more recent versions (setuptools to v68.2.2, certifi to v2023.7.22, and requests to v2.31.0), supporting better performance and security. Some installation instructions from README.adoc were also deleted as they were related to setup.py.

* Refactor README.adoc and enhance unit tests

Refactored README.adoc for better readability and included detailed instructions for Python environment setup. Enhanced unit tests in test_query_header_service.py to ensure message receipt. These changes improve documentation clarity for easier project setup and ensure robustness of unit tests.

* Add MQTT message publish tests

Added unit test scenarios for MQTT message publishing service. The new tests include message publishing, message receipt, and clear up processes ensuring successful message sending and receiving. These were added to increase code coverage and improve robustness of MQTT service.

* Improve MQTT messaging testing

A new test suite has been added to cover MQTT messaging services. This includes tests for sending and receiving messages and cleaning up received messages. The addition is aimed to increase code coverage and ensure the robustness and reliability of the MQTT messaging service.

* Improve MQTT messaging testing

A new test suite has been added to cover MQTT messaging services. This includes tests for sending and receiving messages and cleaning up received messages. The addition is aimed to increase code coverage and ensure the robustness and reliability of the MQTT messaging service.

* Add tests for FeedDeleteService in MQTT messaging

Added a new file 'test_feed_delete_service.py'. This new test file contains unittests verifying the deletion of messages in MQTT messaging system. Test cases covered include: deletion of messages from a specified sender id, deletion of a specified message, deletion of messages within a specified timeframe, and handling deletion commands with incorrect/incomplete parameters. The new tests will help ensure the effectiveness and accuracy of the FeedDeleteService module in the MQTT messaging application.

* Add tests for QueryMessageService in MQTT messaging

The new file 'test_query_message_service.py' contains unit tests for the MQTT messaging system. The tests include: message querying with specified sender id, message id, validity period, and handling edge cases with incorrect parameters. This helps verify the robustness and accuracy of QueryMessageService module ensuring that it correctly fetches messages meeting the specified criteria.

* Updated requirements and project config

* Update Python versions in Github actions

A new Python version, "3.11", was added to the testing matrix in the GitHub Actions workflow configuration. This ensures that the package is tested across the newly released version, maintaining extensive compatibility.

* Remove Python 3.6 from testing matrix

Python 3.6 has been removed from the testing matrix in the GitHub Actions workflow configuration. This is due to Python 3.6 reaching end-of-life status and is no longer supported. As a result, it isn't necessary to test on this version.

* Downgrade setuptools to version 68.0.0

The setuptools package version was downgraded from 68.2.2 to 68.0.0 in the requirements.txt file. This was necessary because version 68.2.2 is not compatible with Python 3.6 which has now been removed from our testing matrix due to its end-of-life status.

* Update GitHub actions version

The versions of actions/checkout and actions/setup-python GitHub actions used in the workflow file (python-package.yml) have been updated. This change was necessary to ensure compatibility with the latest features and improvements provided by these action versions.

* Refactor multiple lines of code for cleaner syntax and better code readability

The changes in this commit opt for more concise syntax and improves code readability by improving the formatting of the code lines. Overly long lines were split into multiple lines for easier viewing. Some superfluous details in the text strings were also removed. Some variable names were changed for better context. Additionally, indentation has been improved for better visual hierarchy of the code structure.

* Update workflow configuration to use 'run' instead of 'uses'

This commit replaces the 'uses' command in the Python-Package GitHub workflow with 'run'. This change aligns with the official syntax for executing commands during a GitHub Actions workflow while maintaining the same functionality. Normally, 'uses' is used to reference action repositories, but 'run' is more appropriate for executing scripts, enhancing clarity and readability in the workflow file.

* Restrict parallel jobs in GitHub workflow

This commit adds 'max-parallel: 1' to the action strategy matrix in the Python-Package GitHub workflow. This change ensures that jobs in the workflow run sequentially instead of concurrently, preventing potential race conditions and conflicts in the testing environment. This helps to maintain the integrity of our test results and also keeps resource usage in check.

* Update python-package.yml to ensure sequential workflow jobs

The commit moves the 'max-parallel: 1' configuration from the matrix to the strategy. This change ensures jobs do not run in parallel causing potential race conditions during testing. The tests are now forced to run sequentially improving the reliability of our results and resource usage efficiency.

* Remove unused import in type_url.py

This commit removes the unused import statement "PushNotification" from the type_url.py file. This contributes towards keeping the codebase clean and efficient, while also focusing on reducing unnecessary dependencies in the agrirouter software development kit code.

* Correct comment spacing in headers.py file

This commit corrects the comment spacing in the headers.py file of the agrirouter onboarding package. By maintaining consistent formatting standards, we improve the readability and overall quality of our application's source code.

* Refactor comment formatting in agrirouter/onboarding files

The commit adjusts spaces in commented code within two agrirouter/onboarding files, improving and maintaining code readability. The changes help promote consistent coding style across the application source code.

* Fix typo in agrirouter/messaging/parameters/service.py

This commit corrects a misspelling in the BaseOnboardingResponse parameter and enhances code readability by fixing the whitespaces. These changes result in better, consistent coding style and runtime stability.

* Refactor and fix typo in agrirouter messaging service

This commit corrects a typo in the technical message type of CapabilityType and refines the import order and whitespace for better readability. This change improves code consistency, contributing to better stability and implementation.

* Remove unnecessary line in agrirouter signature file

This commit simplifies the agrirouter onboarding signature.py file by eliminating an unnecessary line. This minor change contributes to overall code cleanliness and readability.

* Uncommented import line in agrirouter/revoking/request.py

The import line for creating a signature in the agrirouter revoking request file was uncommented. This change improves script efficiency and eliminates redundancy in the codebase.

* Correct comparison operation in response.py

The incorrect comparison operation, comparing "http_response" with "None" using "!=" is modified to the correct operation "is not None" in agrirouter/onboarding/response.py. This change follows the correct Pythonic way to compare something to None and makes the code cleaner.

* Refactor auth response verification code

Refactored the currently commented-out signature verification code in agrirouter/auth/response.py. It has been formatted and repositioned within the class for better readability. This refactoring does not introduce any functionality changes but prepares for potential future use.

* Remove AR_PROD_PUBLIC_KEY import

Removed the import of AR_PROD_PUBLIC_KEY in the environments.py file. Although there has been no change in functionality, this clean-up step is necessary to maintain readable and concise code, removing potentially unnecessary import.

* Refactor NONE comparison in encode method

Modified the 'None' comparisons in the encode method of the Messaging service in the Agrirouter project. Instead of using '!= None', the more Pythonic 'is not None' is used. This change contributes to maintaining a consistent and idiomatic style across the codebase.

* Remove return type hint in parameters.py

The return type hint (`object`) is removed from the constructor of a class in the file parameters.py in the Agrirouter onboarding module. This is done to enhance readability and for maintaining consistency, as the function does not have a return statement and thus does not return anything.

* Commit message:
Remove unnecessary import in request.py

A commented out import statement (importing create_signature, verify_signature from signature) has been removed from request.py file in the Agrirouter onboarding module. It was unnecessary and not being used in the file, hence it's removed to maintain clean and clutter-free code.

* Remove unused commented import in revoking.py

An unused and commented out import: 'RequestNotSigned' from agrirouter.onboarding.exceptions has been removed in revoking.py. This change is made to ensure clarity and to avoid any confusion from lingering unused code in the project.

* Correct typo in service.py

The class name 'BaseOnboardingResonse' has been corrected to 'BaseOnboardingResponse' in two places within the service.py file. This minor typographical error was resolved to ensure that the code implementation aligns with the intended design.

* Enable request signing in revoking.py

The code block in the _perform_request function that handles request signing has been uncommented. This ensures that every request must be signed using the private key before it is sent, and raises an exception if a request is not signed, increasing the security of the revoking process.

* Enable request signing in revoking.py

The uncommented code block now enables request signing functionality in _perform_request function. Consequently, each request must now be signed using a private key before it is sent, thereby enhancing the security of the revoking process through enforcement of signed requests.

* Add SendChunkedMessageService to imported services

SendChunkedMessageService was added to the imported services in agrirouter/__init__.py. This makes it possible for messages to be sent in chunks, which could be useful for handling larger data transfers more efficiently.

* "Activate public and private key in onboarding service"

A commented code has been uncommented in the onboarding.py file to activate usage of public and private keys in the SecuredOnboardingService class. Simultaneously, an unnecessary import was also removed, ensuring optimised resource handling.

* Refactor and enhance the onboarding process

Implemented significant changes in the code to streamline the onboarding process. This includes modifying the SecuredOnboardingService constructor for better parameter handling and the activation of public and private keys usage, which was previously commented out. Additionally, exceptions and environment classes were refined as part of the code clean-up.

* Update import paths and refactor onboarding process

This commit updates import paths and refactorizes the SecuredOnboardingService constructor for better parameter management. Comment out sections regarding application IDs and signatures have been enabled, contributing towards an enhanced onboarding process. The manner in which exceptions and environment classes are handled has also been refined for a clearer, cleaner codebase.

* Remove exception files and rename workflow file

This commit involves two major changes: deletion of exception files in various directories and renaming the workflow file for clarity. With the removal of exception files, the handling of exceptions and environment classes has been refined. Further, the workflow file has been renamed from 'python-package.yml' to 'continuous_integration.yml' to better reflect its function.

* Refactor CI workflow and limit Python versions

This commit renames the 'continuous_integration.yml' workflow to match standard naming conventions and refactor its operations. The workflow now only runs on Python version "3.11". Additionally, a new workflow file, 'linting-for-all-versions.yml', is added to maintain linting for all Python versions, expanding quality control measures.

* Refactor environment import paths and reenable auth response signature verification

This commit refactors the import paths relating to environments across multiple files, moving the environment related modules under the 'api' directory for better organization. Also, sections of commented-out code in the authentication response module were uncommented to reenable the verification of the signature in the auth response, improving the security of auth responses. Lastly, any instance of strings used to denote an environment has been replaced with their corresponding enumerated types.

* Refactor import paths and use enum for environments

This commit refactors the import paths for environment-related modules, organizing them under the 'api' directory for better structure. It also replaces instances of strings used to denote an environment with the corresponding enumerated types, enhancing code clarity and preventing potential errors.

* Update exception handling and request handling in onboarding

This commit includes significant refactoring of the exceptions raised during the onboarding process, making them more descriptive and specific. In addition, it updates the method of handling requests where it now makes them static. Lastly, some updates include enabling the signing of requests and tweaking the logic of setting request headers.

* Refactor messaging parameters and update function names

This commit changes the handling of messaging parameters by making certain parameters mandatory and removing setter methods. It also modifies the function name from 'get_chunk_components' to 'get_chunk_component'. These changes aim to streamline how parameters are managed and improve the readability of the function names.

* Fix comma error in chunk_component assignment

This commit corrects a syntax error in the assignment of the chunk_component parameter in the messaging parameters module. Previously, a comma at the end of the assignment operation was causing it to be treated as a tuple, which is now removed.

* Remove pull_request trigger from CI workflow

The pull_request trigger has been removed from the continuous integration workflow. This change means that the workflow will no longer run automatically on pull requests to the master branch.

* type hint was removed from the chunk_component assignment in the agrirouter messaging parameters dto. This simplification makes the code more readable and easier to maintain.

---------

Co-authored-by: YashRunwal <[email protected]>
Co-authored-by: Sascha Doemer <[email protected]>
Co-authored-by: YashRunwal <[email protected]>
  • Loading branch information
4 people authored Mar 13, 2024
1 parent 4ee6dc3 commit acf1ce4
Show file tree
Hide file tree
Showing 138 changed files with 7,047 additions and 3,185 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Continuous Integration

on:
push:
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest
strategy:
max-parallel: 1
fail-fast: false
matrix:
python-version: [ "3.11" ]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
flake8 .
- name: Test with pytest
run: |
pytest
35 changes: 35 additions & 0 deletions .github/workflows/linting-for-all-versions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Continuous Integration

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

jobs:
build:

runs-on: ubuntu-latest
strategy:
max-parallel: 1
fail-fast: false
matrix:
python-version: [ "3.7", "3.8", "3.9", "3.10", "3.11" ]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
flake8 .
38 changes: 0 additions & 38 deletions .github/workflows/python-package.yml

This file was deleted.

6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ venv
*.log
*.log.*
.env
.pytest_cache
.pytest_cache
/paho/
/paho_mqtt-1.6.1.dist-info/
/paho/
/paho_mqtt-1.6.1.dist-info/
50 changes: 28 additions & 22 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,48 @@

[abstract]
== Abstract
image::agrirouter.svg[agrirouter]

The agrirouter is a universal data exchange platform for farmers and agricultural contractors that makes it possible to connect machinery and agricultural software, regardless of vendor or manufacturer. Agrirouter does not save data; it transfers data.
As a universal data exchange platform, agrirouter fills a gap on the way to Farming 4.0. Its underlying concept unites cross-vendor and discrimination-free data transfer. You retain full control over your data. Even data exchange with service providers (e.g. agricultural contractors) and other partners is uncomplicated: Data are very rapidly transferred via the online connection, and if you wish, is intelligently connected to other datasets.
image::agrirouter.svg[agrirouter]

The agrirouter is a universal data exchange platform for farmers and agricultural contractors that makes it possible to connect machinery and agricultural software, regardless of vendor or manufacturer.
Agrirouter does not save data; it transfers data.
As a universal data exchange platform, agrirouter fills a gap on the way to Farming 4.0. Its underlying concept unites cross-vendor and discrimination-free data transfer.
You retain full control over your data.
Even data exchange with service providers (e.g. agricultural contractors) and other partners is uncomplicated: Data are very rapidly transferred via the online connection, and if you wish, is intelligently connected to other datasets.

== The current project you're looking at

This project contains the SDK for the communication with the agrirouter. Everything you need for the onboard process, secure communication and much more.
This project contains the SDK for the communication with the agrirouter.
Everything you need for the onboard process, secure communication and much more.

== Installation

The necessary dependencies are installed via `composer`. Just run the following command to add the SDK to your project.


`$ git clone https://github.com/DKE-Data/agrirouter-sdk-python.git`

To install the SDK run the 'setup.py' script in the main directory (for a global install you will need to run this command with root privileges):

`$ cd agrirouter-sdk-python`

`$ virtualenv venv`

`...`
Create your virtual environment using any kind of `conda` setup you would like to have.
The SDK is tested with Python 3.8, 3.9, 3.10 and 3.11.

`$ . venv/bin/activate`
[source,bash]
----
conda create -n agrirouter-sdk-python python=3.8
conda create -n agrirouter-sdk-python python=3.9
conda create -n agrirouter-sdk-python python=3.10
conda create -n agrirouter-sdk-python python=3.11
----

`$ python setup.py install`
Create one of the environments and activate it:

For more install options type:
[source,bash]
----
conda activate agrirouter-sdk-python
----

`$ python setup.py --help`
After the activation you are ready to install the requirements for the SDK:

== Requirements
[source,bash]
----
pip install -r requirements.txt
----

Python 3.6 or above is required.
You are able to select the virtual environment when working with the IDE.

== Running unit tests

Expand Down
19 changes: 8 additions & 11 deletions agrirouter/__init__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
from agrirouter.auth.auth import Authorization
from agrirouter.auth.parameters import AuthUrlParameter

from agrirouter.onboarding.onboarding import SoftwareOnboarding
from agrirouter.onboarding.parameters import SoftwareOnboardingParameter

from agrirouter.revoking.revoking import Revoking
from agrirouter.revoking.parameters import RevokingParameter

from agrirouter.messaging.parameters.service import MessageHeaderParameters, MessagePayloadParameters, \
QueryMessageParameters, QueryHeaderParameters, CloudOffboardParameters, CloudOnboardParameters, \
CapabilityParameters, FeedConfirmParameters, FeedDeleteParameters, ListEndpointsParameters, MessageParameters, \
CapabilitiesParameters, FeedConfirmParameters, FeedDeleteParameters, ListEndpointsParameters, MessageParameters, \
SubscriptionParameters, ImageParameters, TaskParameters, EfdiParameters
from agrirouter.messaging.services.cloud import CloudOnboardService, CloudOffboardService
from agrirouter.messaging.services.messaging import SubscriptionService, CapabilityService, FeedConfirmService,\
FeedDeleteService, QueryHeaderService, QueryMessagesService, ListEndpointsService, ImageService, TaskService, EfdiTimelogService, EfdiTimelogPublishService, EfdiDeviceDscService

from agrirouter.messaging.services.messaging import SubscriptionService, CapabilitiesService, FeedConfirmService, \
FeedDeleteService, QueryHeaderService, QueryMessagesService, ListEndpointsService, SendChunkedMessageService, \
ImageService, TaskService, EfdiTimelogService, EfdiTimelogPublishService, EfdiDeviceDscService
from agrirouter.onboarding.onboarding import SecuredOnboardingService, OnboardingService
from agrirouter.onboarding.parameters import OnboardParameters
from agrirouter.revoking.parameters import RevokingParameter
from agrirouter.revoking.revoking import Revoking
File renamed without changes.
32 changes: 32 additions & 0 deletions agrirouter/api/enums.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from enum import Enum


class BaseEnum(Enum):
@classmethod
def choices(cls):
return [(key.value, key.name) for key in cls]

@classmethod
def values_list(cls):
return [key.value for key in cls]


class ResponseTypes(BaseEnum):
VERIFY = "verify"
ONBOARD = "onboard"


class ContentTypes(BaseEnum):
APPLICATION_JSON = "application/json"


class Environments(BaseEnum):
PRODUCTION: str = "production"
QA: str = "qa"


class RequestHeaders(BaseEnum):
AUTHORIZATION: str = "Authorization"
X_AGRIROUTER_SIGNATURE: str = "X-Agrirouter-Signature"
CONTENT_TYPE: str = "Content-Type"
X_AGRIROUTER_APPLICATION_ID: str = "X-Agrirouter-ApplicationId"
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
from agrirouter.environments.keys import AR_QA_PUBLIC_KEY, AR_PROD_PUBLIC_KEY
from agrirouter.api.keys import AR_QA_PUBLIC_KEY, AR_PROD_PUBLIC_KEY


class BaseEnvironment:
_AGRIROUTER_LOGIN_URL = "/app"
_LOGIN_URL = "/app"
_MQTT_URL_TEMPLATE = "ssl://{host}:{port}"
_SECURED_ONBOARDING_AUTHORIZATION_LINK_TEMPLATE = \
"/application/{application_id}/authorize" \
"?response_type={response_type}&state={state}"

_ENV_BASE_URL = ""
_API_PREFIX = ""
_REGISTRATION_SERVICE_URL = ""

AR_PUBLIC_KEY = None
_AR_PUBLIC_KEY = None

def get_base_url(self) -> str:
return self._ENV_BASE_URL
Expand All @@ -36,7 +34,7 @@ def get_revoke_url(self) -> str:
return self.get_registration_service_url() + self.get_api_prefix() + "/registration/onboard/revoke"

def get_agrirouter_login_url(self) -> str:
return self.get_base_url() + self._AGRIROUTER_LOGIN_URL
return self.get_base_url() + self._LOGIN_URL

def get_secured_onboarding_authorization_url(self, application_id, response_type, state, redirect_uri=None) -> str:
auth_url = self.get_base_url() + self._SECURED_ONBOARDING_AUTHORIZATION_LINK_TEMPLATE.format(
Expand All @@ -50,20 +48,18 @@ def get_mqtt_server_url(self, host, port) -> str:
return self._MQTT_URL_TEMPLATE.format(host=host, port=port)

def get_env_public_key(self):
return self.AR_PUBLIC_KEY
return self._AR_PUBLIC_KEY


class ProductionEnvironment(BaseEnvironment):
class Production(BaseEnvironment):
_ENV_BASE_URL = "https://goto.my-agrirouter.com"
_API_PREFIX = "/api/v1.0"
_REGISTRATION_SERVICE_URL = "https://onboard.my-agrirouter.com"
_AR_PUBLIC_KEY = AR_PROD_PUBLIC_KEY

#AR_PUBLIC_KEY = AR_PROD_PUBLIC_KEY


class QAEnvironment(BaseEnvironment):
class QA(BaseEnvironment):
_ENV_BASE_URL = "https://agrirouter-qa.cfapps.eu10.hana.ondemand.com"
_API_PREFIX = "/api/v1.0"
_REGISTRATION_SERVICE_URL = "https://agrirouter-registration-service-hubqa-eu10.cfapps.eu10.hana.ondemand.com"

AR_PUBLIC_KEY = AR_QA_PUBLIC_KEY
_AR_PUBLIC_KEY = AR_QA_PUBLIC_KEY
68 changes: 68 additions & 0 deletions agrirouter/api/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
class AgrirouterBaseException(Exception):
""" Base class for internal exceptions. """
_message = ...

def __init__(self, message=None):
""" Initialize the exception and define the message. """
if not message:
message = self._message
self.message = message


class BadAuthResponse(AgrirouterBaseException):
_message = "Bad Response. Response could is not verified."


class InvalidEnvironmentSetup(AgrirouterBaseException):
_message = "Invalid value of env parameter. [QA] or [Production] values are allowed. " \
"Please use environments.enums.Environments enum for configure environment properly"


class TypeUrlNotFound(AgrirouterBaseException):
_message = "Given type url not found"


class WrongField(AgrirouterBaseException):
_message = "Unknown field"


class CanNotDecodeMessage(AgrirouterBaseException):
_message = "Can't decode message"


class CanNotFetchOutboxMessage(AgrirouterBaseException):
_message = "Can't fetch outbox message"


class WrongCertificationType(AgrirouterBaseException):
""" Exception for wrong certification type. """
_message = "Wrong Certification type. Use 'onboarding.enums.CertificationTypes' values instead."


class WrongGateWayType(AgrirouterBaseException):
""" Exception if there is wrong gateway Type. """
_message = "Wrong Gate Way Id. Use onboarding.enums.GateWays values instead."


class RequestNotSigned(AgrirouterBaseException):
""" Exception if request is not signed correctly. """
_message = """
Request does not contain signature header. Please sign the request with request.sign() method.\n
Details on: https://docs.my-agrirouter.com/agrirouter-interface-documentation/latest/
integration/onboarding.html#signing-requests
"""


class BadMessagingResult(AgrirouterBaseException):
""" Exception if the messaging result is not ok. """
_message = "Messaging request failed"


class UnexpectedErrorDuringOnboarding(AgrirouterBaseException):
""" Exception if onboarding failed (most likely in case of an unexpected error). """
_message = "Unexpected error during onboarding."


class MissingRegistrationCode(AgrirouterBaseException):
""" Exception if registration code is missing. """
_message = "Registration code is required"
File renamed without changes.
1 change: 0 additions & 1 deletion agrirouter/auth/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@


class Authorization(EnvironmentalService):

SIGNATURE_KEY = "signature"
STATE_KEY = "state"
TOKEN_KEY = "token"
Expand Down
Loading

0 comments on commit acf1ce4

Please sign in to comment.