Skip to content
This repository was archived by the owner on May 8, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
937bb12
Create EnvironmentService class. Move exceptions file from auth to en…
dastier Sep 27, 2021
95d6083
Fix exceptions in auth
dastier Sep 27, 2021
cb6191b
Change message of InvalidEnvironmentSetup
dastier Sep 27, 2021
c0569f0
Implement Onboarding
dastier Sep 28, 2021
e039b75
Fix import bug in onboarding/onboarding.py
dastier Sep 28, 2021
eaaacc4
Fix bug in OnboardingParameter.get_body_params() method
dastier Sep 28, 2021
db3f2e0
Fix OnboardingParameter.create_request(), OnboardingParameter.create_…
dastier Sep 28, 2021
ad16fc5
Fix revoking
dastier Sep 28, 2021
9372b54
Implement request signing in onboarding
dastier Sep 28, 2021
810cb18
Implement request signing in revoking
dastier Sep 28, 2021
0fd281e
Implement request signing in auth
dastier Sep 28, 2021
65f5662
Refactor RequestNotSigned exception
dastier Sep 29, 2021
d96a4f3
Create requeirements.txt
dastier Sep 29, 2021
bae3e4a
Merge pull request #1 from DKE-Data/Implement_Onboarding
dastier Sep 29, 2021
01be9b9
Implement get_connection_criteria, get_sensor_alternate_id, get_authe…
dastier Oct 4, 2021
d484cef
Implement messaging/dto parameters
dastier Oct 4, 2021
43a5633
Create protobuf classes for messages
dastier Oct 4, 2021
331f04b
Implement certification for messaging
dastier Oct 4, 2021
0713b51
Create AbstractClient, HttpMessagingClient, MqttMessagingClient
dastier Oct 4, 2021
61da15d
Add prtobuf library to requirements
dastier Oct 4, 2021
968dc24
Create MessageHeaderParameters, MessagePayloadParameters
dastier Oct 4, 2021
6a194e4
Add paho-mqtt to requirements
dastier Oct 4, 2021
6c5d389
Fix MqttMessagingClient
dastier Oct 4, 2021
b6e37e4
Create cloud_virtualized_app_registration_pb2.py protobuf file
dastier Oct 4, 2021
bc5cc97
Move files to common agrirouter directory
Oct 4, 2021
cfe5fb2
Merge pull request #2 from DKE-Data/Refactor_structure
dastier Oct 4, 2021
aa3ba7d
Add package config files (#3)
dastier Oct 5, 2021
09db5b9
Create utils
dastier Oct 5, 2021
a535a25
Fix imports in protobuf generated files
dastier Oct 5, 2021
8d8a0f6
Implement encoding messages
dastier Oct 5, 2021
364aeaa
Implement decoding messages
dastier Oct 5, 2021
c75405c
Implement mqtt client
dastier Oct 5, 2021
6a9bd3e
Implement MQttMessagingService. Refactor HttpMessagingService
dastier Oct 5, 2021
55e9b44
Refactor messaging/parameters
dastier Oct 5, 2021
76465a6
Decoded Message
dastier Oct 5, 2021
0da66d4
Create TypeUrlNotFoundError
dastier Oct 5, 2021
c7f8ac7
Create TypeUrl service
dastier Oct 5, 2021
0b6d1f7
Refactor messaging/decode
dastier Oct 5, 2021
8d35ed2
Add initial documentation (#4)
dastier Oct 5, 2021
fbab5cc
Fix generated/cload_virtualized_add_registration
dastier Oct 5, 2021
ac2b46e
Create TechnicalMessageType enum
dastier Oct 5, 2021
02e89f9
Rename function encode to encode_messge
dastier Oct 5, 2021
d7d1ca4
Implement MessagingServiceParameters
dastier Oct 5, 2021
e759732
Implement MEssagingServices classes
dastier Oct 5, 2021
686eff3
Clean up the README (#5)
dastier Oct 6, 2021
59fcaea
Add AR Public Keys to handle signature verification
dastier Oct 7, 2021
a930124
Refactor auth
dastier Oct 7, 2021
331f3d2
Implement QueryMessagesService, QueryHeaderService
dastier Oct 7, 2021
e0e67a6
Implement OutboxService
dastier Oct 7, 2021
0f00ca2
Implement CloudOnboardService, CloudOffboardService
dastier Oct 7, 2021
5392b9a
Fix SoftwareOnboardingHeader.sign() method
dastier Oct 7, 2021
a24689d
Merge branch 'develop' into Implement_Messaging
dastier Oct 7, 2021
440ff75
Fix imports
dastier Oct 7, 2021
6583369
Create examples file
dastier Oct 7, 2021
8a34738
Add unit tests (#6)
dastier Oct 11, 2021
de831dc
Move main classes to agrirouter/__init__.py
dastier Oct 11, 2021
6403944
Merge remote-tracking branch 'origin/Implement_Messaging' into Implem…
dastier Oct 11, 2021
8b5ee58
Update examples.txt
dastier Oct 11, 2021
add71b4
Fix examples.txt
dastier Oct 11, 2021
7a2de87
Fix examples.txt
dastier Oct 11, 2021
61c6376
Fix SoftwareOnboardingHeader
dastier Oct 11, 2021
2e3e801
Fix onboarding
dastier Oct 12, 2021
49827d2
Implement messaging certification
dastier Oct 13, 2021
fdf133a
Fix onboarding headers signing
dastier Oct 13, 2021
8bd9dab
Refactor onboarding request body
dastier Oct 13, 2021
cd8a255
Refactor onboarding parameters
dastier Oct 13, 2021
7b06470
Refactor onboarding client
dastier Oct 13, 2021
19af659
Fix requests certification in messaging
dastier Oct 13, 2021
1ed15e2
Refactor messaging certification
dastier Oct 13, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
build
dist
venv
.idea
**/__pycache__
*.egg-info
*.log
*.log.*
.env
.env
.pytest_cache
201 changes: 201 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/

TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION

1. Definitions.

"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.

"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.

"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.

"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.

"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.

"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.

"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).

"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.

"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."

"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.

2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.

3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.

4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:

(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and

(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and

(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and

(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.

You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.

5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.

6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.

7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.

8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.

9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.

END OF TERMS AND CONDITIONS

APPENDIX: How to apply the Apache License to your work.

To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
56 changes: 56 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
= agrirouter-sdk-python
:imagesdir: assets/images
:toc:
:toc-title:
:toclevels: 4

[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.


== 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.

== 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`

`...`

`$ . venv/bin/activate`

`$ python setup.py install`

For more install options type:

`$ python setup.py --help`

== Requirements

Python 3.6 or above is required.

== Running unit tests

`$ pytest`

== External resources

Here are some external resources for the development:

* https://my-agrirouter.com[My Agrirouter Website]
* https://github.com/DKE-Data/agrirouter-interface-documentation[Integration Guide]
* https://www.aef-online.org[EFDI Protobuf Definition]
17 changes: 17 additions & 0 deletions agrirouter/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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, \
SubscriptionParameters
from agrirouter.messaging.services.cloud import CloudOnboardService, CloudOffboardService
from agrirouter.messaging.services.messaging import SubscriptionService, CapabilityService, FeedConfirmService,\
FeedDeleteService, QueryHeaderService, QueryMessagesService, ListEndpointsService

File renamed without changes.
28 changes: 11 additions & 17 deletions auth/auth.py → agrirouter/auth/auth.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
from urllib.parse import urlparse, parse_qs

from auth.exceptions import InvalidEnvironmentSetup
from auth.parameters import AuthUrlParameter
from auth.response import AuthResponse
from environments.environments import ProductionEnvironment, QAEnvironment
from agrirouter.auth.parameters import AuthUrlParameter
from agrirouter.auth.response import AuthResponse
from agrirouter.environments.environmental_services import EnvironmentalService


class Authorization:
class Authorization(EnvironmentalService):

SIGNATURE_KEY = "signature"
STATE_KEY = "state"
TOKEN_KEY = "token"
ERROR_KEY = "error"

def __init__(self, env):
self._set_env(env)

def _set_env(self, env) -> None:
if env == "QA":
self._environment = QAEnvironment()
elif env == "Production":
self._environment = ProductionEnvironment()
else:
raise InvalidEnvironmentSetup(env=env)
def __init__(self, *args, **kwargs):
self._public_key = kwargs.pop("public_key")
self._private_key = kwargs.pop("private_key")
super(Authorization, self).__init__(*args, **kwargs)

def get_auth_request_url(self, parameters: AuthUrlParameter) -> str:
auth_parameters = parameters.get_parameters()
Expand All @@ -33,8 +26,9 @@ def extract_auth_response(self, url: str) -> AuthResponse:
query_params = self._extract_query_params(parsed_url.query)
return AuthResponse(query_params)

def verify_auth_response(self):
pass
def verify_auth_response(self, response, public_key=None):
public_key = public_key if public_key else self._environment.get_env_public_key()
response.verify(public_key)

@staticmethod
def _extract_query_params(query_params: str) -> dict:
Expand Down
File renamed without changes.
6 changes: 6 additions & 0 deletions agrirouter/auth/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

class BadAuthResponse(Exception):
def __init__(self, message=None):
if not message:
message = "Bad Response. Response could is not verified."
self.message = message
2 changes: 1 addition & 1 deletion auth/parameters.py → agrirouter/auth/parameters.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from uuid import uuid4

from auth.enums import ResponseType
from agrirouter.auth.enums import ResponseType


class AuthUrlParameter:
Expand Down
Loading