Common: Add NetworkPort type

This commit is contained in:
Ilija Lazoroski 2022-09-29 18:33:02 +02:00 committed by Mike Salvatore
parent 0207519343
commit f62ab10d1c
2 changed files with 16 additions and 2 deletions

View File

@ -6,7 +6,7 @@ from ipaddress import IPv4Address
from typing import Optional from typing import Optional
from uuid import UUID from uuid import UUID
from pydantic import PositiveInt, conint from pydantic import ConstrainedInt, PositiveInt
from typing_extensions import TypeAlias from typing_extensions import TypeAlias
from common import OperatingSystem from common import OperatingSystem
@ -18,6 +18,18 @@ HardwareID: TypeAlias = PositiveInt
MachineID: 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 @dataclass
class PingScanData: class PingScanData:
response_received: bool response_received: bool
@ -38,7 +50,7 @@ class PortStatus(Enum):
class SocketAddress(InfectionMonkeyBaseModel): class SocketAddress(InfectionMonkeyBaseModel):
ip: IPv4Address ip: IPv4Address
port: conint(ge=1, le=65535) # type: ignore[valid-type] port: NetworkPort
@classmethod @classmethod
def from_string(cls, address_str: str) -> SocketAddress: def from_string(cls, address_str: str) -> SocketAddress:

View File

@ -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.repository.zero_trust.IFindingRepository import IFindingRepository
from monkey_island.cc.services import AgentSignalsService 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) 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) 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) fake_monkey_dir_path # unused variable (monkey/tests/infection_monkey/post_breach/actions/test_users_custom_pba.py:57)