diff --git a/CHANGELOG.md b/CHANGELOG.md index 01c6bb515..757be4319 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Removed +### Deprecated +* Mark make_unique argument of create_target Gmpv8 as deprecated and ignore it. + It is already ignored by gvmd with GMP 8 [PR 156](https://github.com/greenbone/python-gvm/pull/156) + [unreleased]: https://github.com/greenbone/python-gvm/compare/v1.0.0...master ## [1.0.0] - 2019-09-18 diff --git a/gvm/protocols/gmpv8/__init__.py b/gvm/protocols/gmpv8/__init__.py index c870d390a..dbbc4434f 100644 --- a/gvm/protocols/gmpv8/__init__.py +++ b/gvm/protocols/gmpv8/__init__.py @@ -582,6 +582,77 @@ def modify_tag( return self._send_xml_command(cmd) + def create_target( + self, + name: str, + *, + make_unique: Optional[bool] = None, + asset_hosts_filter: Optional[str] = None, + hosts: Optional[List[str]] = None, + comment: Optional[str] = None, + exclude_hosts: Optional[List[str]] = None, + ssh_credential_id: Optional[str] = None, + ssh_credential_port: Optional[int] = None, + smb_credential_id: Optional[str] = None, + esxi_credential_id: Optional[str] = None, + snmp_credential_id: Optional[str] = None, + alive_test: Optional[AliveTest] = None, + reverse_lookup_only: Optional[bool] = None, + reverse_lookup_unify: Optional[bool] = None, + port_range: Optional[str] = None, + port_list_id: Optional[str] = None + ) -> Any: + """Create a new target + + Arguments: + name: Name of the target + make_unique: Deprecated. Will be ignored. + asset_hosts_filter: Filter to select target host from assets hosts + hosts: List of hosts addresses to scan + exclude_hosts: List of hosts addresses to exclude from scan + comment: Comment for the target + ssh_credential_id: UUID of a ssh credential to use on target + ssh_credential_port: The port to use for ssh credential + smb_credential_id: UUID of a smb credential to use on target + snmp_credential_id: UUID of a snmp credential to use on target + esxi_credential_id: UUID of a esxi credential to use on target + alive_test: Which alive test to use + reverse_lookup_only: Whether to scan only hosts that have names + reverse_lookup_unify: Whether to scan only one IP when multiple IPs + have the same name. + port_range: Port range for the target + port_list_id: UUID of the port list to use on target + + Returns: + The response. See :py:meth:`send_command` for details. + """ + if make_unique is not None: + import warnings + + warnings.warn( + 'create_target make_unique argument is deprecated ' + 'and will be ignored.', + DeprecationWarning, + ) + + return super().create_target( + name, + asset_hosts_filter=asset_hosts_filter, + hosts=hosts, + comment=comment, + exclude_hosts=exclude_hosts, + ssh_credential_id=ssh_credential_id, + ssh_credential_port=ssh_credential_port, + smb_credential_id=smb_credential_id, + esxi_credential_id=esxi_credential_id, + snmp_credential_id=snmp_credential_id, + alive_test=alive_test, + reverse_lookup_only=reverse_lookup_only, + reverse_lookup_unify=reverse_lookup_unify, + port_range=port_range, + port_list_id=port_list_id, + ) + def clone_ticket(self, ticket_id: str) -> Any: """Clone an existing ticket diff --git a/tests/protocols/gmpv8/test_create_target.py b/tests/protocols/gmpv8/test_create_target.py index 533ebca6c..9d9d652b2 100644 --- a/tests/protocols/gmpv8/test_create_target.py +++ b/tests/protocols/gmpv8/test_create_target.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright (C) 2018 Greenbone Networks GmbH +# Copyright (C) 2019 Greenbone Networks GmbH # # SPDX-License-Identifier: GPL-3.0-or-later # @@ -17,14 +17,49 @@ # along with this program. If not, see . import unittest +import warnings from gvm.errors import RequiredArgument, InvalidArgument + from gvm.protocols.gmpv8 import AliveTest from . import Gmpv8TestCase class GmpCreateTargetCommandTestCase(Gmpv8TestCase): + def test_create_target_with_ignoring_make_unique(self): + + with warnings.catch_warnings(record=True) as warn: + warnings.simplefilter("always") + + self.gmp.create_target( + 'foo', make_unique=True, hosts=['foo', 'bar'] + ) + + self.connection.send.has_been_called_with( + '' + 'foo' + 'foo,bar' + '' + ) + + self.assertEqual(len(warn), 1) + self.assertTrue(issubclass(warn[-1].category, DeprecationWarning)) + + self.gmp.create_target( + 'foo', make_unique=False, hosts=['foo', 'bar'] + ) + + self.connection.send.has_been_called_with( + '' + 'foo' + 'foo,bar' + '' + ) + + self.assertEqual(len(warn), 2) + self.assertTrue(issubclass(warn[-1].category, DeprecationWarning)) + def test_create_target_missing_name(self): with self.assertRaises(RequiredArgument): self.gmp.create_target(None, hosts=['foo'])