diff --git a/gvm/protocols/gmp/_gmpnext.py b/gvm/protocols/gmp/_gmpnext.py index e9a1ccd3..4b3e4894 100644 --- a/gvm/protocols/gmp/_gmpnext.py +++ b/gvm/protocols/gmp/_gmpnext.py @@ -347,6 +347,18 @@ def get_agent_support_bundle( ) ) + def get_agent_inventory_token(self) -> T: + """Request a short-lived agent inventory token. + + The token is used to authenticate requests to the agent-control API + using Authorization: Bearer . + + The authenticated user must have the get_agents permission. + """ + return self._send_request_and_transform_response( + Agents.get_agent_inventory_token() + ) + def create_active_directory_credential( self, name: str, diff --git a/gvm/protocols/gmp/requests/next/_agents.py b/gvm/protocols/gmp/requests/next/_agents.py index df12f761..8d43d6a0 100644 --- a/gvm/protocols/gmp/requests/next/_agents.py +++ b/gvm/protocols/gmp/requests/next/_agents.py @@ -515,3 +515,17 @@ def get_agent_support_bundle( cmd.set_attribute("anonymized", to_bool(anonymized)) return cmd + + @classmethod + def get_agent_inventory_token(cls) -> Request: + """Request a short-lived agent inventory token. + + The token is used to authenticate requests to the agent-control API + using the Authorization: Bearer header. + + The authenticated user must have the get_agents permission. + + Returns: + Request: GMP request for an agent inventory token. + """ + return XmlCommand("get_agent_inventory_token") diff --git a/tests/protocols/gmpnext/entities/agents/test_get_agent_inventory_token.py b/tests/protocols/gmpnext/entities/agents/test_get_agent_inventory_token.py new file mode 100644 index 00000000..450242b6 --- /dev/null +++ b/tests/protocols/gmpnext/entities/agents/test_get_agent_inventory_token.py @@ -0,0 +1,12 @@ +# SPDX-FileCopyrightText: 2026 Greenbone AG +# +# SPDX-License-Identifier: GPL-3.0-or-later + + +class GmpGetAgentInventoryTokenTestMixin: + def test_get_agent_inventory_token(self): + self.gmp.get_agent_inventory_token() + + self.connection.send.has_been_called_with( + b"" + ) diff --git a/tests/protocols/gmpnext/entities/test_agents.py b/tests/protocols/gmpnext/entities/test_agents.py index 8299e549..c0ea1d98 100644 --- a/tests/protocols/gmpnext/entities/test_agents.py +++ b/tests/protocols/gmpnext/entities/test_agents.py @@ -7,6 +7,9 @@ from .agents.test_delete_agents import ( GmpDeleteAgentsTestMixin, ) +from .agents.test_get_agent_inventory_token import ( + GmpGetAgentInventoryTokenTestMixin, +) from .agents.test_get_agent_support_bundle import ( GmpGetAgentSupportBundleTestMixin, ) @@ -48,3 +51,9 @@ class GmpGetAgentSupportBundleTestCase( GmpGetAgentSupportBundleTestMixin, GMPTestCase ): pass + + +class GmpGetAgentInventoryTokenTestCase( + GmpGetAgentInventoryTokenTestMixin, GMPTestCase +): + pass