|
| 1 | +# SPDX-FileCopyrightText: 2025 Greenbone AG |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: GPL-3.0-or-later |
| 4 | + |
| 5 | +""" |
| 6 | +Greenbone Management Protocol (GMP) version 22.7 |
| 7 | +""" |
| 8 | + |
| 9 | +from typing import Optional, Union |
| 10 | + |
| 11 | +from .._protocol import T |
| 12 | +from ._gmp226 import GMPv226 |
| 13 | +from .requests.v227 import ( |
| 14 | + EntityID, |
| 15 | + Scanners, |
| 16 | + ScannerType, |
| 17 | +) |
| 18 | + |
| 19 | + |
| 20 | +class GMPv227(GMPv226[T]): |
| 21 | + """ |
| 22 | + A class implementing the Greenbone Management Protocol (GMP) version 22.7 |
| 23 | +
|
| 24 | + Example: |
| 25 | +
|
| 26 | + .. code-block:: python |
| 27 | +
|
| 28 | + from gvm.protocols.gmp import GMPv227 as GMP |
| 29 | +
|
| 30 | + with GMP(connection) as gmp: |
| 31 | + resp = gmp.get_tasks() |
| 32 | + """ |
| 33 | + |
| 34 | + @staticmethod |
| 35 | + def get_protocol_version() -> tuple[int, int]: |
| 36 | + return (22, 7) |
| 37 | + |
| 38 | + def create_scanner( # type:ignore[override] |
| 39 | + self, |
| 40 | + name: str, |
| 41 | + host: str, |
| 42 | + port: Union[str, int], |
| 43 | + scanner_type: ScannerType, |
| 44 | + credential_id: str, |
| 45 | + *, |
| 46 | + ca_pub: Optional[str] = None, |
| 47 | + comment: Optional[str] = None, |
| 48 | + relay_host: Optional[str] = None, |
| 49 | + relay_port: Optional[Union[str, int]] = None, |
| 50 | + ) -> T: |
| 51 | + """Create a new scanner |
| 52 | +
|
| 53 | + Args: |
| 54 | + name: Name of the new scanner |
| 55 | + host: Hostname or IP address of the scanner |
| 56 | + port: Port of the scanner |
| 57 | + scanner_type: Type of the scanner |
| 58 | + credential_id: UUID of client certificate credential for the |
| 59 | + scanner |
| 60 | + ca_pub: Certificate of CA to verify scanner certificate |
| 61 | + comment: Comment for the scanner |
| 62 | + relay_host: Hostname or IP address of the scanner relay |
| 63 | + relay_port: Port of the scanner relay |
| 64 | + """ |
| 65 | + return self._send_request_and_transform_response( |
| 66 | + Scanners.create_scanner( |
| 67 | + name, |
| 68 | + host, |
| 69 | + port, |
| 70 | + scanner_type, |
| 71 | + credential_id, |
| 72 | + ca_pub=ca_pub, |
| 73 | + comment=comment, |
| 74 | + relay_host=relay_host, |
| 75 | + relay_port=relay_port, |
| 76 | + ) |
| 77 | + ) |
| 78 | + |
| 79 | + def modify_scanner( # type:ignore[override] |
| 80 | + self, |
| 81 | + scanner_id: EntityID, |
| 82 | + *, |
| 83 | + name: Optional[str] = None, |
| 84 | + host: Optional[str] = None, |
| 85 | + port: Optional[int] = None, |
| 86 | + scanner_type: Optional[ScannerType] = None, |
| 87 | + credential_id: Optional[EntityID] = None, |
| 88 | + ca_pub: Optional[str] = None, |
| 89 | + comment: Optional[str] = None, |
| 90 | + relay_host: Optional[str] = None, |
| 91 | + relay_port: Optional[Union[str, int]] = None, |
| 92 | + ) -> T: |
| 93 | + """Modify an existing scanner |
| 94 | +
|
| 95 | + Args: |
| 96 | + scanner_id: UUID of the scanner to modify |
| 97 | + name: New name of the scanner |
| 98 | + host: New hostname or IP address of the scanner |
| 99 | + port: New port of the scanner |
| 100 | + scanner_type: New type of the scanner |
| 101 | + credential_id: New UUID of client certificate credential for the |
| 102 | + scanner |
| 103 | + ca_pub: New certificate of CA to verify scanner certificate |
| 104 | + comment: New comment for the scanner |
| 105 | + relay_host: Hostname or IP address of the scanner relay |
| 106 | + relay_port: Port of the scanner relay |
| 107 | + """ |
| 108 | + return self._send_request_and_transform_response( |
| 109 | + Scanners.modify_scanner( |
| 110 | + scanner_id, |
| 111 | + name=name, |
| 112 | + host=host, |
| 113 | + port=port, |
| 114 | + scanner_type=scanner_type, |
| 115 | + credential_id=credential_id, |
| 116 | + ca_pub=ca_pub, |
| 117 | + comment=comment, |
| 118 | + relay_host=relay_host, |
| 119 | + relay_port=relay_port, |
| 120 | + ) |
| 121 | + ) |
| 122 | + |
| 123 | + def get_scanners( |
| 124 | + self, |
| 125 | + *, |
| 126 | + filter_string: Optional[str] = None, |
| 127 | + filter_id: Optional[EntityID] = None, |
| 128 | + trash: Optional[bool] = None, |
| 129 | + details: Optional[bool] = None, |
| 130 | + ) -> T: |
| 131 | + """Request a list of scanners |
| 132 | +
|
| 133 | + Args: |
| 134 | + filter_string: Filter term to use for the query |
| 135 | + filter_id: UUID of an existing filter to use for the query |
| 136 | + trash: Whether to get the trashcan scanners instead |
| 137 | + details: Whether to include extra details like tasks using this |
| 138 | + scanner |
| 139 | + """ |
| 140 | + return self._send_request_and_transform_response( |
| 141 | + Scanners.get_scanners( |
| 142 | + filter_string=filter_string, |
| 143 | + filter_id=filter_id, |
| 144 | + trash=trash, |
| 145 | + details=details, |
| 146 | + ) |
| 147 | + ) |
| 148 | + |
| 149 | + def get_scanner(self, scanner_id: EntityID) -> T: |
| 150 | + """Request a single scanner |
| 151 | +
|
| 152 | + Args: |
| 153 | + scanner_id: UUID of an existing scanner |
| 154 | + """ |
| 155 | + return self._send_request_and_transform_response( |
| 156 | + Scanners.get_scanner(scanner_id) |
| 157 | + ) |
| 158 | + |
| 159 | + def verify_scanner(self, scanner_id: EntityID) -> T: |
| 160 | + """Verify an existing scanner |
| 161 | +
|
| 162 | + Args: |
| 163 | + scanner_id: UUID of an existing scanner |
| 164 | + """ |
| 165 | + return self._send_request_and_transform_response( |
| 166 | + Scanners.verify_scanner(scanner_id) |
| 167 | + ) |
| 168 | + |
| 169 | + def clone_scanner(self, scanner_id: EntityID) -> T: |
| 170 | + """Clone an existing scanner |
| 171 | +
|
| 172 | + Args: |
| 173 | + scanner_id: UUID of an existing scanner |
| 174 | + """ |
| 175 | + return self._send_request_and_transform_response( |
| 176 | + Scanners.clone_scanner(scanner_id) |
| 177 | + ) |
| 178 | + |
| 179 | + def delete_scanner( |
| 180 | + self, scanner_id: EntityID, ultimate: Optional[bool] = False |
| 181 | + ) -> T: |
| 182 | + """Delete an existing scanner |
| 183 | +
|
| 184 | + Args: |
| 185 | + scanner_id: UUID of an existing scanner |
| 186 | + ultimate: Whether to remove entirely, or to the trashcan. |
| 187 | + """ |
| 188 | + return self._send_request_and_transform_response( |
| 189 | + Scanners.delete_scanner(scanner_id, ultimate=ultimate) |
| 190 | + ) |
0 commit comments