diff --git a/CHANGELOG.md b/CHANGELOG.md index 316ade516..9fd441fcb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,13 +9,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added * Added ignore_pagination and details arguments for get_report [#163](https://github.com/greenbone/python-gvm/pull/163) * Introduced Gmpv9 for [GMP 9](https://docs.greenbone.net/API/GMP/gmp-9.0.html) - support [#157](https://github.com/greenbone/python-gvm/pull/157) + support [#157](https://github.com/greenbone/python-gvm/pull/157), + [#165](https://github.com/greenbone/python-gvm/pull/165) * Added new `create_audit` method, to create a task with the `usage_type` `audit` [#157](https://github.com/greenbone/python-gvm/pull/157) * Added new `create_policy` method, to create a config with the `usage_type` `policy` [#157](https://github.com/greenbone/python-gvm/pull/157) * Added the new methods `create_tls_certificate`, `modify_tls_certificate` and `clone_tls_certificate` to create, modify and copy TLS certificates [#157](https://github.com/greenbone/python-gvm/pull/157) * Added the new method `get_tls_certificates`, to request TLS certificates from the server [#157](https://github.com/greenbone/python-gvm/pull/157) ### Changed +* Use Gmpv9 in gvm.protocols.latest module [#165](https://github.com/greenbone/python-gvm/pull/165) * Added type `TLS_CERTIFICATE` to `EntityType` and `FilterType` [#157](https://github.com/greenbone/python-gvm/pull/157) * Changed the `DEFAULT_UNIX_SOCKET_PATH` [#119](https://github.com/greenbone/python-gvm/pull/162) diff --git a/docs/api/gmpv9.rst b/docs/api/gmpv9.rst new file mode 100644 index 000000000..87fced44d --- /dev/null +++ b/docs/api/gmpv9.rst @@ -0,0 +1,92 @@ +.. _gmpv9: + +GMP v9 +^^^^^^ + +.. automodule:: gvm.protocols.gmpv9 + +Enums +----- + +.. autoclass:: AlertCondition + :members: + :undoc-members: + +.. autoclass:: AlertEvent + :members: + :undoc-members: + +.. autoclass:: AlertMethod + :members: + :undoc-members: + +.. autoclass:: AliveTest + :members: + :undoc-members: + +.. autoclass:: AssetType + :members: + :undoc-members: + +.. autoclass:: CredentialFormat + :members: + :undoc-members: + +.. autoclass:: CredentialType + :members: + :undoc-members: + +.. autoclass:: EntityType + :members: + :undoc-members: + +.. autoclass:: FeedType + :members: + :undoc-members: + +.. autoclass:: FilterType + :members: + :undoc-members: + +.. autoclass:: HostsOrdering + :members: + :undoc-members: + +.. autoclass:: InfoType + :members: + :undoc-members: + +.. autoclass:: PermissionSubjectType + :members: + :undoc-members: + +.. autoclass:: ScannerType + :members: + :undoc-members: + +.. autoclass:: PortRangeType + :members: + :undoc-members: + +.. autoclass:: SeverityLevel + :members: + :undoc-members: + +.. autoclass:: SnmpAuthAlgorithm + :members: + :undoc-members: + +.. autoclass:: SnmpPrivacyAlgorithm + :members: + :undoc-members: + +.. autoclass:: TicketStatus + :members: + :undoc-members: + +Protocol +-------- + +.. autoclass:: Gmp + :members: + :inherited-members: diff --git a/docs/api/protocols.rst b/docs/api/protocols.rst index 2b8ff7237..fdce8e373 100644 --- a/docs/api/protocols.rst +++ b/docs/api/protocols.rst @@ -10,6 +10,7 @@ Protocols gmpv7 gmpv8 + gmpv9 ospv1 Dynamic diff --git a/gvm/protocols/__init__.py b/gvm/protocols/__init__.py index 302cfdea7..5778aecb4 100644 --- a/gvm/protocols/__init__.py +++ b/gvm/protocols/__init__.py @@ -18,12 +18,15 @@ """ Package for supported Greenbone Protocol versions. -Currently `GMP version 7`_, `GMP version 8`_ and `OSP version 1`_ are supported. +Currently `GMP version 7`_, `GMP version 8`_, `GMP version 9`_ and +`OSP version 1`_ are supported. .. _GMP version 7: https://docs.greenbone.net/API/GMP/gmp-7.0.html .. _GMP version 8: https://docs.greenbone.net/API/GMP/gmp-8.0.html +.. _GMP version 9: + https://docs.greenbone.net/API/GMP/gmp-9.0.html .. _OSP version 1: - https://docs.greenbone.net/API/OSP/osp-1.1.html + https://docs.greenbone.net/API/OSP/osp-1.2.html """ diff --git a/gvm/protocols/gmp.py b/gvm/protocols/gmp.py index 1e363e63d..0243ae20d 100644 --- a/gvm/protocols/gmp.py +++ b/gvm/protocols/gmp.py @@ -27,6 +27,7 @@ from gvm.protocols.gmpv7 import Gmp as Gmpv7 from gvm.protocols.gmpv8 import Gmp as Gmpv8 +from gvm.protocols.gmpv9 import Gmp as Gmpv9 from gvm.transforms import EtreeCheckCommandTransform @@ -46,9 +47,9 @@ class Gmp(GvmProtocol): from gvm.protocols.gmp import Gmp with Gmp(connection) as gmp: - # gmp can be an instance of gvm.protocols.gmpv7.Gmp or - # gvm.protocols.gmpv8.Gmp depending on the supported GMP - # version of the remote manager daemon + # gmp can be an instance of gvm.protocols.gmpv7.Gmp, + # gvm.protocols.gmpv8.Gmp or gvm.protocols.gmpv9.Gmp depending + # on the supported GMP version of the remote manager daemon resp = gmp.get_tasks() Attributes: @@ -91,8 +92,10 @@ def __enter__(self): if major_version == 7: gmp_class = Gmpv7 - elif major_version >= 8: + elif major_version == 8: gmp_class = Gmpv8 + elif major_version >= 9: + gmp_class = Gmpv9 else: raise GvmError( 'Remote manager daemon uses an unsupported version of GMP. ' diff --git a/gvm/protocols/gmpv9/__init__.py b/gvm/protocols/gmpv9/__init__.py index 841f62aa3..5158c161e 100644 --- a/gvm/protocols/gmpv9/__init__.py +++ b/gvm/protocols/gmpv9/__init__.py @@ -38,8 +38,7 @@ from gvm.protocols.gmpv7 import _is_list_like, _to_comma_list from . import types -from .types import HostsOrdering, EntityType, FilterType -from .types import get_entity_type_from_string, get_filter_type_from_string +from .types import * from .types import _UsageType as UsageType PROTOCOL_VERSION = (9,) @@ -96,7 +95,7 @@ def create_audit( The response. See :py:meth:`send_command` for details. """ - self.__create_task( + return self.__create_task( name=name, config_id=audit_id, target_id=target_id, @@ -115,6 +114,7 @@ def create_audit( def create_config(self, config_id: str, name: str) -> Any: """Create a new scan config + Arguments: config_id: UUID of the existing scan config name: Name of the new scan config @@ -122,15 +122,16 @@ def create_config(self, config_id: str, name: str) -> Any: Returns: The response. See :py:meth:`send_command` for details. """ - self.__create_config( + return self.__create_config( config_id=config_id, name=name, - usage_type=UsageType.SCAN, # pylint: disable=W0212 + usage_type=UsageType.SCAN, function=self.create_config.__name__, ) def create_policy(self, policy_id: str, name: str) -> Any: """Create a new policy config + Arguments: policy_id: UUID of the existing policy config name: Name of the new scan config @@ -138,10 +139,10 @@ def create_policy(self, policy_id: str, name: str) -> Any: Returns: The response. See :py:meth:`send_command` for details. """ - self.__create_config( + return self.__create_config( config_id=policy_id, name=name, - usage_type=UsageType.POLICY, # pylint: disable=W0212 + usage_type=UsageType.POLICY, function=self.create_policy.__name__, ) @@ -182,12 +183,12 @@ def create_task( Returns: The response. See :py:meth:`send_command` for details. """ - self.__create_task( + return self.__create_task( name=name, config_id=config_id, target_id=target_id, scanner_id=scanner_id, - usage_type=UsageType.SCAN, # pylint: disable=W0212 + usage_type=UsageType.SCAN, function=self.create_task.__name__, alterable=alterable, hosts_ordering=hosts_ordering, @@ -205,20 +206,19 @@ def create_tls_certificate( certificate: str, *, comment: Optional[str] = None, - copy: Optional[str] = None, trust: Optional[bool] = None ) -> Any: """Create a new TLS certificate Arguments: comment: Comment for the TLS certificate. - name: Name of the TLS certificate, defaulting to the MD5 fingerprint - copy: The UUID of an existing TLS certificate + name: Name of the TLS certificate, defaulting to the MD5 + fingerprint. trust: Whether the certificate is trusted. certificate: The Base64 encoded certificate data (x.509 DER or PEM). Returns: - The response. See :py:meth:`send_command`for details. + The response. See :py:meth:`send_command` for details. """ if not name: raise RequiredArgument( @@ -235,9 +235,6 @@ def create_tls_certificate( if comment: cmd.add_element("comment", comment) - if copy: - cmd.add_element("copy", copy) - cmd.add_element("name", name) cmd.add_element("certificate", certificate) @@ -340,7 +337,7 @@ def __create_task( config_id: str, target_id: str, scanner_id: str, - usage_type: types._UsageType, # pylint: disable=W0212 + usage_type: UsageType, function: str, *, alterable: Optional[bool] = None, @@ -449,11 +446,7 @@ def __create_task( return self._send_xml_command(cmd) def __create_config( - self, - config_id: str, - name: str, - usage_type: types._UsageType, # pylint: disable=W0212 - function: str, + self, config_id: str, name: str, usage_type: UsageType, function: str ) -> Any: if not name: raise RequiredArgument("{} requires name argument".format(function)) diff --git a/gvm/protocols/latest.py b/gvm/protocols/latest.py index b06c7a7da..037d46ade 100644 --- a/gvm/protocols/latest.py +++ b/gvm/protocols/latest.py @@ -27,14 +27,14 @@ :py:mod:`gvm.protocols`. Exports: - - :py:class:`gvm.protocols.gmpv8.Gmp` + - :py:class:`gvm.protocols.gmpv9.Gmp` - :py:class:`gvm.protocols.ospv1.Osp` .. _Greenbone Management Protocol: https://docs.greenbone.net/API/GMP/gmp.html """ -from .gmpv8 import ( +from .gmpv9 import ( Gmp, AlertCondition, AlertEvent, diff --git a/tests/protocols/gmpv9/test_create_tls_certificate.py b/tests/protocols/gmpv9/test_create_tls_certificate.py index 815cc2bb2..107ea8320 100644 --- a/tests/protocols/gmpv9/test_create_tls_certificate.py +++ b/tests/protocols/gmpv9/test_create_tls_certificate.py @@ -25,12 +25,11 @@ class GmpCreateTLSCertificateTestCase(Gmpv9TestCase): def test_create_tls_certificate(self): - self.gmp.create_tls_certificate('foo', 'c1', copy='a1', comment='bar') + self.gmp.create_tls_certificate('foo', 'c1', comment='bar') self.connection.send.has_been_called_with( '' 'bar' - 'a1' 'foo' 'c1' '' diff --git a/tests/protocols/test_latest.py b/tests/protocols/test_latest.py index 974564df7..09c5f54cb 100644 --- a/tests/protocols/test_latest.py +++ b/tests/protocols/test_latest.py @@ -23,7 +23,7 @@ class LatestProtocolsTestCase(unittest.TestCase): def test_gmp_version(self): - self.assertEqual(Gmp.get_protocol_version(), (8,)) + self.assertEqual(Gmp.get_protocol_version(), (9,)) def test_osp_version(self): self.assertEqual(Osp.get_protocol_version(), (1, 2))