Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/update file structure to match other sdks #51

Merged
merged 17 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
44 changes: 24 additions & 20 deletions example_script.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import time
import agrirouter as ar
from agrirouter.onboarding.enums import Gateways
from agrirouter.api.enums import CapabilityType
from agrirouter.service.dto.response.messaging import OnboardResponse
from agrirouter.service.messaging.common import MqttMessagingService, HttpMessagingService
from agrirouter.service.messaging.message_sending import ListEndpointsService, CapabilitiesService, SubscriptionService, \
QueryHeaderService
from agrirouter.service.parameter.messaging import QueryHeaderParameters, ListEndpointsParameters, \
CapabilitiesParameters, SubscriptionParameters
from agrirouter.api.enums import Gateways
from agrirouter.generated.messaging.request.payload.endpoint.subscription_pb2 import Subscription
from agrirouter.generated.messaging.request.payload.endpoint.capabilities_pb2 import CapabilitySpecification
from agrirouter.messaging.services.commons import HttpMessagingService, MqttMessagingService
from agrirouter.utils.uuid_util import new_uuid
from agrirouter.util.uuid_util import UUIDUtil

from google.protobuf.timestamp_pb2 import Timestamp

from agrirouter.generated.messaging.request.payload.account.endpoints_pb2 import ListEndpointsQuery
from agrirouter.generated.messaging.request.payload.feed.feed_requests_pb2 import ValidityPeriod
from agrirouter.onboarding.response import OnboardResponse

public_key = """-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzGt41/+kSOTlO1sJvLIN
Expand Down Expand Up @@ -143,7 +148,7 @@ def example_list_endpoints_mqtt(onboarding_response_data, foo):
direction=ListEndpointsQuery.Direction.Value("SEND_RECEIVE"),
filtered=False,
onboarding_response=onboarding_response,
application_message_id=new_uuid(),
application_message_id=UUIDUtil.new_uuid(),
application_message_seq_no=1,
)
list_endpoint_service = ListEndpointsService(messaging_service)
Expand All @@ -165,7 +170,7 @@ def example_set_capabilities(onboarding_response_data, mqtt_message_callback):
)
capabilities_parameters = CapabilitiesParameters(
onboarding_response=onboarding_response,
application_message_id=new_uuid(),
application_message_id=UUIDUtil.new_uuid(),
application_message_seq_no=1,
application_id=application_id,
certification_version_id=certification_version_id,
Expand All @@ -189,7 +194,7 @@ def example_list_endpoints_http(onboarding_response_data):
direction=2,
filtered=False,
onboarding_response=onboarding_response,
application_message_id=new_uuid(),
application_message_id=UUIDUtil.new_uuid(),
application_message_seq_no=1,
)
list_endpoint_service = ListEndpointsService(messaging_service)
Expand All @@ -211,7 +216,7 @@ def example_subscription_http(onboarding_response_data):
subscription_parameters = SubscriptionParameters(
subscription_items=[subscription_item],
onboarding_response=onboarding_response,
application_message_id=new_uuid(),
application_message_id=UUIDUtil.new_uuid(),
application_message_seq_no=1,
)

Expand All @@ -232,7 +237,7 @@ def example_subscription_mqtt(onboarding_response_data, on_msg_callback):
subscription_parameters = SubscriptionParameters(
subscription_items=[subscription_item],
onboarding_response=onboarding_response,
application_message_id=new_uuid(),
application_message_id=UUIDUtil.new_uuid(),
application_message_seq_no=1,
)

Expand All @@ -254,11 +259,11 @@ def example_query_header_message_http(onboarding_response_data):
sent_to = Timestamp()
validity_period = ValidityPeriod(sent_from=sent_from, sent_to=sent_to)
query_header_parameters = QueryHeaderParameters(
message_ids=[new_uuid(), new_uuid()],
senders=[new_uuid(), new_uuid()],
message_ids=[UUIDUtil.new_uuid(), UUIDUtil.new_uuid()],
senders=[UUIDUtil.new_uuid(), UUIDUtil.new_uuid()],
validity_period=validity_period,
onboarding_response=onboarding_response,
application_message_id=new_uuid(),
application_message_id=UUIDUtil.new_uuid(),
application_message_seq_no=1,
)
messaging_result = query_header_service.send(query_header_parameters)
Expand All @@ -277,11 +282,11 @@ def example_query_header_message_mqtt(onboarding_response_data, on_msg_callback)
sent_to = Timestamp()
validity_period = ValidityPeriod(sent_from=sent_from, sent_to=sent_to)
query_header_parameters = QueryHeaderParameters(
message_ids=[new_uuid(), new_uuid()],
senders=[new_uuid(), new_uuid()],
message_ids=[UUIDUtil.new_uuid(), UUIDUtil.new_uuid()],
senders=[UUIDUtil.new_uuid(), UUIDUtil.new_uuid()],
validity_period=validity_period,
onboarding_response=onboarding_response,
application_message_id=new_uuid(),
application_message_id=UUIDUtil.new_uuid(),
application_message_seq_no=1,
)
messaging_result = query_header_service.send(query_header_parameters)
Expand All @@ -295,20 +300,19 @@ def example_query_header_message_mqtt(onboarding_response_data, on_msg_callback)
def on_message_callback(client, userdata, msg):
# Define here the way receiving messages will be processed

from agrirouter.messaging.decode import decode_response
from agrirouter.messaging.decode import decode_details
from agrirouter.messaging.messages import OutboxMessage
from agrirouter.service.messaging.decoding import DecodingService
from agrirouter.api.messages import OutboxMessage

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

print(outbox_message.command.message)

decoded_message = decode_response(outbox_message.command.message)
decoded_message = DecodingService.decode_response(outbox_message.command.message)
print(decoded_message.response_envelope)

try:
decoded_details = decode_details(decoded_message.response_payload.details)
decoded_details = DecodingService.decode_details(decoded_message.response_payload.details)
print(decoded_details)
except Exception as exc:
print("Error in decoding details: ", exc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@
"GNASOOHju7ewlYjkyGIRxxAoc3C0w5dg1qlLiAFWToYwgDOcUpLRjU/7bzGiGvp8\n" \
"RwIDAQAB\n" \
"-----END PUBLIC KEY-----"

ASYNC = "ASYNC"

SYNC = "SYNC"
26 changes: 26 additions & 0 deletions src/agrirouter/api/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,29 @@ class CapabilityDirectionType(BaseEnum):
SEND = "SEND"
RECEIVE = "RECEIVE"
SEND_RECEIVE = "SEND_RECEIVE"


class CertificateTypes(BaseEnum):
"""
CertificateTypes Enum Class

