guardicore / monkey

Infection Monkey - An open-source adversary emulation platform
https://www.guardicore.com/infectionmonkey/
GNU General Public License v3.0
6.63k stars 773 forks source link

Use SocketAddress to represent servers #2323

Closed mssalvatore closed 1 year ago

mssalvatore commented 1 year ago

Refactor

Component(s) to be refactored

Explanation

A more specific data type is needed to define an IP/Port combination representing the Island server. We'll define a new type called common.types.SocketAddress. It should look something like:

class SocketAddress(InfectionMonkeyBaseModel):
    ip: IPv4Address
    port: conint(ge=1, le=65535)

    def __str__(self):
        return f"{self.ip}:{self.port}"

Tasks

VakarisZ commented 1 year ago

This is what I've done already:

from ipaddress import IPv4Address

from common.base_models import InfectionMonkeyBaseModel

class SocketAddress(InfectionMonkeyBaseModel):
    """
    Combination of IP address and port

    Attributes:
        :param ip_address: IP address
        :param port: Port
    """
    ip_address: IPv4Address
    port: int