|
| 1 | +# SPDX-FileCopyrightText: 2024 Greenbone AG |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: GPL-3.0-or-later |
| 4 | + |
| 5 | +""" |
| 6 | +Greenbone Management Protocol (GMP) version 22.6 |
| 7 | +""" |
| 8 | + |
| 9 | +from typing import Optional, Union |
| 10 | + |
| 11 | +from .._protocol import T |
| 12 | +from ._gmp225 import GMPv225 |
| 13 | +from .requests.v226 import ( |
| 14 | + AuditReports, |
| 15 | + EntityID, |
| 16 | + ReportFormatType, |
| 17 | + Reports, |
| 18 | + ResourceNames, |
| 19 | + ResourceType, |
| 20 | +) |
| 21 | + |
| 22 | + |
| 23 | +class GMPv226(GMPv225[T]): |
| 24 | + """ |
| 25 | + A class implementing the Greenbone Management Protocol (GMP) version 22.6 |
| 26 | +
|
| 27 | + Example: |
| 28 | +
|
| 29 | + .. code-block:: python |
| 30 | +
|
| 31 | + from gvm.protocols.gmp import GMPv226 as GMP |
| 32 | +
|
| 33 | + with GMP(connection) as gmp: |
| 34 | + resp = gmp.get_tasks() |
| 35 | + """ |
| 36 | + |
| 37 | + def __init__(self, *args, **kwargs): |
| 38 | + """ |
| 39 | + Create a new GMPv226 instance. |
| 40 | +
|
| 41 | + Args: |
| 42 | + connection: Connection to use to talk with the remote daemon. See |
| 43 | + :mod:`gvm.connections` for possible connection types. |
| 44 | + transform: Optional transform `callable`_ to convert response data. |
| 45 | + After each request the callable gets passed the plain response data |
| 46 | + which can be used to check the data and/or conversion into different |
| 47 | + representations like a xml dom. |
| 48 | +
|
| 49 | + See :mod:`gvm.transforms` for existing transforms. |
| 50 | +
|
| 51 | + .. _callable: |
| 52 | + https://docs.python.org/3/library/functions.html#callable |
| 53 | + """ |
| 54 | + super().__init__(*args, **kwargs) |
| 55 | + |
| 56 | + @staticmethod |
| 57 | + def get_protocol_version() -> tuple[int, int]: |
| 58 | + return (22, 6) |
| 59 | + |
| 60 | + def get_resource_names( |
| 61 | + self, |
| 62 | + resource_type: ResourceType, # type: ignore[override] |
| 63 | + *, |
| 64 | + filter_string: Optional[str] = None, |
| 65 | + ) -> T: |
| 66 | + """Request a list of resource names and IDs |
| 67 | +
|
| 68 | + Arguments: |
| 69 | + resource_type: Type must be either ALERT, CERT_BUND_ADV, |
| 70 | + CONFIG, CPE, CREDENTIAL, CVE, DFN_CERT_ADV, FILTER, |
| 71 | + GROUP, HOST, NOTE, NVT, OS, OVERRIDE, PERMISSION, |
| 72 | + PORT_LIST, REPORT_FORMAT, REPORT, REPORT_CONFIG, RESULT, ROLE, |
| 73 | + SCANNER, SCHEDULE, TARGET, TASK, TLS_CERTIFICATE |
| 74 | + or USER |
| 75 | + filter_string: Filter term to use for the query |
| 76 | + """ |
| 77 | + return self._send_and_transform_command( |
| 78 | + ResourceNames.get_resource_names( |
| 79 | + resource_type, filter_string=filter_string |
| 80 | + ) |
| 81 | + ) |
| 82 | + |
| 83 | + def get_resource_name( |
| 84 | + self, resource_id: str, resource_type: ResourceType # type: ignore[override] |
| 85 | + ) -> T: |
| 86 | + """Request a single resource name |
| 87 | +
|
| 88 | + Arguments: |
| 89 | + resource_id: ID of an existing resource |
| 90 | + resource_type: Type must be either ALERT, CERT_BUND_ADV, |
| 91 | + CONFIG, CPE, CREDENTIAL, CVE, DFN_CERT_ADV, FILTER, |
| 92 | + GROUP, HOST, NOTE, NVT, OS, OVERRIDE, PERMISSION, |
| 93 | + PORT_LIST, REPORT_FORMAT, REPORT, REPORT_CONFIG, RESULT, ROLE, |
| 94 | + SCANNER, SCHEDULE, TARGET, TASK, TLS_CERTIFICATE |
| 95 | + or USER |
| 96 | + """ |
| 97 | + return self._send_and_transform_command( |
| 98 | + ResourceNames.get_resource_name(resource_id, resource_type) |
| 99 | + ) |
| 100 | + |
| 101 | + def delete_report(self, report_id: EntityID) -> T: |
| 102 | + """Deletes an existing scan report |
| 103 | +
|
| 104 | + Args: |
| 105 | + report_id: UUID of the report to be deleted. |
| 106 | + """ |
| 107 | + return self._send_and_transform_command( |
| 108 | + Reports.delete_report(report_id) |
| 109 | + ) |
| 110 | + |
| 111 | + def get_report( |
| 112 | + self, |
| 113 | + report_id: EntityID, |
| 114 | + *, |
| 115 | + filter_string: Optional[str] = None, |
| 116 | + filter_id: Optional[str] = None, |
| 117 | + delta_report_id: Optional[EntityID] = None, |
| 118 | + report_format_id: Optional[Union[str, ReportFormatType]] = None, |
| 119 | + ignore_pagination: Optional[bool] = None, |
| 120 | + details: Optional[bool] = True, |
| 121 | + ) -> T: |
| 122 | + """Request a single scan report |
| 123 | +
|
| 124 | + Args: |
| 125 | + report_id: UUID of an existing report |
| 126 | + filter_string: Filter term to use to filter results in the report |
| 127 | + filter_id: UUID of filter to use to filter results in the report |
| 128 | + delta_report_id: UUID of an existing report to compare report to. |
| 129 | + report_format_id: UUID of report format to use |
| 130 | + or ReportFormatType (enum) |
| 131 | + ignore_pagination: Whether to ignore the filter terms "first" and |
| 132 | + "rows". |
| 133 | + details: Request additional report information details |
| 134 | + defaults to True |
| 135 | + """ |
| 136 | + return self._send_and_transform_command( |
| 137 | + Reports.get_report( |
| 138 | + report_id, |
| 139 | + filter_string=filter_string, |
| 140 | + filter_id=filter_id, |
| 141 | + delta_report_id=delta_report_id, |
| 142 | + report_format_id=report_format_id, |
| 143 | + ignore_pagination=ignore_pagination, |
| 144 | + details=details, |
| 145 | + ) |
| 146 | + ) |
| 147 | + |
| 148 | + def get_reports( |
| 149 | + self, |
| 150 | + *, |
| 151 | + filter_string: Optional[str] = None, |
| 152 | + filter_id: Optional[EntityID] = None, |
| 153 | + note_details: Optional[bool] = None, |
| 154 | + override_details: Optional[bool] = None, |
| 155 | + ignore_pagination: Optional[bool] = None, |
| 156 | + details: Optional[bool] = None, |
| 157 | + ) -> T: |
| 158 | + """Request a list of scan reports |
| 159 | +
|
| 160 | + Args: |
| 161 | + filter_string: Filter term to use for the query |
| 162 | + filter_id: UUID of an existing filter to use for the query |
| 163 | + note_details: If notes are included, whether to include note details |
| 164 | + override_details: If overrides are included, whether to include |
| 165 | + override details |
| 166 | + ignore_pagination: Whether to ignore the filter terms "first" and |
| 167 | + "rows". |
| 168 | + details: Whether to exclude results |
| 169 | + """ |
| 170 | + return self._send_and_transform_command( |
| 171 | + Reports.get_reports( |
| 172 | + filter_string=filter_string, |
| 173 | + filter_id=filter_id, |
| 174 | + note_details=note_details, |
| 175 | + override_details=override_details, |
| 176 | + ignore_pagination=ignore_pagination, |
| 177 | + details=details, |
| 178 | + ) |
| 179 | + ) |
| 180 | + |
| 181 | + def import_report( |
| 182 | + self, |
| 183 | + report: str, |
| 184 | + task_id: EntityID, |
| 185 | + *, |
| 186 | + in_assets: Optional[bool] = None, |
| 187 | + ) -> T: |
| 188 | + """Import a scan Report from XML |
| 189 | +
|
| 190 | + Args: |
| 191 | + report: Report XML as string to import. This XML must contain |
| 192 | + a :code:`<report>` root element. |
| 193 | + task_id: UUID of task to import report to |
| 194 | + in_asset: Whether to create or update assets using the report |
| 195 | + """ |
| 196 | + return self._send_and_transform_command( |
| 197 | + Reports.import_report(report, task_id, in_assets=in_assets) |
| 198 | + ) |
| 199 | + |
| 200 | + def delete_audit_report(self, report_id: EntityID) -> T: |
| 201 | + """Deletes an existing audit report |
| 202 | +
|
| 203 | + Args: |
| 204 | + report_id: UUID of the report to be deleted. |
| 205 | + """ |
| 206 | + return self._send_and_transform_command( |
| 207 | + AuditReports.delete_report(report_id) |
| 208 | + ) |
| 209 | + |
| 210 | + def get_audit_report( |
| 211 | + self, |
| 212 | + report_id: EntityID, |
| 213 | + *, |
| 214 | + filter_string: Optional[str] = None, |
| 215 | + filter_id: Optional[str] = None, |
| 216 | + delta_report_id: Optional[EntityID] = None, |
| 217 | + report_format_id: Optional[Union[str, ReportFormatType]] = None, |
| 218 | + ignore_pagination: Optional[bool] = None, |
| 219 | + details: Optional[bool] = True, |
| 220 | + ) -> T: |
| 221 | + """Request a single audit report |
| 222 | +
|
| 223 | + Args: |
| 224 | + report_id: UUID of an existing audit report |
| 225 | + filter_string: Filter term to use to filter results in the report |
| 226 | + filter_id: UUID of filter to use to filter results in the report |
| 227 | + delta_report_id: UUID of an existing report to compare report to. |
| 228 | + report_format_id: UUID of report format to use |
| 229 | + or ReportFormatType (enum) |
| 230 | + ignore_pagination: Whether to ignore the filter terms "first" and |
| 231 | + "rows". |
| 232 | + details: Request additional report information details |
| 233 | + defaults to True |
| 234 | + """ |
| 235 | + return self._send_and_transform_command( |
| 236 | + AuditReports.get_report( |
| 237 | + report_id, |
| 238 | + filter_string=filter_string, |
| 239 | + filter_id=filter_id, |
| 240 | + delta_report_id=delta_report_id, |
| 241 | + report_format_id=report_format_id, |
| 242 | + ignore_pagination=ignore_pagination, |
| 243 | + details=details, |
| 244 | + ) |
| 245 | + ) |
| 246 | + |
| 247 | + def get_audit_reports( |
| 248 | + self, |
| 249 | + *, |
| 250 | + filter_string: Optional[str] = None, |
| 251 | + filter_id: Optional[EntityID] = None, |
| 252 | + note_details: Optional[bool] = None, |
| 253 | + override_details: Optional[bool] = None, |
| 254 | + ignore_pagination: Optional[bool] = None, |
| 255 | + details: Optional[bool] = None, |
| 256 | + ) -> T: |
| 257 | + """Request a list of audit reports |
| 258 | +
|
| 259 | + Args: |
| 260 | + filter_string: Filter term to use for the query |
| 261 | + filter_id: UUID of an existing filter to use for the query |
| 262 | + note_details: If notes are included, whether to include note details |
| 263 | + override_details: If overrides are included, whether to include |
| 264 | + override details |
| 265 | + ignore_pagination: Whether to ignore the filter terms "first" and |
| 266 | + "rows". |
| 267 | + details: Whether to exclude results |
| 268 | + """ |
| 269 | + return self._send_and_transform_command( |
| 270 | + AuditReports.get_reports( |
| 271 | + filter_string=filter_string, |
| 272 | + filter_id=filter_id, |
| 273 | + note_details=note_details, |
| 274 | + override_details=override_details, |
| 275 | + ignore_pagination=ignore_pagination, |
| 276 | + details=details, |
| 277 | + ) |
| 278 | + ) |
0 commit comments