Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 6 additions & 2 deletions gvm/protocols/gmp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,21 @@
In most circumstances you will want to use the :class:`GMP` class which
dynamically selects the supported GMP protocol of the remote manager daemon.

If you need to use a specific GMP version, you can use the :class:`GMPv224` or
:class:`GMPv225` classes.
If you need to use a specific GMP version, you can use the :class:`GMPv224`,
:class:`GMPv225`, :class:`GMPv226` or :class:`GMPv227` classes.

* :class:`GMP` - Dynamically select supported GMP protocol of the remote manager daemon.
* :class:`GMPv224` - GMP version 22.4
* :class:`GMPv225` - GMP version 22.5
* :class:`GMPv226` - GMP version 22.6
* :class:`GMPv227` - GMP version 22.7
"""

from ._gmp import GMP
from ._gmp224 import GMPv224
from ._gmp225 import GMPv225
from ._gmp226 import GMPv226
from ._gmp227 import GMPv227

Gmp = GMP # for backwards compatibility

Expand All @@ -29,4 +32,5 @@
"GMPv224",
"GMPv225",
"GMPv226",
"GMPv227",
)
10 changes: 6 additions & 4 deletions gvm/protocols/gmp/_gmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
from ._gmp224 import GMPv224
from ._gmp225 import GMPv225
from ._gmp226 import GMPv226
from ._gmp227 import GMPv227
from .requests import Version

SUPPORTED_GMP_VERSIONS = Union[GMPv224[T], GMPv225[T], GMPv226[T]]
_SUPPORTED_GMP_VERSION_STRINGS = ["22.4", "22.5", "22.6"]
SUPPORTED_GMP_VERSIONS = Union[GMPv224[T], GMPv225[T], GMPv226[T], GMPv227[T]]
_SUPPORTED_GMP_VERSION_STRINGS = ["22.4", "22.5", "22.6", "22.7"]


class GMP(GvmProtocol[T]):
Expand All @@ -36,8 +37,9 @@ class GMP(GvmProtocol[T]):
with GMP(connection) as gmp:
# gmp can be an instance of
# gvm.protocols.gmp.GMPv224,
# gvm.protocols.gmp.GMPv225
# or gvm.protocols.gmp.GMPv226
# gvm.protocols.gmp.GMPv225,
# gvm.protocols.gmp.GMPv226,
# or gvm.protocols.gmp.GMPv227
# depending on the supported GMP version of the remote manager daemon
resp = gmp.get_tasks()

Expand Down
190 changes: 190 additions & 0 deletions gvm/protocols/gmp/_gmp227.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
# SPDX-FileCopyrightText: 2025 Greenbone AG
#
# SPDX-License-Identifier: GPL-3.0-or-later

"""
Greenbone Management Protocol (GMP) version 22.7
"""

from typing import Optional, Union

from .._protocol import T
from ._gmp226 import GMPv226
from .requests.v227 import (
EntityID,
Scanners,
ScannerType,
)


class GMPv227(GMPv226[T]):
"""
A class implementing the Greenbone Management Protocol (GMP) version 22.7

Example:

.. code-block:: python

from gvm.protocols.gmp import GMPv227 as GMP

with GMP(connection) as gmp:
resp = gmp.get_tasks()
"""

@staticmethod
def get_protocol_version() -> tuple[int, int]:
return (22, 7)

def create_scanner( # type:ignore[override]
self,
name: str,
host: str,
port: Union[str, int],
scanner_type: ScannerType,
credential_id: str,
*,
ca_pub: Optional[str] = None,
comment: Optional[str] = None,
relay_host: Optional[str] = None,
relay_port: Optional[Union[str, int]] = None,
) -> T:
"""Create a new scanner

Args:
name: Name of the new scanner
host: Hostname or IP address of the scanner
port: Port of the scanner
scanner_type: Type of the scanner
credential_id: UUID of client certificate credential for the
scanner
ca_pub: Certificate of CA to verify scanner certificate
comment: Comment for the scanner
relay_host: Hostname or IP address of the scanner relay
relay_port: Port of the scanner relay
"""
return self._send_request_and_transform_response(
Scanners.create_scanner(
name,
host,
port,
scanner_type,
credential_id,
ca_pub=ca_pub,
comment=comment,
relay_host=relay_host,
relay_port=relay_port,
)
)

def modify_scanner( # type:ignore[override]
self,
scanner_id: EntityID,
*,
name: Optional[str] = None,
host: Optional[str] = None,
port: Optional[int] = None,
scanner_type: Optional[ScannerType] = None,
credential_id: Optional[EntityID] = None,
ca_pub: Optional[str] = None,
comment: Optional[str] = None,
relay_host: Optional[str] = None,
relay_port: Optional[Union[str, int]] = None,
) -> T:
"""Modify an existing scanner

