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
50 commits
Select commit Hold shift + click to select a range
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
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
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
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ venv
*.log
*.log.*
.env
.pytest_cache
3 changes: 3 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ For more install options type:

Python 3.6 or above is required.

== Running unit tests

`$ pytest`

== External resources

Expand Down
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

4 changes: 2 additions & 2 deletions agrirouter/auth/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def extract_auth_response(self, url: str) -> AuthResponse:
query_params = self._extract_query_params(parsed_url.query)
return AuthResponse(query_params)

@staticmethod
def verify_auth_response(response, public_key):
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
Expand Down
20 changes: 13 additions & 7 deletions agrirouter/auth/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,16 @@ def __init__(self, query_params):
self._token = query_params.get(self.TOKEN_KEY, None)
self._error = query_params.get(self.ERROR_KEY, None)
self.is_successful = not bool(self._error)
self.is_valid = False
self._was_verified = False
self._is_valid = False

@property
def is_valid(self):
if not self._was_verified:
raise PermissionError("The response was not verified yet. Please verify first. "
"You can access is_valid only after verifying")

return self._is_valid

def verify(self, public_key) -> None:
"""
Expand All @@ -37,13 +46,14 @@ def verify(self, public_key) -> None:
encoded_data = self._state + self._token
unquoted_signature = unquote(self._signature)
encoded_signature = base64.b64decode(unquoted_signature.encode("utf-8"))
self._was_verified = True
try:
verify_signature(encoded_data, encoded_signature, public_key)
except InvalidSignature:
print("Response is invalid: invalid signature.")
self.is_valid = False
self._is_valid = False

self.is_valid = True
self._is_valid = True

@staticmethod
def decode_token(token: Union[str, bytes]) -> dict:
Expand All @@ -63,7 +73,3 @@ def get_auth_result(self) -> dict:
self.TOKEN_KEY: self._token,
self.CRED_KEY: decoded_token
}


def decorator(func):
pass
29 changes: 0 additions & 29 deletions agrirouter/clients/clients.py

This file was deleted.

11 changes: 11 additions & 0 deletions agrirouter/environments/environments.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from agrirouter.environments.keys import AR_QA_PUBLIC_KEY, AR_PROD_PUBLIC_KEY


class BaseEnvironment:
_AGRIROUTER_LOGIN_URL = "/app"
Expand All @@ -10,6 +12,8 @@ class BaseEnvironment:
_API_PREFIX = ""
_REGISTRATION_SERVICE_URL = ""

AR_PUBLIC_KEY = None

def get_base_url(self) -> str:
return self._ENV_BASE_URL

Expand Down Expand Up @@ -45,14 +49,21 @@ def get_secured_onboarding_authorization_url(self, application_id, response_type
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


class ProductionEnvironment(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


class QAEnvironment(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
19 changes: 19 additions & 0 deletions agrirouter/environments/keys.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
AR_QA_PUBLIC_KEY = "-----BEGIN PUBLIC KEY-----\n" \
"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAy8xF9661acn+iS+QS+9Y\n" \
"3HvTfUVcismzbuvxHgHA7YeoOUFxyj3lkaTnXm7hzQe4wDEDgwpJSGAzxIIYSUXe\n" \
"8EsWLorg5O0tRexx5SP3+kj1i83DATBJCXP7k+bAF4u2FVJphC1m2BfLxelGLjzx\n" \
"VAS/v6+EwvYaT1AI9FFqW/a2o92IsVPOh9oM9eds3lBOAbH/8XrmVIeHofw+XbTH\n" \
"1/7MLD6IE2+HbEeY0F96nioXArdQWXcjUQsTch+p0p9eqh23Ak4ef5oGcZhNd4yp\n" \
"Y8M6ppvIMiXkgWSPJevCJjhxRJRmndY+ajYGx7CLePx7wNvxXWtkng3yh+7WiZ/Y\n" \
"qwIDAQAB\n" \
"-----END PUBLIC KEY-----"

AR_PROD_PUBLIC_KEY = "-----BEGIN PUBLIC KEY-----\n" \
"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwCxD31sYtzH9NTfZ6n8H\n" \
"+H/QgOaoTL9GAakplAsdwYSLjBpgYMZOHIgkdM9ksRP8WsITChtZtxrCnBjR8bap\n" \
"ekPT/pM9zPZlNEPxUlylJNwwTWjzTJP03+Yr07Q8v8fTJ5VWzAHlHtGQ/sI7yXA8\n" \
"pzruTNre1MzxO3lkljt2Q2e7CVXAp1b53BghgysppL9Bl7NK1R+vdWSs0B1Db/Gj\n" \
"alOkWUnhivTjRMX61RGDCQSVSEaX12EvJX7FooAsW3NFeZCgeZGWEa5ZMALIiBL4\n" \
"GNASOOHju7ewlYjkyGIRxxAoc3C0w5dg1qlLiAFWToYwgDOcUpLRjU/7bzGiGvp8\n" \
"RwIDAQAB\n" \
"-----END PUBLIC KEY-----"
Loading