From 5b4b7f004926ae0d0a5490e9c04f61a211e47355 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Thu, 18 Aug 2022 10:44:32 -0400 Subject: [PATCH] Island: Use make_immutable_sequence() when constructing Machine --- monkey/monkey_island/cc/models/machine.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/monkey/monkey_island/cc/models/machine.py b/monkey/monkey_island/cc/models/machine.py index b6f7a04a4..25c830a24 100644 --- a/monkey/monkey_island/cc/models/machine.py +++ b/monkey/monkey_island/cc/models/machine.py @@ -1,11 +1,12 @@ from ipaddress import IPv4Interface -from typing import MutableSequence, Optional, Sequence +from typing import Optional, Sequence from pydantic import Field, PositiveInt, validator from common import OperatingSystems from .base_models import MutableBaseModel +from .transforms import make_immutable_sequence MachineID = PositiveInt @@ -18,9 +19,6 @@ class Machine(MutableBaseModel): operating_system_version: str hostname: str - @validator("network_interfaces", pre=True) - def _make_sequence_immutable(cls, sequence: Sequence): - if isinstance(sequence, MutableSequence): - return tuple(sequence) - - return sequence + _make_immutable_sequence = validator("network_interfaces", pre=True, allow_reuse=True)( + make_immutable_sequence + )