forked from p34709852/monkey
Common: Add NetworkPort type
This commit is contained in:
parent
0207519343
commit
f62ab10d1c
|
@ -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:
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue