Skip to content

Commit 31695c0

Browse files
authored
Merge pull request #51
* Update import and rename constants file * Refactor certificate creation to CertificationService class * Refactor decoding methods into DecodingService class * Refactor decoding functions into DecodingService class * Refactor encoding functions into EncodingService class * Refactor encoding functions into EncodingService class * Moved CertificateTypes and Gateways enum to api.enums * Refactor signature handling into SignatureService class * Refactored utc_time_util to a class structure * Refactor uuid utility to a class-based implementation * Refactor environment handling and file structure * Refactor constants and keys management in agrirouter API * Refactored package structure and rearranged onboarding and messaging … * Update efdi_pb2.py in agrirouter messaging * Refactor import statements across multiple modules * Refactor import order in test modules * Refactor messaging services and minor changes in file structures
1 parent 06aa6dd commit 31695c0

93 files changed

Lines changed: 6658 additions & 6666 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

example_script.py

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
import time
22
import agrirouter as ar
3-
from agrirouter.onboarding.enums import Gateways
3+
from agrirouter.api.enums import CapabilityType
4+
from agrirouter.service.dto.response.messaging import OnboardResponse
5+
from agrirouter.service.messaging.common import MqttMessagingService, HttpMessagingService
6+
from agrirouter.service.messaging.message_sending import ListEndpointsService, CapabilitiesService, SubscriptionService, \
7+
QueryHeaderService
8+
from agrirouter.service.parameter.messaging import QueryHeaderParameters, ListEndpointsParameters, \
9+
CapabilitiesParameters, SubscriptionParameters
10+
from agrirouter.api.enums import Gateways
411
from agrirouter.generated.messaging.request.payload.endpoint.subscription_pb2 import Subscription
512
from agrirouter.generated.messaging.request.payload.endpoint.capabilities_pb2 import CapabilitySpecification
6-
from agrirouter.messaging.services.commons import HttpMessagingService, MqttMessagingService
7-
from agrirouter.utils.uuid_util import new_uuid
13+
from agrirouter.util.uuid_util import UUIDUtil
814

915
from google.protobuf.timestamp_pb2 import Timestamp
1016

1117
from agrirouter.generated.messaging.request.payload.account.endpoints_pb2 import ListEndpointsQuery
1218
from agrirouter.generated.messaging.request.payload.feed.feed_requests_pb2 import ValidityPeriod
13-
from agrirouter.onboarding.response import OnboardResponse
1419

