From f62ab10d1cb380a10d48b8d2042b776ef9fd41b8 Mon Sep 17 00:00:00 2001 From: Ilija Lazoroski Date: Thu, 29 Sep 2022 18:33:02 +0200 Subject: [PATCH] Common: Add NetworkPort type --- monkey/common/types.py | 16 ++++++++++++++-- vulture_allowlist.py | 2 ++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/monkey/common/types.py b/monkey/common/types.py index 439f07c63..b4503afc2 100644 --- a/monkey/common/types.py +++ b/monkey/common/types.py @@ -6,7 +6,7 @@ from ipaddress import IPv4Address from typing import Optional from uuid import UUID -from pydantic import PositiveInt, conint +from pydantic import ConstrainedInt, PositiveInt from typing_extensions import TypeAlias from common import OperatingSystem @@ -18,6 +18,18 @@ HardwareID: TypeAlias = PositiveInt MachineID: TypeAlias = PositiveInt +class NetworkPort(ConstrainedInt): + """ + Define network port as constrainer integer. + + To define a default value with this type: + port: NetworkPort = typing.cast(NetworkPort, 1000) + """ + + ge = 1 + le = 65535 + + @dataclass class PingScanData: response_received: bool @@ -38,7 +50,7 @@ class PortStatus(Enum): class SocketAddress(InfectionMonkeyBaseModel): ip: IPv4Address - port: conint(ge=1, le=65535) # type: ignore[valid-type] + port: NetworkPort @classmethod def from_string(cls, address_str: str) -> SocketAddress: diff --git a/vulture_allowlist.py b/vulture_allowlist.py index 699951b10..fd4e3fbf3 100644 --- a/vulture_allowlist.py +++ b/vulture_allowlist.py @@ -29,6 +29,8 @@ from monkey_island.cc.repository.zero_trust.IEventRepository import IEventReposi from monkey_island.cc.repository.zero_trust.IFindingRepository import IFindingRepository from monkey_island.cc.services import AgentSignalsService +ge # unused vairable (monkey/common/types.py:28) +le # unused variable (monkey/common/types.py:29) fake_monkey_dir_path # unused variable (monkey/tests/infection_monkey/post_breach/actions/test_users_custom_pba.py:37) set_os_linux # unused variable (monkey/tests/infection_monkey/post_breach/actions/test_users_custom_pba.py:37) fake_monkey_dir_path # unused variable (monkey/tests/infection_monkey/post_breach/actions/test_users_custom_pba.py:57)