Agent: Fix mypy issues in IslandAPIClient

This commit is contained in:
Kekoa Kaaikala 2022-09-21 17:54:33 +00:00
parent fc82715262
commit ccfc41fc2f
2 changed files with 6 additions and 7 deletions

View File

@ -94,7 +94,7 @@ class HTTPIslandAPIClient(IIslandAPIClient):
return response.content return response.content
@handle_island_errors @handle_island_errors
def get_agent_binary(self, operating_system: OperatingSystem): def get_agent_binary(self, operating_system: OperatingSystem) -> bytes:
os_name = operating_system.value os_name = operating_system.value
response = requests.get( # noqa: DUO123 response = requests.get( # noqa: DUO123
f"{self._api_url}/agent-binaries/{os_name}", f"{self._api_url}/agent-binaries/{os_name}",
@ -106,7 +106,7 @@ class HTTPIslandAPIClient(IIslandAPIClient):
return response.content return response.content
@handle_island_errors @handle_island_errors
def send_events(self, events: Sequence[JSONSerializable]): def send_events(self, events: Sequence[AbstractAgentEvent]):
response = requests.post( # noqa: DUO123 response = requests.post( # noqa: DUO123
f"{self._api_url}/agent-events", f"{self._api_url}/agent-events",
json=self._serialize_events(events), json=self._serialize_events(events),
@ -132,9 +132,9 @@ class HTTPIslandAPIClient(IIslandAPIClient):
class HTTPIslandAPIClientFactory(AbstractIslandAPIClientFactory): class HTTPIslandAPIClientFactory(AbstractIslandAPIClientFactory):
def __init__( def __init__(
self, self,
agent_event_serializer_registry: AgentEventSerializerRegistry = None, agent_event_serializer_registry: AgentEventSerializerRegistry,
): ):
self._agent_event_serializer_registry = agent_event_serializer_registry self._agent_event_serializer_registry = agent_event_serializer_registry
def create_island_api_client(self): def create_island_api_client(self) -> IIslandAPIClient:
return HTTPIslandAPIClient(self._agent_event_serializer_registry) return HTTPIslandAPIClient(self._agent_event_serializer_registry)

View File

@ -1,5 +1,5 @@
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from typing import Optional, Sequence from typing import Sequence
from common import OperatingSystem from common import OperatingSystem
from common.agent_events import AbstractAgentEvent from common.agent_events import AbstractAgentEvent
@ -60,7 +60,7 @@ class IIslandAPIClient(ABC):
""" """
@abstractmethod @abstractmethod
def get_agent_binary(self, operating_system: OperatingSystem) -> Optional[bytes]: def get_agent_binary(self, operating_system: OperatingSystem) -> bytes:
""" """
Get an agent binary for the given OS from the island Get an agent binary for the given OS from the island
@ -74,7 +74,6 @@ class IIslandAPIClient(ABC):
:raises IslandAPITimeoutError: If a timeout occurs while attempting to connect to the island :raises IslandAPITimeoutError: If a timeout occurs while attempting to connect to the island
:raises IslandAPIError: If an unexpected error occurs while attempting to retrieve the :raises IslandAPIError: If an unexpected error occurs while attempting to retrieve the
agent binary agent binary
""" """
@abstractmethod @abstractmethod