Args:
scanner_id: UUID of the scanner to modify
name: New name of the scanner
host: New hostname or IP address of the scanner
port: New port of the scanner
scanner_type: New type of the scanner
credential_id: New UUID of client certificate credential for the
scanner
ca_pub: New certificate of CA to verify scanner certificate
comment: New comment for the scanner
relay_host: Hostname or IP address of the scanner relay
relay_port: Port of the scanner relay
"""
return self._send_request_and_transform_response(
Scanners.modify_scanner(
scanner_id,
name=name,
host=host,
port=port,
scanner_type=scanner_type,
credential_id=credential_id,
ca_pub=ca_pub,
comment=comment,
relay_host=relay_host,
relay_port=relay_port,
)
)

def get_scanners(
self,
*,
filter_string: Optional[str] = None,
filter_id: Optional[EntityID] = None,
trash: Optional[bool] = None,
details: Optional[bool] = None,
) -> T:
"""Request a list of scanners

Args:
filter_string: Filter term to use for the query
filter_id: UUID of an existing filter to use for the query
trash: Whether to get the trashcan scanners instead
details: Whether to include extra details like tasks using this
scanner
"""
return self._send_request_and_transform_response(
Scanners.get_scanners(
filter_string=filter_string,
filter_id=filter_id,
trash=trash,
details=details,
)
)

def get_scanner(self, scanner_id: EntityID) -> T:
"""Request a single scanner

Args:
scanner_id: UUID of an existing scanner
"""
return self._send_request_and_transform_response(
Scanners.get_scanner(scanner_id)
)

def verify_scanner(self, scanner_id: EntityID) -> T:
"""Verify an existing scanner

Args:
scanner_id: UUID of an existing scanner
"""
return self._send_request_and_transform_response(
Scanners.verify_scanner(scanner_id)
)

def clone_scanner(self, scanner_id: EntityID) -> T:
"""Clone an existing scanner

Args:
scanner_id: UUID of an existing scanner
"""
return self._send_request_and_transform_response(
Scanners.clone_scanner(scanner_id)
)

def delete_scanner(
self, scanner_id: EntityID, ultimate: Optional[bool] = False
) -> T:
"""Delete an existing scanner

Args:
scanner_id: UUID of an existing scanner
ultimate: Whether to remove entirely, or to the trashcan.
"""
return self._send_request_and_transform_response(
Scanners.delete_scanner(scanner_id, ultimate=ultimate)
)
151 changes: 151 additions & 0 deletions gvm/protocols/gmp/requests/v227/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
# SPDX-FileCopyrightText: 2025 Greenbone AG
#
# SPDX-License-Identifier: GPL-3.0-or-later

"""
GMP Request implementations for GMP version 22.7.
"""

from gvm.protocols.gmp.requests.v227._scanners import Scanners, ScannerType

from .._entity_id import EntityID
from .._version import Version
from ..v226 import (
Aggregates,
AggregateStatistic,
AlertCondition,
AlertEvent,
AlertMethod,
Alerts,
AliveTest,
AuditReports,
Audits,
Authentication,
CertBundAdvisories,
Cpes,
CredentialFormat,
Credentials,
CredentialType,
Cves,
DfnCertAdvisories,
EntityType,
Feed,
FeedType,
Filters,
FilterType,
Groups,
Help,
HelpFormat,
Hosts,
HostsOrdering,
InfoType,
Notes,
Nvts,
OperatingSystems,
Overrides,
Permissions,
PermissionSubjectType,
Policies,
PortLists,
PortRangeType,
ReportConfigParameter,
ReportConfigs,
ReportFormats,
ReportFormatType,
Reports,
ResourceNames,
ResourceType,
Results,
Roles,
ScanConfigs,
Schedules,
SecInfo,
Severity,
SnmpAuthAlgorithm,
SnmpPrivacyAlgorithm,
SortOrder,
SystemReports,
Tags,
Targets,
Tasks,
Tickets,
TicketStatus,
TLSCertificates,
TrashCan,
UserAuthType,
Users,
UserSettings,
Vulnerabilities,
)

__all__ = (
"Aggregates",
"AggregateStatistic",
"Alerts",
"AlertCondition",
"AlertEvent",
"AlertMethod",
"AliveTest",
"AuditReports",
"Audits",
"Authentication",
"CertBundAdvisories",
"Cpes",
"Credentials",
"CredentialFormat",
"CredentialType",
"Cves",
"DfnCertAdvisories",
"EntityID",
"EntityType",
"Feed",
"FeedType",
"Filters",
"FilterType",
"Groups",
"Help",
"HelpFormat",
"Hosts",
"HostsOrdering",
"InfoType",
"Notes",
"Nvts",
"OperatingSystems",
"Overrides",
"Permissions",
"PermissionSubjectType",
"Policies",
"PortLists",
"PortRangeType",
"ReportConfigs",
"ReportConfigParameter",
"ReportFormatType",
"ReportFormats",
"Reports",
"ResourceNames",
"ResourceType",
"Results",
"Roles",
"ScanConfigs",
"Scanners",
"ScannerType",
"Schedules",
"SecInfo",
"Severity",
"SortOrder",
"SnmpAuthAlgorithm",
"SnmpPrivacyAlgorithm",
"SystemReports",
"Tags",
"Targets",
"Tasks",
"Tickets",
"TicketStatus",
"TLSCertificates",
"TrashCan",
"UserAuthType",
"UserSettings",
"Users",
"Version",
"Vulnerabilities",
)
Loading