Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions gvm/protocols/gmp/_gmpnext.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def modify_agents(
agent_ids: list[EntityID],
*,
authorized: Optional[bool] = None,
update_to_latest: Optional[bool] = None,
config: Optional[Mapping[str, Any]] = None,
comment: Optional[str] = None,
) -> T:
Expand All @@ -126,13 +127,15 @@ def modify_agents(
Args:
agent_ids: List of agent UUIDs to modify.
authorized: Whether the agent is authorized.
update_to_latest: Whether the agent is allowed to update to latest automatically.
config: Nested config for Agent Controller.
comment: Optional comment for the change.
"""
return self._send_request_and_transform_response(
Agents.modify_agents(
agent_ids=agent_ids,
authorized=authorized,
update_to_latest=update_to_latest,
config=config,
comment=comment,
)
Expand Down
5 changes: 5 additions & 0 deletions gvm/protocols/gmp/requests/next/_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ def modify_agents(
agent_ids: list[EntityID],
*,
authorized: Optional[bool] = None,
update_to_latest: Optional[bool] = None,
config: Optional[Mapping[str, Any]] = None,
comment: Optional[str] = None,
) -> Request:
Expand All @@ -197,6 +198,7 @@ def modify_agents(
Args:
agent_ids: List of agent UUIDs to modify.
authorized: Whether the agent is authorized.
update_to_latest: Whether the agent is allowed to update to latest automatically.
config: Nested config, e.g.:
{
"agent_control": {
Expand Down Expand Up @@ -233,6 +235,9 @@ def modify_agents(
if authorized is not None:
cmd.add_element("authorized", to_bool(authorized))

if update_to_latest is not None:
cmd.add_element("update_to_latest", to_bool(update_to_latest))

if config is not None:
cls._validate_agent_config(
config, caller=cls.modify_agents.__name__
Expand Down
14 changes: 14 additions & 0 deletions tests/protocols/gmpnext/entities/agents/test_modify_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ def test_modify_agents_with_authorized_only(self):
b"</modify_agent>"
)

def test_modify_agents_with_update_to_latest_only(self):
self.gmp.modify_agents(
agent_ids=["agent-123", "agent-456"], update_to_latest=True
)

self.connection.send.has_been_called_with(
b"<modify_agent>"
b'<agents><agent id="agent-123"/><agent id="agent-456"/></agents>'
b"<update_to_latest>1</update_to_latest>"
b"</modify_agent>"
)

def test_modify_agents_with_full_config_and_comment(self):
cfg = {
"agent_control": {
Expand All @@ -48,6 +60,7 @@ def test_modify_agents_with_full_config_and_comment(self):
self.gmp.modify_agents(
agent_ids=["agent-123", "agent-456"],
authorized=True,
update_to_latest=True,
config=cfg,
comment="Updated agents",
)
Expand All @@ -56,6 +69,7 @@ def test_modify_agents_with_full_config_and_comment(self):
b"<modify_agent>"
b'<agents><agent id="agent-123"/><agent id="agent-456"/></agents>'
b"<authorized>1</authorized>"
b"<update_to_latest>1</update_to_latest>"
b"<config>"
b"<agent_control>"
b"<retry>"
Expand Down