An enum class representing different types of certificates.

Attributes:
PEM (str): The PEM certificate type.
P12 (str): The P12 certificate type.
"""
PEM = "PEM"
P12 = "P12"


class Gateways(BaseEnum):
"""
Enum class to store the possible gateways for communication.

Attributes:
MQTT (str): The MQTT gateway.
HTTP (str): The HTTP gateway.
"""
MQTT = "2"
HTTP = "3"
26 changes: 25 additions & 1 deletion src/agrirouter/api/environments.py → src/agrirouter/api/env.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from agrirouter.api.keys import AR_QA_PUBLIC_KEY, AR_PROD_PUBLIC_KEY
from agrirouter.api.constants import AR_QA_PUBLIC_KEY, AR_PROD_PUBLIC_KEY


class BaseEnvironment:
Expand Down Expand Up @@ -63,3 +63,27 @@ class Qa(BaseEnvironment):
_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


class EnvironmentalService:
"""
A class that provides environmental messaging based on the provided environment value.

Attributes:
- _environment (Environment): The current environment.
"""

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

def _set_env(self, env) -> None:
"""
Sets the environment based on the provided value.

Parameters:
- env (str): The desired environment value. Must be one of the following: `qa` or `production`.

Raises:
- InvalidEnvironmentSetup: If the provided environment value is not valid.
"""
self._environment = env
2 changes: 1 addition & 1 deletion src/agrirouter/api/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class BadAuthResponse(AgrirouterBaseException):

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"
"Please use env.enums.Environments enum for configure environment properly"


class TypeUrlNotFound(AgrirouterBaseException):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import Union, Dict

from agrirouter.api.exceptions import WrongField
from agrirouter.utils.utc_time_util import now_as_utc_str
from agrirouter.util.utc_time_util import UtcTimeUtil


class EncodedMessage:
Expand Down Expand Up @@ -36,7 +36,7 @@ class Message:

def __init__(self, content):
self.content = content
self.timestamp = now_as_utc_str()
self.timestamp = UtcTimeUtil.now_as_utc_str()

def json_serialize(self) -> dict:
return {
Expand Down Expand Up @@ -115,7 +115,7 @@ def set_command(self, command: Command) -> None:

class MessageParameterTuple:
"""
Class used to form a tuple of header and payload parameters
Class used to form a tuple of header and payload parameter
"""

def __init__(self, message_header_parameters, message_payload_parameters):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from typing import List

from agrirouter.api.enums import CapabilityType
from agrirouter.generated.messaging.request.payload.endpoint.capabilities_pb2 import CapabilitySpecification
from agrirouter.generated.messaging.request.payload.endpoint.subscription_pb2 import Subscription
from agrirouter.api.enums import CapabilityType


class SubscriptionItemBuilder:
Expand Down
25 changes: 0 additions & 25 deletions src/agrirouter/environments/environmental_services.py

This file was deleted.

10,512 changes: 5,243 additions & 5,269 deletions src/agrirouter/generated/messaging/request/payload/efdi/efdi_pb2.py

Large diffs are not rendered by default.

19 changes: 0 additions & 19 deletions src/agrirouter/messaging/certification.py

This file was deleted.

2 changes: 0 additions & 2 deletions src/agrirouter/messaging/clients/constants.py

This file was deleted.

78 changes: 0 additions & 78 deletions src/agrirouter/messaging/decode.py

This file was deleted.

Loading