From 9fc91239f2abe52b4fc8b059aa42728c8bba76fc Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Wed, 14 Sep 2022 12:59:44 -0400 Subject: [PATCH] Agent: Use private module variable for ID caching mypy complains about setting an attribute on the function object. Using `global _id` accomplishes the same thing and doesn't upset mypy --- monkey/infection_monkey/utils/ids.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/monkey/infection_monkey/utils/ids.py b/monkey/infection_monkey/utils/ids.py index a53672b93..fc53a5147 100644 --- a/monkey/infection_monkey/utils/ids.py +++ b/monkey/infection_monkey/utils/ids.py @@ -2,6 +2,8 @@ from uuid import UUID, getnode, uuid4 from common.types import HardwareID +_id = None + def get_agent_id() -> UUID: """ @@ -10,13 +12,11 @@ def get_agent_id() -> UUID: Each time an agent process starts, the return value of this function will be unique. Subsequent calls to this function from within the same process will have the same return value. """ - if get_agent_id._id is None: - get_agent_id._id = uuid4() + global _id + if _id is None: + _id = uuid4() - return get_agent_id._id - - -get_agent_id._id = None + return _id def get_machine_id() -> HardwareID: