Agent: Add get_agent_id()

This commit is contained in:
Mike Salvatore 2022-08-22 14:02:18 -04:00
parent 78f792aee9
commit 160d2d11cf
2 changed files with 27 additions and 0 deletions

View File

@ -0,0 +1,17 @@
from uuid import UUID, uuid4
def get_agent_id() -> UUID:
"""
Get the agent ID for the current running agent
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()
return get_agent_id._id
get_agent_id._id = None

View File

@ -0,0 +1,10 @@
from uuid import UUID
from infection_monkey.utils.agent_id import get_agent_id
def test_get_agent_id():
agent_id = get_agent_id()
assert isinstance(agent_id, UUID)
assert agent_id == get_agent_id()