Skip to content

Commit

Permalink
Agent: Remove caching from get_agent_id()
Browse files Browse the repository at this point in the history
Issue #3119
PR #3162
  • Loading branch information
cakekoa committed Mar 28, 2023
1 parent eb3abd8 commit a1bfc9c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
19 changes: 6 additions & 13 deletions monkey/infection_monkey/utils/ids.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
from uuid import UUID, getnode, uuid4
from uuid import getnode, uuid4

from common.types import HardwareID
from common.types import AgentID, HardwareID

_id = None


def get_agent_id() -> UUID:
def get_agent_id() -> AgentID:
"""
Get the agent ID for the current running agent
Generate an agent ID
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.
Subsequent calls to this function will return a different ID.
"""
global _id
if _id is None:
_id = uuid4()

return _id
return uuid4()


def get_machine_id() -> HardwareID:
Expand Down
7 changes: 6 additions & 1 deletion monkey/tests/unit_tests/infection_monkey/utils/test_ids.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ def test_get_agent_id():
agent_id = get_agent_id()

assert isinstance(agent_id, UUID)
assert agent_id == get_agent_id()


def test_get_agent_id__is_unique():
agent_id = get_agent_id()

assert agent_id != get_agent_id()


def test_get_machine_id():
Expand Down

0 comments on commit a1bfc9c

Please sign in to comment.