Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate make unique #156

Merged
merged 4 commits into from
Sep 19, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
71 changes: 71 additions & 0 deletions gvm/protocols/gmpv8/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
31 changes: 30 additions & 1 deletion tests/protocols/gmpv8/test_create_target.py
Original file line number Diff line number Diff line change
@@ -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
#
Expand All @@ -17,14 +17,43 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

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):
bjoernricks marked this conversation as resolved.
Show resolved Hide resolved

with warnings.catch_warnings():
warnings.simplefilter("ignore")

self.gmp.create_target(
'foo', make_unique=True, hosts=['foo', 'bar']
)

self.connection.send.has_been_called_with(
'<create_target>'
'<name>foo</name>'
'<hosts>foo,bar</hosts>'
'</create_target>'
)

self.gmp.create_target(
'foo', make_unique=False, hosts=['foo', 'bar']
)

self.connection.send.has_been_called_with(
'<create_target>'
'<name>foo</name>'
'<hosts>foo,bar</hosts>'
'</create_target>'
)

def test_create_target_missing_name(self):
with self.assertRaises(RequiredArgument):
self.gmp.create_target(None, hosts=['foo'])
Expand Down