1520
public_key = """-----BEGIN PUBLIC KEY-----
1621
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzGt41/+kSOTlO1sJvLIN
@@ -143,7 +148,7 @@ def example_list_endpoints_mqtt(onboarding_response_data, foo):
143148
direction=ListEndpointsQuery.Direction.Value("SEND_RECEIVE"),
144149
filtered=False,
145150
onboarding_response=onboarding_response,
146-
application_message_id=new_uuid(),
151+
application_message_id=UUIDUtil.new_uuid(),
147152
application_message_seq_no=1,
148153
)
149154
list_endpoint_service = ListEndpointsService(messaging_service)
@@ -165,7 +170,7 @@ def example_set_capabilities(onboarding_response_data, mqtt_message_callback):
165170
)
166171
capabilities_parameters = CapabilitiesParameters(
167172
onboarding_response=onboarding_response,
168-
application_message_id=new_uuid(),
173+
application_message_id=UUIDUtil.new_uuid(),
169174
application_message_seq_no=1,
170175
application_id=application_id,
171176
certification_version_id=certification_version_id,
@@ -189,7 +194,7 @@ def example_list_endpoints_http(onboarding_response_data):
189194
direction=2,
190195
filtered=False,
191196
onboarding_response=onboarding_response,
192-
application_message_id=new_uuid(),
197+
application_message_id=UUIDUtil.new_uuid(),
193198
application_message_seq_no=1,
194199
)
195200
list_endpoint_service = ListEndpointsService(messaging_service)
@@ -211,7 +216,7 @@ def example_subscription_http(onboarding_response_data):
211216
subscription_parameters = SubscriptionParameters(
212217
subscription_items=[subscription_item],
213218
onboarding_response=onboarding_response,
214-
application_message_id=new_uuid(),
219+
application_message_id=UUIDUtil.new_uuid(),
215220
application_message_seq_no=1,
216221
)
217222

@@ -232,7 +237,7 @@ def example_subscription_mqtt(onboarding_response_data, on_msg_callback):
232237
subscription_parameters = SubscriptionParameters(
233238
subscription_items=[subscription_item],
234239
onboarding_response=onboarding_response,
235-
application_message_id=new_uuid(),
240+
application_message_id=UUIDUtil.new_uuid(),
236241
application_message_seq_no=1,
237242
)
238243

@@ -254,11 +259,11 @@ def example_query_header_message_http(onboarding_response_data):
254259
sent_to = Timestamp()
255260
validity_period = ValidityPeriod(sent_from=sent_from, sent_to=sent_to)
256261
query_header_parameters = QueryHeaderParameters(
257-
message_ids=[new_uuid(), new_uuid()],
258-
senders=[new_uuid(), new_uuid()],
262+
message_ids=[UUIDUtil.new_uuid(), UUIDUtil.new_uuid()],
263+
senders=[UUIDUtil.new_uuid(), UUIDUtil.new_uuid()],
259264
validity_period=validity_period,
260265
onboarding_response=onboarding_response,
261-
application_message_id=new_uuid(),
266+
application_message_id=UUIDUtil.new_uuid(),
262267
application_message_seq_no=1,
263268
)
264269
messaging_result = query_header_service.send(query_header_parameters)
@@ -277,11 +282,11 @@ def example_query_header_message_mqtt(onboarding_response_data, on_msg_callback)
277282
sent_to = Timestamp()
278283
validity_period = ValidityPeriod(sent_from=sent_from, sent_to=sent_to)
279284
query_header_parameters = QueryHeaderParameters(
280-
message_ids=[new_uuid(), new_uuid()],
281-
senders=[new_uuid(), new_uuid()],
285+
message_ids=[UUIDUtil.new_uuid(), UUIDUtil.new_uuid()],
286+
senders=[UUIDUtil.new_uuid(), UUIDUtil.new_uuid()],
282287
validity_period=validity_period,
283288
onboarding_response=onboarding_response,
284-
application_message_id=new_uuid(),
289+
application_message_id=UUIDUtil.new_uuid(),
285290
application_message_seq_no=1,
286291
)
287292
messaging_result = query_header_service.send(query_header_parameters)
@@ -295,20 +300,19 @@ def example_query_header_message_mqtt(onboarding_response_data, on_msg_callback)
295300
def on_message_callback(client, userdata, msg):
296301
# Define here the way receiving messages will be processed
297302

298-
from agrirouter.messaging.decode import decode_response
299-
from agrirouter.messaging.decode import decode_details
300-
from agrirouter.messaging.messages import OutboxMessage
303+
from agrirouter.service.messaging.decoding import DecodingService
304+
from agrirouter.api.messages import OutboxMessage
301305

302306
outbox_message = OutboxMessage()
303307
outbox_message.json_deserialize(msg.payload.decode().replace("'", '"'))
304308

305309
print(outbox_message.command.message)
306310

307-
decoded_message = decode_response(outbox_message.command.message)
311+
decoded_message = DecodingService.decode_response(outbox_message.command.message)
308312
print(decoded_message.response_envelope)
309313

310314
try:
311-
decoded_details = decode_details(decoded_message.response_payload.details)
315+
decoded_details = DecodingService.decode_details(decoded_message.response_payload.details)
312316
print(decoded_details)
313317
except Exception as exc:
314318
print("Error in decoding details: ", exc)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,7 @@
1717
"GNASOOHju7ewlYjkyGIRxxAoc3C0w5dg1qlLiAFWToYwgDOcUpLRjU/7bzGiGvp8\n" \
1818
"RwIDAQAB\n" \
1919
"-----END PUBLIC KEY-----"
20+
21+
ASYNC = "ASYNC"
22+
23+
SYNC = "SYNC"

src/agrirouter/api/enums.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,29 @@ class CapabilityDirectionType(BaseEnum):
7777
SEND = "SEND"
7878
RECEIVE = "RECEIVE"
7979
SEND_RECEIVE = "SEND_RECEIVE"
80+
81+
82+
class CertificateTypes(BaseEnum):
83+
"""
84+
CertificateTypes Enum Class
85+
86+
An enum class representing different types of certificates.
87+
88+
Attributes:
89+
PEM (str): The PEM certificate type.
90+
P12 (str): The P12 certificate type.
91+
"""
92+
PEM = "PEM"
93+
P12 = "P12"
94+
95+
96+
class Gateways(BaseEnum):
97+
"""
98+
Enum class to store the possible gateways for communication.
99+
100+
Attributes:
101+
MQTT (str): The MQTT gateway.
102+
HTTP (str): The HTTP gateway.
103+
"""
104+
MQTT = "2"
105+
HTTP = "3"
Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from agrirouter.api.keys import AR_QA_PUBLIC_KEY, AR_PROD_PUBLIC_KEY
1+
from agrirouter.api.constants import AR_QA_PUBLIC_KEY, AR_PROD_PUBLIC_KEY
22

33

44
class BaseEnvironment:
@@ -63,3 +63,27 @@ class Qa(BaseEnvironment):
6363
_API_PREFIX = "/api/v1.0"
6464
_REGISTRATION_SERVICE_URL = "https://agrirouter-registration-service-hubqa-eu10.cfapps.eu10.hana.ondemand.com"
6565
_AR_PUBLIC_KEY = AR_QA_PUBLIC_KEY
66+
67+
68+
class EnvironmentalService:
69+
"""
70+
A class that provides environmental messaging based on the provided environment value.
71+
72+
Attributes:
73+
- _environment (Environment): The current environment.
74+
"""
75+
76+
def __init__(self, env: BaseEnvironment):
77+
self._set_env(env)
78+
79+
def _set_env(self, env) -> None:
80+
"""
81+
Sets the environment based on the provided value.
82+
83+
Parameters:
84+
- env (str): The desired environment value. Must be one of the following: `qa` or `production`.
85+
86+
Raises:
87+
- InvalidEnvironmentSetup: If the provided environment value is not valid.
88+
"""
89+
self._environment = env

src/agrirouter/api/exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class BadAuthResponse(AgrirouterBaseException):
1515

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

2020

2121
class TypeUrlNotFound(AgrirouterBaseException):
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from typing import Union, Dict
33

44
from agrirouter.api.exceptions import WrongField
5-
from agrirouter.utils.utc_time_util import now_as_utc_str
5+
from agrirouter.util.utc_time_util import UtcTimeUtil
66

77

88
class EncodedMessage:
@@ -36,7 +36,7 @@ class Message:
3636

3737
def __init__(self, content):
3838
self.content = content
39-
self.timestamp = now_as_utc_str()
39+
self.timestamp = UtcTimeUtil.now_as_utc_str()
4040

4141
def json_serialize(self) -> dict:
4242
return {
@@ -115,7 +115,7 @@ def set_command(self, command: Command) -> None:
115115

116116
class MessageParameterTuple:
117117
"""
118-
Class used to form a tuple of header and payload parameters
118+
Class used to form a tuple of header and payload parameter
119119
"""
120120

121121
def __init__(self, message_header_parameters, message_payload_parameters):
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from typing import List
22

3+
from agrirouter.api.enums import CapabilityType
34
from agrirouter.generated.messaging.request.payload.endpoint.capabilities_pb2 import CapabilitySpecification
45
from agrirouter.generated.messaging.request.payload.endpoint.subscription_pb2 import Subscription
5-
from agrirouter.api.enums import CapabilityType
66

77

88
class SubscriptionItemBuilder:

src/agrirouter/environments/environmental_services.py

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/agrirouter/generated/messaging/request/payload/efdi/efdi_pb2.py

Lines changed: 5243 additions & 5269 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/agrirouter/messaging/certification.py

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)