Skip to content

Commit

Permalink
Refactor messaging services and minor changes in file structures
Browse files Browse the repository at this point in the history
Made several changes in messaging services including restructuring and moving certain classes to align with design patterns. Also made minor changes and updates in file structures of various test scripts and source files. Improved unified decoding strategy with EncodingService class.
  • Loading branch information
saschadoemer committed May 2, 2024
1 parent 0263758 commit dadbcb1
Show file tree
Hide file tree
Showing 27 changed files with 54 additions and 279 deletions.
8 changes: 4 additions & 4 deletions example_script.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import time
import agrirouter as ar
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.service.messaging import QueryHeaderService, ListEndpointsService, CapabilitiesService, \
SubscriptionService
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.service.messaging import HttpMessagingService, MqttMessagingService
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.service.onboarding import OnboardResponse

public_key = """-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzGt41/+kSOTlO1sJvLIN
Expand Down
2 changes: 1 addition & 1 deletion src/agrirouter/service/certification.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import tempfile

from agrirouter.service.dto.response.onboarding import OnboardResponse
from agrirouter.service.dto.response.messaging import OnboardResponse


class CertificationService:
Expand Down
2 changes: 1 addition & 1 deletion src/agrirouter/service/client/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from urllib.parse import urlparse

from agrirouter.service.certification import CertificationService
from agrirouter.service.dto.response.onboarding import OnboardResponse
from agrirouter.service.dto.response.messaging import OnboardResponse


class HttpClient:
Expand Down
217 changes: 0 additions & 217 deletions src/agrirouter/service/dto/messaging.py

This file was deleted.

2 changes: 1 addition & 1 deletion src/agrirouter/service/messaging/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def encode(parameters: CloudOffboardParameters) -> EncodedMessage:
value=offboarding_request.SerializeToString()
)

message_content = encode_message(message_header_parameters, message_payload_parameters)
message_content = EncodingService.encode_message(message_header_parameters, message_payload_parameters)
encoded_message = EncodedMessage(
id_=UUIDUtil.new_uuid(),
content=message_content
Expand Down
2 changes: 1 addition & 1 deletion src/agrirouter/service/messaging/encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from agrirouter.api.messages import MessageParameterTuple
from agrirouter.generated.commons.chunk_pb2 import ChunkComponent
from agrirouter.generated.messaging.request.request_pb2 import RequestEnvelope, RequestPayloadWrapper
from agrirouter.service.dto.response.onboarding import OnboardResponse
from agrirouter.service.dto.response.messaging import OnboardResponse
from agrirouter.service.messaging.sequence_numbers import SequenceNumberService
from agrirouter.service.parameter.messaging import MessageHeaderParameters, MessagePayloadParameters
from agrirouter.util.utc_time_util import UtcTimeUtil
Expand Down
3 changes: 1 addition & 2 deletions src/agrirouter/service/messaging/message_sending.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@
from agrirouter.generated.messaging.request.payload.feed.feed_requests_pb2 import MessageConfirm, MessageDelete, \
MessageQuery
from agrirouter.generated.messaging.request.request_pb2 import RequestEnvelope
from agrirouter.service.dto.messaging import SendMessageParameters, ChunkedMessageParameters
from agrirouter.service.messaging.common import AbstractService
from agrirouter.service.messaging.encoding import EncodingService
from agrirouter.service.parameter.messaging import MessageHeaderParameters, MessagePayloadParameters, \
CapabilitiesParameters, FeedConfirmParameters, FeedDeleteParameters, ListEndpointsParameters, \
SubscriptionParameters, QueryHeaderParameters, QueryMessageParameters, ImageParameters, TaskParameters, \
EfdiParameters
EfdiParameters, SendMessageParameters, ChunkedMessageParameters
from agrirouter.util.type_url import TypeUrl
from agrirouter.util.uuid_util import UUIDUtil

Expand Down
5 changes: 2 additions & 3 deletions src/agrirouter/service/onboarding.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import requests
from agrirouter.service.onboarding.request_headers import SoftwareOnboardingHeader

from agrirouter.api.env import BaseEnvironment
from agrirouter.api.env import EnvironmentalService
from agrirouter.api.exceptions import UnexpectedErrorDuringOnboarding, RequestNotSigned
from agrirouter.service.dto.request.onboarding import OnboardRequest, SoftwareOnboardingBody
from agrirouter.service.dto.response.onboarding import VerificationResponse, OnboardResponse
from agrirouter.service.dto.request.onboarding import OnboardRequest, SoftwareOnboardingBody, SoftwareOnboardingHeader
from agrirouter.service.dto.response.messaging import VerificationResponse, OnboardResponse
from agrirouter.service.parameter.onboarding import OnboardParameters


Expand Down
4 changes: 2 additions & 2 deletions src/agrirouter/service/parameter/messaging.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from copy import deepcopy
from typing import List

from agrirouter.api.messages import EncodedMessage
from agrirouter.generated.commons.chunk_pb2 import ChunkComponent
from agrirouter.generated.commons.message_pb2 import Metadata
from agrirouter.generated.messaging.request.payload.endpoint.capabilities_pb2 import CapabilitySpecification
from agrirouter.generated.messaging.request.payload.endpoint.subscription_pb2 import Subscription
from agrirouter.generated.messaging.request.payload.feed.feed_requests_pb2 import ValidityPeriod
from agrirouter.service.dto.messaging import MessageParameters
from agrirouter.service.dto.response.onboarding import BaseOnboardingResponse
from agrirouter.service.dto.response.messaging import BaseOnboardingResponse


class Parameters:
Expand Down
2 changes: 1 addition & 1 deletion tests/agrirouter/common/onboarding.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from agrirouter.service.dto.response.messaging import OnboardResponse
from agrirouter.service.onboarding import OnboardParameters
from agrirouter.service.onboarding import OnboardResponse
from agrirouter.service.onboarding import OnboardingService
from tests.agrirouter.data.applications import CommunicationUnit

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os

import tests
from agrirouter.service.onboarding import OnboardResponse
from agrirouter.service.dto.response.messaging import OnboardResponse


def read_onboard_response(identifier: str) -> OnboardResponse:
Expand Down
6 changes: 3 additions & 3 deletions tests/agrirouter/fixtures/update_http_onboard_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
from agrirouter.api.enums import CertificateTypes, Gateways
from agrirouter.api.env import Qa
from agrirouter.generated.messaging.request.payload.endpoint.capabilities_pb2 import CapabilitySpecification
from agrirouter.service.messaging import CapabilitiesService
from agrirouter.service.messaging import HttpMessagingService
from agrirouter.service.messaging.http import FetchMessageService
from agrirouter.service.messaging.common import HttpMessagingService
from agrirouter.service.messaging.http.message_fetching import FetchMessageService
from agrirouter.service.messaging.message_sending import CapabilitiesService
from agrirouter.service.onboarding import OnboardResponse
from agrirouter.service.parameter.messaging import CapabilitiesParameters
from agrirouter.util.uuid_util import UUIDUtil
Expand Down
4 changes: 2 additions & 2 deletions tests/agrirouter/fixtures/update_mqtt_onboard_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from agrirouter.api.env import Qa
from agrirouter.api.messages import OutboxMessage
from agrirouter.generated.messaging.request.payload.endpoint.capabilities_pb2 import CapabilitySpecification
from agrirouter.service.messaging import CapabilitiesService
from agrirouter.service.messaging import MqttMessagingService
from agrirouter.service.messaging.common import MqttMessagingService
from agrirouter.service.messaging.decoding import DecodingService
from agrirouter.service.messaging.message_sending import CapabilitiesService
from agrirouter.service.messaging.sequence_numbers import SequenceNumberService
from agrirouter.service.parameter.messaging import CapabilitiesParameters
from agrirouter.util.uuid_util import UUIDUtil
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
"""Test src/env/environmental_services.py"""

from src.agrirouter.env.environmental_services import EnvironmentalService

from src.agrirouter.api.env import Qa, Production
from src.agrirouter.api.env import Qa, Production, EnvironmentalService


def test_arclient_set_env():
Expand Down
2 changes: 1 addition & 1 deletion tests/agrirouter/internal/messaging/test_decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_decode_details():
json_response = json.loads(MESSAGING_RESULT)
message = DecodingService.decode_response(json_response[0]["command"]["message"].encode())
details = message.response_payload.details
decoded_details = decode_details(details)
decoded_details = DecodingService.decode_details(details)

assert decoded_details.endpoints
assert len(decoded_details.endpoints) == 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import pytest

from agrirouter.api.exceptions import WrongField
from agrirouter.service.onboarding import ConnectionCriteria, Authentication, ErrorResponse
from agrirouter.service.dto.response.onboarding import Authentication, ConnectionCriteria, ErrorResponse


class TestConnectionCriteria:
Expand Down
Loading

0 comments on commit dadbcb1

Please sign in to comment.