Skip to content

Commit 476c349

Browse files
ozgengreenbonebot
authored andcommitted
Change: Add update_to_latest to modify_agents
1 parent 7043850 commit 476c349

3 files changed

Lines changed: 22 additions & 0 deletions

File tree

gvm/protocols/gmp/_gmpnext.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ def modify_agents(
117117
agent_ids: list[EntityID],
118118
*,
119119
authorized: Optional[bool] = None,
120+
update_to_latest: Optional[bool] = None,
120121
config: Optional[Mapping[str, Any]] = None,
121122
comment: Optional[str] = None,
122123
) -> T:
@@ -126,13 +127,15 @@ def modify_agents(
126127
Args:
127128
agent_ids: List of agent UUIDs to modify.
128129
authorized: Whether the agent is authorized.
130+
update_to_latest: Whether the agent is allowed to update to latest automatically.
129131
config: Nested config for Agent Controller.
130132
comment: Optional comment for the change.
131133
"""
132134
return self._send_request_and_transform_response(
133135
Agents.modify_agents(
134136
agent_ids=agent_ids,
135137
authorized=authorized,
138+
update_to_latest=update_to_latest,
136139
config=config,
137140
comment=comment,
138141
)

gvm/protocols/gmp/requests/next/_agents.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ def modify_agents(
188188
agent_ids: list[EntityID],
189189
*,
190190
authorized: Optional[bool] = None,
191+
update_to_latest: Optional[bool] = None,
191192
config: Optional[Mapping[str, Any]] = None,
192193
comment: Optional[str] = None,
193194
) -> Request:
@@ -197,6 +198,7 @@ def modify_agents(
197198
Args:
198199
agent_ids: List of agent UUIDs to modify.
199200
authorized: Whether the agent is authorized.
201+
update_to_latest: Whether the agent is allowed to update to latest automatically.
200202
config: Nested config, e.g.:
201203
{
202204
"agent_control": {
@@ -233,6 +235,9 @@ def modify_agents(
233235
if authorized is not None:
234236
cmd.add_element("authorized", to_bool(authorized))
235237

238+
if update_to_latest is not None:
239+
cmd.add_element("update_to_latest", to_bool(update_to_latest))
240+
236241
if config is not None:
237242
cls._validate_agent_config(
238243
config, caller=cls.modify_agents.__name__

tests/protocols/gmpnext/entities/agents/test_modify_agents.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@ def test_modify_agents_with_authorized_only(self):
2727
b"</modify_agent>"
2828
)
2929

30+
def test_modify_agents_with_update_to_latest_only(self):
31+
self.gmp.modify_agents(
32+
agent_ids=["agent-123", "agent-456"], update_to_latest=True
33+
)
34+
35+
self.connection.send.has_been_called_with(
36+
b"<modify_agent>"
37+
b'<agents><agent id="agent-123"/><agent id="agent-456"/></agents>'
38+
b"<update_to_latest>1</update_to_latest>"
39+
b"</modify_agent>"
40+
)
41+
3042
def test_modify_agents_with_full_config_and_comment(self):
3143
cfg = {
3244
"agent_control": {
@@ -48,6 +60,7 @@ def test_modify_agents_with_full_config_and_comment(self):
4860
self.gmp.modify_agents(
4961
agent_ids=["agent-123", "agent-456"],
5062
authorized=True,
63+
update_to_latest=True,
5164
config=cfg,
5265
comment="Updated agents",
5366
)
@@ -56,6 +69,7 @@ def test_modify_agents_with_full_config_and_comment(self):
5669
b"<modify_agent>"
5770
b'<agents><agent id="agent-123"/><agent id="agent-456"/></agents>'
5871
b"<authorized>1</authorized>"
72+
b"<update_to_latest>1</update_to_latest>"
5973
b"<config>"
6074
b"<agent_control>"
6175
b"<retry>"

0 commit comments

Comments
 (0)