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
This commit is contained in:
Mike Salvatore 2022-09-14 12:59:44 -04:00
parent 8faf8de4dd
commit 9fc91239f2
1 changed files with 6 additions and 6 deletions

View File

@ -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: