Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
bjoernricks authored Sep 25, 2019
2 parents 99c6091 + a497be9 commit 05575b2
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ output-format=text
# Tells whether to display a full report or only the messages
reports=no

# Deativate the evaluation score.
# Deactivate the evaluation score.
score=no


Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,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
37 changes: 36 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,49 @@
# 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):

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(
'<create_target>'
'<name>foo</name>'
'<hosts>foo,bar</hosts>'
'</create_target>'
)

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(
'<create_target>'
'<name>foo</name>'
'<hosts>foo,bar</hosts>'
'</create_target>'
)

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'])
Expand Down

0 comments on commit 05575b2

Please sign in to comment.