| Total Complexity | 877 |
| Total Lines | 7233 |
| Duplicated Lines | 18.78 % |
| Changes | 0 | ||
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like gvm.protocols.gmpv208.gmpv208 often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | # -*- coding: utf-8 -*- |
||
| 2 | # Copyright (C) 2018-2021 Greenbone Networks GmbH |
||
| 3 | # |
||
| 4 | # SPDX-License-Identifier: GPL-3.0-or-later |
||
| 5 | # |
||
| 6 | # This program is free software: you can redistribute it and/or modify |
||
| 7 | # it under the terms of the GNU General Public License as published by |
||
| 8 | # the Free Software Foundation, either version 3 of the License, or |
||
| 9 | # (at your option) any later version. |
||
| 10 | # |
||
| 11 | # This program is distributed in the hope that it will be useful, |
||
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
| 14 | # GNU General Public License for more details. |
||
| 15 | # |
||
| 16 | # You should have received a copy of the GNU General Public License |
||
| 17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
||
| 18 | |||
| 19 | # pylint: disable=arguments-differ, redefined-builtin, too-many-lines |
||
| 20 | |||
| 21 | """ |
||
| 22 | Module for communication with gvmd in |
||
| 23 | `Greenbone Management Protocol version 20.08`_ |
||
| 24 | |||
| 25 | .. _Greenbone Management Protocol version 20.08: |
||
| 26 | https://docs.greenbone.net/API/GMP/gmp-20.08.html |
||
| 27 | """ |
||
| 28 | import collections |
||
| 29 | import logging |
||
| 30 | import numbers |
||
| 31 | import warnings |
||
| 32 | |||
| 33 | from typing import Any, List, Optional, Callable, Union, Tuple |
||
| 34 | from lxml import etree |
||
| 35 | |||
| 36 | from gvm.connections import GvmConnection |
||
| 37 | from gvm.errors import InvalidArgument, InvalidArgumentType, RequiredArgument |
||
| 38 | from gvm.protocols.base import GvmProtocol |
||
| 39 | from gvm.utils import ( |
||
| 40 | deprecation, |
||
| 41 | check_command_status, |
||
| 42 | is_list_like, |
||
| 43 | to_base64, |
||
| 44 | to_bool, |
||
| 45 | to_comma_list, |
||
| 46 | add_filter, |
||
| 47 | ) |
||
| 48 | from gvm.xml import XmlCommand |
||
| 49 | |||
| 50 | from . import types |
||
| 51 | from .types import * # pylint: disable=unused-wildcard-import, wildcard-import |
||
| 52 | from .types import _UsageType as UsageType |
||
| 53 | |||
| 54 | _EMPTY_POLICY_ID = '085569ce-73ed-11df-83c3-002264764cea' |
||
| 55 | |||
| 56 | PROTOCOL_VERSION = (20, 8) |
||
| 57 | |||
| 58 | |||
| 59 | logger = logging.getLogger(__name__) |
||
| 60 | |||
| 61 | Severity = numbers.Real |
||
| 62 | |||
| 63 | # put this into the Alert Entity |
||
| 64 | def _check_event( |
||
| 65 | event: AlertEvent, condition: AlertCondition, method: AlertMethod |
||
| 66 | ): |
||
| 67 | if event == AlertEvent.TASK_RUN_STATUS_CHANGED: |
||
|
|
|||
| 68 | if not condition: |
||
| 69 | raise RequiredArgument( |
||
| 70 | "condition is required for event {}".format(event.name) |
||
| 71 | ) |
||
| 72 | |||
| 73 | if not method: |
||
| 74 | raise RequiredArgument( |
||
| 75 | "method is required for event {}".format(event.name) |
||
| 76 | ) |
||
| 77 | |||
| 78 | if condition not in ( |
||
| 79 | AlertCondition.ALWAYS, |
||
| 80 | AlertCondition.FILTER_COUNT_CHANGED, |
||
| 81 | AlertCondition.FILTER_COUNT_AT_LEAST, |
||
| 82 | AlertCondition.SEVERITY_AT_LEAST, |
||
| 83 | AlertCondition.SEVERITY_CHANGED, |
||
| 84 | ): |
||
| 85 | raise InvalidArgument( |
||
| 86 | "Invalid condition {} for event {}".format( |
||
| 87 | condition.name, event.name |
||
| 88 | ) |
||
| 89 | ) |
||
| 90 | elif event in ( |
||
| 91 | AlertEvent.NEW_SECINFO_ARRIVED, |
||
| 92 | AlertEvent.UPDATED_SECINFO_ARRIVED, |
||
| 93 | ): |
||
| 94 | if not condition: |
||
| 95 | raise RequiredArgument( |
||
| 96 | "condition is required for event {}".format(event.name) |
||
| 97 | ) |
||
| 98 | |||
| 99 | if not method: |
||
| 100 | raise RequiredArgument( |
||
| 101 | "method is required for event {}".format(event.name) |
||
| 102 | ) |
||
| 103 | |||
| 104 | if condition != AlertCondition.ALWAYS: |
||
| 105 | raise InvalidArgument( |
||
| 106 | "Invalid condition {} for event {}".format( |
||
| 107 | condition.name, event.name |
||
| 108 | ) |
||
| 109 | ) |
||
| 110 | if method not in ( |
||
| 111 | AlertMethod.SCP, |
||
| 112 | AlertMethod.SEND, |
||
| 113 | AlertMethod.SMB, |
||
| 114 | AlertMethod.SNMP, |
||
| 115 | AlertMethod.SYSLOG, |
||
| 116 | AlertMethod.EMAIL, |
||
| 117 | ): |
||
| 118 | raise InvalidArgument( |
||
| 119 | "Invalid method {} for event {}".format(method.name, event.name) |
||
| 120 | ) |
||
| 121 | elif event in ( |
||
| 122 | AlertEvent.TICKET_RECEIVED, |
||
| 123 | AlertEvent.OWNED_TICKET_CHANGED, |
||
| 124 | AlertEvent.ASSIGNED_TICKET_CHANGED, |
||
| 125 | ): |
||
| 126 | if not condition: |
||
| 127 | raise RequiredArgument( |
||
| 128 | "condition is required for event {}".format(event.name) |
||
| 129 | ) |
||
| 130 | |||
| 131 | if not method: |
||
| 132 | raise RequiredArgument( |
||
| 133 | "method is required for event {}".format(event.name) |
||
| 134 | ) |
||
| 135 | if condition != AlertCondition.ALWAYS: |
||
| 136 | raise InvalidArgument( |
||
| 137 | "Invalid condition {} for event {}".format( |
||
| 138 | condition.name, event.name |
||
| 139 | ) |
||
| 140 | ) |
||
| 141 | if method not in ( |
||
| 142 | AlertMethod.EMAIL, |
||
| 143 | AlertMethod.START_TASK, |
||
| 144 | AlertMethod.SYSLOG, |
||
| 145 | ): |
||
| 146 | raise InvalidArgument( |
||
| 147 | "Invalid method {} for event {}".format(method.name, event.name) |
||
| 148 | ) |
||
| 149 | elif event is not None: |
||
| 150 | raise InvalidArgument('Invalid event "{}"'.format(event.name)) |
||
| 151 | |||
| 152 | |||
| 153 | class GmpV208Mixin(GvmProtocol): |
||
| 154 | """Python interface for Greenbone Management Protocol |
||
| 155 | |||
| 156 | This class implements the `Greenbone Management Protocol version 20.08`_ |
||
| 157 | |||
| 158 | Arguments: |
||
| 159 | connection: Connection to use to talk with the gvmd daemon. See |
||
| 160 | :mod:`gvm.connections` for possible connection types. |
||
| 161 | transform: Optional transform `callable`_ to convert response data. |
||
| 162 | After each request the callable gets passed the plain response data |
||
| 163 | which can be used to check the data and/or conversion into different |
||
| 164 | representations like a xml dom. |
||
| 165 | |||
| 166 | See :mod:`gvm.transforms` for existing transforms. |
||
| 167 | |||
| 168 | .. _Greenbone Management Protocol version 20.08: |
||
| 169 | https://docs.greenbone.net/API/GMP/gmp-20.08.html |
||
| 170 | .. _callable: |
||
| 171 | https://docs.python.org/3/library/functions.html#callable |
||
| 172 | """ |
||
| 173 | |||
| 174 | types = types |
||
| 175 | |||
| 176 | def __init__( |
||
| 177 | self, |
||
| 178 | connection: GvmConnection, |
||
| 179 | *, |
||
| 180 | transform: Optional[Callable[[str], Any]] = None, |
||
| 181 | ): |
||
| 182 | super().__init__(connection, transform=transform) |
||
| 183 | |||
| 184 | # Is authenticated on gvmd |
||
| 185 | self._authenticated = False |
||
| 186 | |||
| 187 | def is_authenticated(self) -> bool: |
||
| 188 | """Checks if the user is authenticated |
||
| 189 | |||
| 190 | If the user is authenticated privileged GMP commands like get_tasks |
||
| 191 | may be send to gvmd. |
||
| 192 | |||
| 193 | Returns: |
||
| 194 | bool: True if an authenticated connection to gvmd has been |
||
| 195 | established. |
||
| 196 | """ |
||
| 197 | return self._authenticated |
||
| 198 | |||
| 199 | def authenticate(self, username: str, password: str) -> Any: |
||
| 200 | """Authenticate to gvmd. |
||
| 201 | |||
| 202 | The generated authenticate command will be send to server. |
||
| 203 | Afterwards the response is read, transformed and returned. |
||
| 204 | |||
| 205 | Arguments: |
||
| 206 | username: Username |
||
| 207 | password: Password |
||
| 208 | |||
| 209 | Returns: |
||
| 210 | Transformed response from server. |
||
| 211 | """ |
||
| 212 | cmd = XmlCommand("authenticate") |
||
| 213 | |||
| 214 | if not username: |
||
| 215 | raise RequiredArgument( |
||
| 216 | function=self.authenticate.__name__, argument='username' |
||
| 217 | ) |
||
| 218 | |||
| 219 | if not password: |
||
| 220 | raise RequiredArgument( |
||
| 221 | function=self.authenticate.__name__, argument='password' |
||
| 222 | ) |
||
| 223 | |||
| 224 | credentials = cmd.add_element("credentials") |
||
| 225 | credentials.add_element("username", username) |
||
| 226 | credentials.add_element("password", password) |
||
| 227 | |||
| 228 | self._send(cmd.to_string()) |
||
| 229 | response = self._read() |
||
| 230 | |||
| 231 | if check_command_status(response): |
||
| 232 | self._authenticated = True |
||
| 233 | |||
| 234 | return self._transform(response) |
||
| 235 | |||
| 236 | def create_alert( |
||
| 237 | self, |
||
| 238 | name: str, |
||
| 239 | condition: AlertCondition, |
||
| 240 | event: AlertEvent, |
||
| 241 | method: AlertMethod, |
||
| 242 | *, |
||
| 243 | method_data: Optional[dict] = None, |
||
| 244 | event_data: Optional[dict] = None, |
||
| 245 | condition_data: Optional[dict] = None, |
||
| 246 | filter_id: Optional[int] = None, |
||
| 247 | comment: Optional[str] = None, |
||
| 248 | ) -> Any: |
||
| 249 | """Create a new alert |
||
| 250 | |||
| 251 | Arguments: |
||
| 252 | name: Name of the new Alert |
||
| 253 | condition: The condition that must be satisfied for the alert |
||
| 254 | to occur; if the event is either 'Updated SecInfo arrived' or |
||
| 255 | 'New SecInfo arrived', condition must be 'Always'. Otherwise, |
||
| 256 | condition can also be on of 'Severity at least', 'Filter count |
||
| 257 | changed' or 'Filter count at least'. |
||
| 258 | event: The event that must happen for the alert to occur, one |
||
| 259 | of 'Task run status changed', 'Updated SecInfo arrived' or 'New |
||
| 260 | SecInfo arrived' |
||
| 261 | method: The method by which the user is alerted, one of 'SCP', |
||
| 262 | 'Send', 'SMB', 'SNMP', 'Syslog' or 'Email'; if the event is |
||
| 263 | neither 'Updated SecInfo arrived' nor 'New SecInfo arrived', |
||
| 264 | method can also be one of 'Start Task', 'HTTP Get', 'Sourcefire |
||
| 265 | Connector' or 'verinice Connector'. |
||
| 266 | condition_data: Data that defines the condition |
||
| 267 | event_data: Data that defines the event |
||
| 268 | method_data: Data that defines the method |
||
| 269 | filter_id: Filter to apply when executing alert |
||
| 270 | comment: Comment for the alert |
||
| 271 | |||
| 272 | Returns: |
||
| 273 | The response. See :py:meth:`send_command` for details. |
||
| 274 | """ |
||
| 275 | if not name: |
||
| 276 | raise RequiredArgument( |
||
| 277 | function=self.create_alert.__name__, argument='name' |
||
| 278 | ) |
||
| 279 | |||
| 280 | if not condition: |
||
| 281 | raise RequiredArgument( |
||
| 282 | function=self.create_alert.__name__, argument='condition' |
||
| 283 | ) |
||
| 284 | |||
| 285 | if not event: |
||
| 286 | raise RequiredArgument( |
||
| 287 | function=self.create_alert.__name__, argument='event' |
||
| 288 | ) |
||
| 289 | |||
| 290 | if not method: |
||
| 291 | raise RequiredArgument( |
||
| 292 | function=self.create_alert.__name__, argument='method' |
||
| 293 | ) |
||
| 294 | |||
| 295 | if not isinstance(condition, AlertCondition): |
||
| 296 | raise InvalidArgumentType( |
||
| 297 | function=self.create_alert.__name__, |
||
| 298 | argument='condition', |
||
| 299 | arg_type=AlertCondition.__name__, |
||
| 300 | ) |
||
| 301 | |||
| 302 | if not isinstance(event, AlertEvent): |
||
| 303 | raise InvalidArgumentType( |
||
| 304 | function=self.create_alert.__name__, |
||
| 305 | argument='even', |
||
| 306 | arg_type=AlertEvent.__name__, |
||
| 307 | ) |
||
| 308 | |||
| 309 | if not isinstance(method, AlertMethod): |
||
| 310 | raise InvalidArgumentType( |
||
| 311 | function=self.create_alert.__name__, |
||
| 312 | argument='method', |
||
| 313 | arg_type=AlertMethod.__name__, |
||
| 314 | ) |
||
| 315 | |||
| 316 | _check_event(event, condition, method) |
||
| 317 | |||
| 318 | cmd = XmlCommand("create_alert") |
||
| 319 | cmd.add_element("name", name) |
||
| 320 | |||
| 321 | conditions = cmd.add_element("condition", condition.value) |
||
| 322 | |||
| 323 | if condition_data is not None: |
||
| 324 | for key, value in condition_data.items(): |
||
| 325 | _data = conditions.add_element("data", value) |
||
| 326 | _data.add_element("name", key) |
||
| 327 | |||
| 328 | events = cmd.add_element("event", event.value) |
||
| 329 | |||
| 330 | if event_data is not None: |
||
| 331 | for key, value in event_data.items(): |
||
| 332 | _data = events.add_element("data", value) |
||
| 333 | _data.add_element("name", key) |
||
| 334 | |||
| 335 | methods = cmd.add_element("method", method.value) |
||
| 336 | |||
| 337 | if method_data is not None: |
||
| 338 | for key, value in method_data.items(): |
||
| 339 | _data = methods.add_element("data", value) |
||
| 340 | _data.add_element("name", key) |
||
| 341 | |||
| 342 | if filter_id: |
||
| 343 | cmd.add_element("filter", attrs={"id": filter_id}) |
||
| 344 | |||
| 345 | if comment: |
||
| 346 | cmd.add_element("comment", comment) |
||
| 347 | |||
| 348 | return self._send_xml_command(cmd) |
||
| 349 | |||
| 350 | View Code Duplication | def create_audit( |
|
| 351 | self, |
||
| 352 | name: str, |
||
| 353 | policy_id: str, |
||
| 354 | target_id: str, |
||
| 355 | scanner_id: str, |
||
| 356 | *, |
||
| 357 | alterable: Optional[bool] = None, |
||
| 358 | hosts_ordering: Optional[HostsOrdering] = None, |
||
| 359 | schedule_id: Optional[str] = None, |
||
| 360 | alert_ids: Optional[List[str]] = None, |
||
| 361 | comment: Optional[str] = None, |
||
| 362 | schedule_periods: Optional[int] = None, |
||
| 363 | observers: Optional[List[str]] = None, |
||
| 364 | preferences: Optional[dict] = None, |
||
| 365 | ) -> Any: |
||
| 366 | """Create a new audit task |
||
| 367 | |||
| 368 | Arguments: |
||
| 369 | name: Name of the new audit |
||
| 370 | policy_id: UUID of policy to use by the audit |
||
| 371 | target_id: UUID of target to be scanned |
||
| 372 | scanner_id: UUID of scanner to use for scanning the target |
||
| 373 | comment: Comment for the audit |
||
| 374 | alterable: Whether the task should be alterable |
||
| 375 | alert_ids: List of UUIDs for alerts to be applied to the audit |
||
| 376 | hosts_ordering: The order hosts are scanned in |
||
| 377 | schedule_id: UUID of a schedule when the audit should be run. |
||
| 378 | schedule_periods: A limit to the number of times the audit will be |
||
| 379 | scheduled, or 0 for no limit |
||
| 380 | observers: List of names or ids of users which should be allowed to |
||
| 381 | observe this audit |
||
| 382 | preferences: Name/Value pairs of scanner preferences. |
||
| 383 | |||
| 384 | Returns: |
||
| 385 | The response. See :py:meth:`send_command` for details. |
||
| 386 | """ |
||
| 387 | |||
| 388 | return self.__create_task( |
||
| 389 | name=name, |
||
| 390 | config_id=policy_id, |
||
| 391 | target_id=target_id, |
||
| 392 | scanner_id=scanner_id, |
||
| 393 | usage_type=UsageType.AUDIT, |
||
| 394 | function=self.create_audit.__name__, |
||
| 395 | alterable=alterable, |
||
| 396 | hosts_ordering=hosts_ordering, |
||
| 397 | schedule_id=schedule_id, |
||
| 398 | alert_ids=alert_ids, |
||
| 399 | comment=comment, |
||
| 400 | schedule_periods=schedule_periods, |
||
| 401 | observers=observers, |
||
| 402 | preferences=preferences, |
||
| 403 | ) |
||
| 404 | |||
| 405 | def create_config( |
||
| 406 | self, config_id: str, name: str, *, comment: Optional[str] = None |
||
| 407 | ) -> Any: |
||
| 408 | """Create a new scan config |
||
| 409 | |||
| 410 | Arguments: |
||
| 411 | config_id: UUID of the existing scan config |
||
| 412 | name: Name of the new scan config |
||
| 413 | comment: A comment on the config |
||
| 414 | |||
| 415 | Returns: |
||
| 416 | The response. See :py:meth:`send_command` for details. |
||
| 417 | """ |
||
| 418 | return self.__create_config( |
||
| 419 | config_id=config_id, |
||
| 420 | name=name, |
||
| 421 | comment=comment, |
||
| 422 | usage_type=UsageType.SCAN, |
||
| 423 | function=self.create_config.__name__, |
||
| 424 | ) |
||
| 425 | |||
| 426 | def create_config_from_osp_scanner( |
||
| 427 | self, scanner_id: str, name: str, *, comment: Optional[str] = None |
||
| 428 | ) -> Any: |
||
| 429 | """Create a new scan config from an ospd scanner. |
||
| 430 | |||
| 431 | Create config by retrieving the expected preferences from the given |
||
| 432 | scanner via OSP. |
||
| 433 | |||
| 434 | Arguments: |
||
| 435 | scanner_id: UUID of an OSP scanner to get config data from |
||
| 436 | name: Name of the new scan config |
||
| 437 | comment: A comment on the config |
||
| 438 | |||
| 439 | Returns: |
||
| 440 | The response. See :py:meth:`send_command` for details. |
||
| 441 | """ |
||
| 442 | return self.__create_config_from_osp_scanner( |
||
| 443 | scanner_id=scanner_id, |
||
| 444 | name=name, |
||
| 445 | comment=comment, |
||
| 446 | usage_type=UsageType.SCAN, |
||
| 447 | function=self.create_config.__name__, |
||
| 448 | ) |
||
| 449 | |||
| 450 | def create_permission( |
||
| 451 | self, |
||
| 452 | name: str, |
||
| 453 | subject_id: str, |
||
| 454 | subject_type: PermissionSubjectType, |
||
| 455 | *, |
||
| 456 | resource_id: Optional[str] = None, |
||
| 457 | resource_type: Optional[EntityType] = None, |
||
| 458 | comment: Optional[str] = None, |
||
| 459 | ) -> Any: |
||
| 460 | """Create a new permission |
||
| 461 | |||
| 462 | Arguments: |
||
| 463 | name: Name of the new permission |
||
| 464 | subject_id: UUID of subject to whom the permission is granted |
||
| 465 | subject_type: Type of the subject user, group or role |
||
| 466 | comment: Comment for the permission |
||
| 467 | resource_id: UUID of entity to which the permission applies |
||
| 468 | resource_type: Type of the resource. For Super permissions user, |
||
| 469 | group or role |
||
| 470 | |||
| 471 | Returns: |
||
| 472 | The response. See :py:meth:`send_command` for details. |
||
| 473 | """ |
||
| 474 | if not name: |
||
| 475 | raise RequiredArgument( |
||
| 476 | function=self.create_permission.__name__, argument='name' |
||
| 477 | ) |
||
| 478 | |||
| 479 | if not subject_id: |
||
| 480 | raise RequiredArgument( |
||
| 481 | function=self.create_permission.__name__, argument='subject_id' |
||
| 482 | ) |
||
| 483 | |||
| 484 | if not isinstance(subject_type, PermissionSubjectType): |
||
| 485 | raise InvalidArgumentType( |
||
| 486 | function=self.create_permission.__name__, |
||
| 487 | argument='subject_type', |
||
| 488 | arg_type=PermissionSubjectType.__name__, |
||
| 489 | ) |
||
| 490 | |||
| 491 | cmd = XmlCommand("create_permission") |
||
| 492 | cmd.add_element("name", name) |
||
| 493 | |||
| 494 | _xmlsubject = cmd.add_element("subject", attrs={"id": subject_id}) |
||
| 495 | _xmlsubject.add_element("type", subject_type.value) |
||
| 496 | |||
| 497 | if comment: |
||
| 498 | cmd.add_element("comment", comment) |
||
| 499 | |||
| 500 | View Code Duplication | if resource_id or resource_type: |
|
| 501 | if not resource_id: |
||
| 502 | raise RequiredArgument( |
||
| 503 | function=self.create_permission.__name__, |
||
| 504 | argument='resource_id', |
||
| 505 | ) |
||
| 506 | |||
| 507 | if not resource_type: |
||
| 508 | raise RequiredArgument( |
||
| 509 | function=self.create_permission.__name__, |
||
| 510 | argument='resource_type', |
||
| 511 | ) |
||
| 512 | |||
| 513 | if not isinstance(resource_type, self.types.EntityType): |
||
| 514 | raise InvalidArgumentType( |
||
| 515 | function=self.create_permission.__name__, |
||
| 516 | argument='resource_type', |
||
| 517 | arg_type=self.types.EntityType.__name__, |
||
| 518 | ) |
||
| 519 | |||
| 520 | _xmlresource = cmd.add_element( |
||
| 521 | "resource", attrs={"id": resource_id} |
||
| 522 | ) |
||
| 523 | |||
| 524 | _actual_resource_type = resource_type |
||
| 525 | if resource_type.value == EntityType.AUDIT.value: |
||
| 526 | _actual_resource_type = EntityType.TASK |
||
| 527 | elif resource_type.value == EntityType.POLICY.value: |
||
| 528 | _actual_resource_type = EntityType.SCAN_CONFIG |
||
| 529 | |||
| 530 | _xmlresource.add_element("type", _actual_resource_type.value) |
||
| 531 | |||
| 532 | return self._send_xml_command(cmd) |
||
| 533 | |||
| 534 | def create_policy( |
||
| 535 | self, name: str, *, policy_id: str = None, comment: Optional[str] = None |
||
| 536 | ) -> Any: |
||
| 537 | """Create a new policy config |
||
| 538 | |||
| 539 | Arguments: |
||
| 540 | name: Name of the new policy |
||
| 541 | policy_id: UUID of an existing policy as base. By default the empty |
||
| 542 | policy is used. |
||
| 543 | comment: A comment on the policy |
||
| 544 | |||
| 545 | Returns: |
||
| 546 | The response. See :py:meth:`send_command` for details. |
||
| 547 | """ |
||
| 548 | if policy_id is None: |
||
| 549 | policy_id = _EMPTY_POLICY_ID |
||
| 550 | return self.__create_config( |
||
| 551 | config_id=policy_id, |
||
| 552 | name=name, |
||
| 553 | comment=comment, |
||
| 554 | usage_type=UsageType.POLICY, |
||
| 555 | function=self.create_policy.__name__, |
||
| 556 | ) |
||
| 557 | |||
| 558 | def create_tag( |
||
| 559 | self, |
||
| 560 | name: str, |
||
| 561 | resource_type: EntityType, |
||
| 562 | *, |
||
| 563 | resource_filter: Optional[str] = None, |
||
| 564 | resource_ids: Optional[List[str]] = None, |
||
| 565 | value: Optional[str] = None, |
||
| 566 | comment: Optional[str] = None, |
||
| 567 | active: Optional[bool] = None, |
||
| 568 | ) -> Any: |
||
| 569 | """Create a tag. |
||
| 570 | |||
| 571 | Arguments: |
||
| 572 | name: Name of the tag. A full tag name consisting of namespace and |
||
| 573 | predicate e.g. `foo:bar`. |
||
| 574 | resource_type: Entity type the tag is to be attached to. |
||
| 575 | resource_filter: Filter term to select resources the tag is to be |
||
| 576 | attached to. Only one of resource_filter or resource_ids can be |
||
| 577 | provided. |
||
| 578 | resource_ids: IDs of the resources the tag is to be attached to. |
||
| 579 | Only one of resource_filter or resource_ids can be provided. |
||
| 580 | value: Value associated with the tag. |
||
| 581 | comment: Comment for the tag. |
||
| 582 | active: Whether the tag should be active. |
||
| 583 | |||
| 584 | Returns: |
||
| 585 | The response. See :py:meth:`send_command` for details. |
||
| 586 | """ |
||
| 587 | if not name: |
||
| 588 | raise RequiredArgument( |
||
| 589 | function=self.create_tag.__name__, argument='name' |
||
| 590 | ) |
||
| 591 | |||
| 592 | if resource_filter and resource_ids: |
||
| 593 | raise InvalidArgument( |
||
| 594 | "create_tag accepts either resource_filter or resource_ids " |
||
| 595 | "argument", |
||
| 596 | function=self.create_tag.__name__, |
||
| 597 | ) |
||
| 598 | |||
| 599 | if not resource_type: |
||
| 600 | raise RequiredArgument( |
||
| 601 | function=self.create_tag.__name__, argument='resource_type' |
||
| 602 | ) |
||
| 603 | |||
| 604 | if not isinstance(resource_type, self.types.EntityType): |
||
| 605 | raise InvalidArgumentType( |
||
| 606 | function=self.create_tag.__name__, |
||
| 607 | argument='resource_type', |
||
| 608 | arg_type=EntityType.__name__, |
||
| 609 | ) |
||
| 610 | |||
| 611 | cmd = XmlCommand('create_tag') |
||
| 612 | cmd.add_element('name', name) |
||
| 613 | |||
| 614 | _xmlresources = cmd.add_element("resources") |
||
| 615 | if resource_filter is not None: |
||
| 616 | _xmlresources.set_attribute("filter", resource_filter) |
||
| 617 | |||
| 618 | for resource_id in resource_ids or []: |
||
| 619 | _xmlresources.add_element( |
||
| 620 | "resource", attrs={"id": str(resource_id)} |
||
| 621 | ) |
||
| 622 | |||
| 623 | _actual_resource_type = resource_type |
||
| 624 | if resource_type.value == EntityType.AUDIT.value: |
||
| 625 | _actual_resource_type = EntityType.TASK |
||
| 626 | elif resource_type.value == EntityType.POLICY.value: |
||
| 627 | _actual_resource_type = EntityType.SCAN_CONFIG |
||
| 628 | _xmlresources.add_element("type", _actual_resource_type.value) |
||
| 629 | |||
| 630 | if comment: |
||
| 631 | cmd.add_element("comment", comment) |
||
| 632 | |||
| 633 | if value: |
||
| 634 | cmd.add_element("value", value) |
||
| 635 | |||
| 636 | if active is not None: |
||
| 637 | if active: |
||
| 638 | cmd.add_element("active", "1") |
||
| 639 | else: |
||
| 640 | cmd.add_element("active", "0") |
||
| 641 | |||
| 642 | return self._send_xml_command(cmd) |
||
| 643 | |||
| 644 | View Code Duplication | def create_task( |
|
| 645 | self, |
||
| 646 | name: str, |
||
| 647 | config_id: str, |
||
| 648 | target_id: str, |
||
| 649 | scanner_id: str, |
||
| 650 | *, |
||
| 651 | alterable: Optional[bool] = None, |
||
| 652 | hosts_ordering: Optional[HostsOrdering] = None, |
||
| 653 | schedule_id: Optional[str] = None, |
||
| 654 | alert_ids: Optional[List[str]] = None, |
||
| 655 | comment: Optional[str] = None, |
||
| 656 | schedule_periods: Optional[int] = None, |
||
| 657 | observers: Optional[List[str]] = None, |
||
| 658 | preferences: Optional[dict] = None, |
||
| 659 | ) -> Any: |
||
| 660 | """Create a new scan task |
||
| 661 | |||
| 662 | Arguments: |
||
| 663 | name: Name of the task |
||
| 664 | config_id: UUID of scan config to use by the task |
||
| 665 | target_id: UUID of target to be scanned |
||
| 666 | scanner_id: UUID of scanner to use for scanning the target |
||
| 667 | comment: Comment for the task |
||
| 668 | alterable: Whether the task should be alterable |
||
| 669 | alert_ids: List of UUIDs for alerts to be applied to the task |
||
| 670 | hosts_ordering: The order hosts are scanned in |
||
| 671 | schedule_id: UUID of a schedule when the task should be run. |
||
| 672 | schedule_periods: A limit to the number of times the task will be |
||
| 673 | scheduled, or 0 for no limit |
||
| 674 | observers: List of names or ids of users which should be allowed to |
||
| 675 | observe this task |
||
| 676 | preferences: Name/Value pairs of scanner preferences. |
||
| 677 | |||
| 678 | Returns: |
||
| 679 | The response. See :py:meth:`send_command` for details. |
||
| 680 | """ |
||
| 681 | return self.__create_task( |
||
| 682 | name=name, |
||
| 683 | config_id=config_id, |
||
| 684 | target_id=target_id, |
||
| 685 | scanner_id=scanner_id, |
||
| 686 | usage_type=UsageType.SCAN, |
||
| 687 | function=self.create_task.__name__, |
||
| 688 | alterable=alterable, |
||
| 689 | hosts_ordering=hosts_ordering, |
||
| 690 | schedule_id=schedule_id, |
||
| 691 | alert_ids=alert_ids, |
||
| 692 | comment=comment, |
||
| 693 | schedule_periods=schedule_periods, |
||
| 694 | observers=observers, |
||
| 695 | preferences=preferences, |
||
| 696 | ) |
||
| 697 | |||
| 698 | View Code Duplication | def create_tls_certificate( |
|
| 699 | self, |
||
| 700 | name: str, |
||
| 701 | certificate: str, |
||
| 702 | *, |
||
| 703 | comment: Optional[str] = None, |
||
| 704 | trust: Optional[bool] = None, |
||
| 705 | ) -> Any: |
||
| 706 | """Create a new TLS certificate |
||
| 707 | |||
| 708 | Arguments: |
||
| 709 | name: Name of the TLS certificate, defaulting to the MD5 |
||
| 710 | fingerprint. |
||
| 711 | certificate: The Base64 encoded certificate data (x.509 DER or PEM). |
||
| 712 | comment: Comment for the TLS certificate. |
||
| 713 | trust: Whether the certificate is trusted. |
||
| 714 | |||
| 715 | Returns: |
||
| 716 | The response. See :py:meth:`send_command` for details. |
||
| 717 | """ |
||
| 718 | if not name: |
||
| 719 | raise RequiredArgument( |
||
| 720 | function=self.create_tls_certificate.__name__, argument='name' |
||
| 721 | ) |
||
| 722 | if not certificate: |
||
| 723 | raise RequiredArgument( |
||
| 724 | function=self.create_tls_certificate.__name__, |
||
| 725 | argument='certificate', |
||
| 726 | ) |
||
| 727 | |||
| 728 | cmd = XmlCommand("create_tls_certificate") |
||
| 729 | |||
| 730 | if comment: |
||
| 731 | cmd.add_element("comment", comment) |
||
| 732 | |||
| 733 | cmd.add_element("name", name) |
||
| 734 | cmd.add_element("certificate", certificate) |
||
| 735 | |||
| 736 | if trust: |
||
| 737 | cmd.add_element("trust", to_bool(trust)) |
||
| 738 | |||
| 739 | return self._send_xml_command(cmd) |
||
| 740 | |||
| 741 | def get_aggregates( |
||
| 742 | self, |
||
| 743 | resource_type: EntityType, |
||
| 744 | *, |
||
| 745 | filter: Optional[str] = None, |
||
| 746 | filter_id: Optional[str] = None, |
||
| 747 | sort_criteria: Optional[list] = None, |
||
| 748 | data_columns: Optional[list] = None, |
||
| 749 | group_column: Optional[str] = None, |
||
| 750 | subgroup_column: Optional[str] = None, |
||
| 751 | text_columns: Optional[list] = None, |
||
| 752 | first_group: Optional[int] = None, |
||
| 753 | max_groups: Optional[int] = None, |
||
| 754 | mode: Optional[int] = None, |
||
| 755 | **kwargs, |
||
| 756 | ) -> Any: |
||
| 757 | """Request aggregated information on a resource / entity type |
||
| 758 | |||
| 759 | Additional arguments can be set via the kwargs parameter for backward |
||
| 760 | compatibility with older versions of python-gvm, but are not validated. |
||
| 761 | |||
| 762 | Arguments: |
||
| 763 | resource_type: The entity type to gather data from |
||
| 764 | filter: Filter term to use for the query |
||
| 765 | filter_id: UUID of an existing filter to use for the query |
||
| 766 | sort_criteria: List of sort criteria (dicts that can contain |
||
| 767 | a field, stat and order) |
||
| 768 | data_columns: List of fields to aggregate data from |
||
| 769 | group_column: The field to group the entities by |
||
| 770 | subgroup_column: The field to further group the entities |
||
| 771 | inside groups by |
||
| 772 | text_columns: List of simple text columns which no statistics |
||
| 773 | are calculated for |
||
| 774 | first_group: The index of the first aggregate group to return |
||
| 775 | max_groups: The maximum number of aggregate groups to return, |
||
| 776 | -1 for all |
||
| 777 | mode: Special mode for aggregation |
||
| 778 | |||
| 779 | Returns: |
||
| 780 | The response. See :py:meth:`send_command` for details. |
||
| 781 | """ |
||
| 782 | if not resource_type: |
||
| 783 | raise RequiredArgument( |
||
| 784 | function=self.get_aggregates.__name__, argument='resource_type' |
||
| 785 | ) |
||
| 786 | |||
| 787 | if not isinstance(resource_type, self.types.EntityType): |
||
| 788 | raise InvalidArgumentType( |
||
| 789 | function=self.get_aggregates.__name__, |
||
| 790 | argument='resource_type', |
||
| 791 | arg_type=self.types.EntityType.__name__, |
||
| 792 | ) |
||
| 793 | |||
| 794 | cmd = XmlCommand('get_aggregates') |
||
| 795 | |||
| 796 | _actual_resource_type = resource_type |
||
| 797 | if resource_type.value == EntityType.AUDIT.value: |
||
| 798 | _actual_resource_type = EntityType.TASK |
||
| 799 | cmd.set_attribute('usage_type', 'audit') |
||
| 800 | elif resource_type.value == EntityType.POLICY.value: |
||
| 801 | _actual_resource_type = EntityType.SCAN_CONFIG |
||
| 802 | cmd.set_attribute('usage_type', 'policy') |
||
| 803 | elif resource_type.value == EntityType.SCAN_CONFIG.value: |
||
| 804 | cmd.set_attribute('usage_type', 'scan') |
||
| 805 | elif resource_type.value == EntityType.TASK.value: |
||
| 806 | cmd.set_attribute('usage_type', 'scan') |
||
| 807 | cmd.set_attribute('type', _actual_resource_type.value) |
||
| 808 | |||
| 809 | add_filter(cmd, filter, filter_id) |
||
| 810 | |||
| 811 | if first_group is not None: |
||
| 812 | if not isinstance(first_group, int): |
||
| 813 | raise InvalidArgumentType( |
||
| 814 | function=self.get_aggregates.__name__, |
||
| 815 | argument='first_group', |
||
| 816 | arg_type=int.__name__, |
||
| 817 | ) |
||
| 818 | cmd.set_attribute('first_group', str(first_group)) |
||
| 819 | |||
| 820 | if max_groups is not None: |
||
| 821 | if not isinstance(max_groups, int): |
||
| 822 | raise InvalidArgumentType( |
||
| 823 | function=self.get_aggregates.__name__, |
||
| 824 | argument='max_groups', |
||
| 825 | arg_type=int.__name__, |
||
| 826 | ) |
||
| 827 | cmd.set_attribute('max_groups', str(max_groups)) |
||
| 828 | |||
| 829 | if sort_criteria is not None: |
||
| 830 | if not isinstance(sort_criteria, list): |
||
| 831 | raise InvalidArgumentType( |
||
| 832 | function=self.get_aggregates.__name__, |
||
| 833 | argument='sort_criteria', |
||
| 834 | arg_type=list.__name__, |
||
| 835 | ) |
||
| 836 | for sort in sort_criteria: |
||
| 837 | if not isinstance(sort, dict): |
||
| 838 | raise InvalidArgumentType( |
||
| 839 | function=self.get_aggregates.__name__, |
||
| 840 | argument='sort_criteria', |
||
| 841 | ) |
||
| 842 | |||
| 843 | sort_elem = cmd.add_element('sort') |
||
| 844 | if sort.get('field'): |
||
| 845 | sort_elem.set_attribute('field', sort.get('field')) |
||
| 846 | |||
| 847 | if sort.get('stat'): |
||
| 848 | if isinstance(sort['stat'], AggregateStatistic): |
||
| 849 | sort_elem.set_attribute('stat', sort['stat'].value) |
||
| 850 | else: |
||
| 851 | stat = get_aggregate_statistic_from_string(sort['stat']) |
||
| 852 | sort_elem.set_attribute('stat', stat.value) |
||
| 853 | |||
| 854 | if sort.get('order'): |
||
| 855 | if isinstance(sort['order'], SortOrder): |
||
| 856 | sort_elem.set_attribute('order', sort['order'].value) |
||
| 857 | else: |
||
| 858 | so = get_sort_order_from_string(sort['order']) |
||
| 859 | sort_elem.set_attribute('order', so.value) |
||
| 860 | |||
| 861 | if data_columns is not None: |
||
| 862 | if not isinstance(data_columns, list): |
||
| 863 | raise InvalidArgumentType( |
||
| 864 | function=self.get_aggregates.__name__, |
||
| 865 | argument='data_columns', |
||
| 866 | arg_type=list.__name__, |
||
| 867 | ) |
||
| 868 | for column in data_columns: |
||
| 869 | cmd.add_element('data_column', column) |
||
| 870 | |||
| 871 | if group_column is not None: |
||
| 872 | cmd.set_attribute('group_column', group_column) |
||
| 873 | |||
| 874 | if subgroup_column is not None: |
||
| 875 | if not group_column: |
||
| 876 | raise RequiredArgument( |
||
| 877 | '{} requires a group_column argument' |
||
| 878 | ' if subgroup_column is given'.format( |
||
| 879 | self.get_aggregates.__name__ |
||
| 880 | ), |
||
| 881 | function=self.get_aggregates.__name__, |
||
| 882 | argument='subgroup_column', |
||
| 883 | ) |
||
| 884 | cmd.set_attribute('subgroup_column', subgroup_column) |
||
| 885 | |||
| 886 | if text_columns is not None: |
||
| 887 | if not isinstance(text_columns, list): |
||
| 888 | raise InvalidArgumentType( |
||
| 889 | function=self.get_aggregates.__name__, |
||
| 890 | argument='text_columns', |
||
| 891 | arg_type=list.__name__, |
||
| 892 | ) |
||
| 893 | for column in text_columns: |
||
| 894 | cmd.add_element('text_column', column) |
||
| 895 | |||
| 896 | if mode is not None: |
||
| 897 | cmd.set_attribute('mode', mode) |
||
| 898 | |||
| 899 | # Add additional keyword args as attributes for backward compatibility. |
||
| 900 | cmd.set_attributes(kwargs) |
||
| 901 | |||
| 902 | return self._send_xml_command(cmd) |
||
| 903 | |||
| 904 | View Code Duplication | def get_tls_certificates( |
|
| 905 | self, |
||
| 906 | *, |
||
| 907 | filter: Optional[str] = None, |
||
| 908 | filter_id: Optional[str] = None, |
||
| 909 | include_certificate_data: Optional[bool] = None, |
||
| 910 | details: Optional[bool] = None, |
||
| 911 | ) -> Any: |
||
| 912 | """Request a list of TLS certificates |
||
| 913 | |||
| 914 | Arguments: |
||
| 915 | filter: Filter term to use for the query |
||
| 916 | filter_id: UUID of an existing filter to use for the query |
||
| 917 | include_certificate_data: Whether to include the certificate data in |
||
| 918 | the response |
||
| 919 | |||
| 920 | Returns: |
||
| 921 | The response. See :py:meth:`send_command` for details. |
||
| 922 | """ |
||
| 923 | |||
| 924 | cmd = XmlCommand("get_tls_certificates") |
||
| 925 | |||
| 926 | add_filter(cmd, filter, filter_id) |
||
| 927 | |||
| 928 | if details is not None: |
||
| 929 | cmd.set_attribute("details", to_bool(details)) |
||
| 930 | |||
| 931 | if include_certificate_data is not None: |
||
| 932 | cmd.set_attribute( |
||
| 933 | "include_certificate_data", to_bool(include_certificate_data) |
||
| 934 | ) |
||
| 935 | |||
| 936 | return self._send_xml_command(cmd) |
||
| 937 | |||
| 938 | def get_tls_certificate(self, tls_certificate_id: str) -> Any: |
||
| 939 | """Request a single TLS certificate |
||
| 940 | |||
| 941 | Arguments: |
||
| 942 | tls_certificate_id: UUID of an existing TLS certificate |
||
| 943 | |||
| 944 | Returns: |
||
| 945 | The response. See :py:meth:`send_command` for details. |
||
| 946 | """ |
||
| 947 | cmd = XmlCommand("get_tls_certificates") |
||
| 948 | |||
| 949 | if not tls_certificate_id: |
||
| 950 | raise RequiredArgument( |
||
| 951 | function=self.get_tls_certificate.__name__, |
||
| 952 | argument='tls_certificate_id', |
||
| 953 | ) |
||
| 954 | |||
| 955 | cmd.set_attribute("tls_certificate_id", tls_certificate_id) |
||
| 956 | |||
| 957 | # for single tls certificate always request cert data |
||
| 958 | cmd.set_attribute("include_certificate_data", "1") |
||
| 959 | |||
| 960 | # for single entity always request all details |
||
| 961 | cmd.set_attribute("details", "1") |
||
| 962 | |||
| 963 | return self._send_xml_command(cmd) |
||
| 964 | |||
| 965 | def modify_alert( |
||
| 966 | self, |
||
| 967 | alert_id: str, |
||
| 968 | *, |
||
| 969 | name: Optional[str] = None, |
||
| 970 | comment: Optional[str] = None, |
||
| 971 | filter_id: Optional[str] = None, |
||
| 972 | event: Optional[AlertEvent] = None, |
||
| 973 | event_data: Optional[dict] = None, |
||
| 974 | condition: Optional[AlertCondition] = None, |
||
| 975 | condition_data: Optional[dict] = None, |
||
| 976 | method: Optional[AlertMethod] = None, |
||
| 977 | method_data: Optional[dict] = None, |
||
| 978 | ) -> Any: |
||
| 979 | """Modifies an existing alert. |
||
| 980 | |||
| 981 | Arguments: |
||
| 982 | alert_id: UUID of the alert to be modified. |
||
| 983 | name: Name of the Alert. |
||
| 984 | condition: The condition that must be satisfied for the alert to |
||
| 985 | occur. If the event is either 'Updated SecInfo |
||
| 986 | arrived' or 'New SecInfo arrived', condition must be 'Always'. |
||
| 987 | Otherwise, condition can also be on of 'Severity at least', |
||
| 988 | 'Filter count changed' or 'Filter count at least'. |
||
| 989 | condition_data: Data that defines the condition |
||
| 990 | event: The event that must happen for the alert to occur, one of |
||
| 991 | 'Task run status changed', 'Updated SecInfo arrived' or |
||
| 992 | 'New SecInfo arrived' |
||
| 993 | event_data: Data that defines the event |
||
| 994 | method: The method by which the user is alerted, one of 'SCP', |
||
| 995 | 'Send', 'SMB', 'SNMP', 'Syslog' or 'Email'; |
||
| 996 | if the event is neither 'Updated SecInfo arrived' nor |
||
| 997 | 'New SecInfo arrived', method can also be one of 'Start Task', |
||
| 998 | 'HTTP Get', 'Sourcefire Connector' or 'verinice Connector'. |
||
| 999 | method_data: Data that defines the method |
||
| 1000 | filter_id: Filter to apply when executing alert |
||
| 1001 | comment: Comment for the alert |
||
| 1002 | |||
| 1003 | Returns: |
||
| 1004 | The response. See :py:meth:`send_command` for details. |
||
| 1005 | """ |
||
| 1006 | |||
| 1007 | if not alert_id: |
||
| 1008 | raise RequiredArgument( |
||
| 1009 | function=self.modify_alert.__name__, argument='alert_id' |
||
| 1010 | ) |
||
| 1011 | |||
| 1012 | cmd = XmlCommand("modify_alert") |
||
| 1013 | cmd.set_attribute("alert_id", str(alert_id)) |
||
| 1014 | |||
| 1015 | if name: |
||
| 1016 | cmd.add_element("name", name) |
||
| 1017 | |||
| 1018 | if comment: |
||
| 1019 | cmd.add_element("comment", comment) |
||
| 1020 | |||
| 1021 | if filter_id: |
||
| 1022 | cmd.add_element("filter", attrs={"id": filter_id}) |
||
| 1023 | |||
| 1024 | if condition: |
||
| 1025 | if not isinstance(condition, AlertCondition): |
||
| 1026 | raise InvalidArgumentType( |
||
| 1027 | function=self.modify_alert.__name__, |
||
| 1028 | argument='condition', |
||
| 1029 | arg_type=AlertCondition.__name__, |
||
| 1030 | ) |
||
| 1031 | |||
| 1032 | conditions = cmd.add_element("condition", condition.value) |
||
| 1033 | |||
| 1034 | if condition_data is not None: |
||
| 1035 | for key, value in condition_data.items(): |
||
| 1036 | _data = conditions.add_element("data", value) |
||
| 1037 | _data.add_element("name", key) |
||
| 1038 | |||
| 1039 | if method: |
||
| 1040 | if not isinstance(method, AlertMethod): |
||
| 1041 | raise InvalidArgumentType( |
||
| 1042 | function=self.modify_alert.__name__, |
||
| 1043 | argument='method', |
||
| 1044 | arg_type=AlertMethod.__name__, |
||
| 1045 | ) |
||
| 1046 | |||
| 1047 | methods = cmd.add_element("method", method.value) |
||
| 1048 | |||
| 1049 | if method_data is not None: |
||
| 1050 | for key, value in method_data.items(): |
||
| 1051 | _data = methods.add_element("data", value) |
||
| 1052 | _data.add_element("name", key) |
||
| 1053 | |||
| 1054 | if event: |
||
| 1055 | if not isinstance(event, AlertEvent): |
||
| 1056 | raise InvalidArgumentType( |
||
| 1057 | function=self.modify_alert.__name__, |
||
| 1058 | argument='event', |
||
| 1059 | arg_type=AlertEvent.__name__, |
||
| 1060 | ) |
||
| 1061 | |||
| 1062 | _check_event(event, condition, method) |
||
| 1063 | |||
| 1064 | events = cmd.add_element("event", event.value) |
||
| 1065 | |||
| 1066 | if event_data is not None: |
||
| 1067 | for key, value in event_data.items(): |
||
| 1068 | _data = events.add_element("data", value) |
||
| 1069 | _data.add_element("name", key) |
||
| 1070 | |||
| 1071 | return self._send_xml_command(cmd) |
||
| 1072 | |||
| 1073 | def modify_audit( |
||
| 1074 | self, |
||
| 1075 | audit_id: str, |
||
| 1076 | *, |
||
| 1077 | name: Optional[str] = None, |
||
| 1078 | policy_id: Optional[str] = None, |
||
| 1079 | target_id: Optional[str] = None, |
||
| 1080 | scanner_id: Optional[str] = None, |
||
| 1081 | alterable: Optional[bool] = None, |
||
| 1082 | hosts_ordering: Optional[HostsOrdering] = None, |
||
| 1083 | schedule_id: Optional[str] = None, |
||
| 1084 | schedule_periods: Optional[int] = None, |
||
| 1085 | comment: Optional[str] = None, |
||
| 1086 | alert_ids: Optional[List[str]] = None, |
||
| 1087 | observers: Optional[List[str]] = None, |
||
| 1088 | preferences: Optional[dict] = None, |
||
| 1089 | ) -> Any: |
||
| 1090 | """Modifies an existing task. |
||
| 1091 | |||
| 1092 | Arguments: |
||
| 1093 | audit_id: UUID of audit to modify. |
||
| 1094 | name: The name of the audit. |
||
| 1095 | policy_id: UUID of policy to use by the audit |
||
| 1096 | target_id: UUID of target to be scanned |
||
| 1097 | scanner_id: UUID of scanner to use for scanning the target |
||
| 1098 | comment: The comment on the audit. |
||
| 1099 | alert_ids: List of UUIDs for alerts to be applied to the audit |
||
| 1100 | hosts_ordering: The order hosts are scanned in |
||
| 1101 | schedule_id: UUID of a schedule when the audit should be run. |
||
| 1102 | schedule_periods: A limit to the number of times the audit will be |
||
| 1103 | scheduled, or 0 for no limit. |
||
| 1104 | observers: List of names or ids of users which should be allowed to |
||
| 1105 | observe this audit |
||
| 1106 | preferences: Name/Value pairs of scanner preferences. |
||
| 1107 | |||
| 1108 | Returns: |
||
| 1109 | The response. See :py:meth:`send_command` for details. |
||
| 1110 | """ |
||
| 1111 | self.modify_task( |
||
| 1112 | task_id=audit_id, |
||
| 1113 | name=name, |
||
| 1114 | config_id=policy_id, |
||
| 1115 | target_id=target_id, |
||
| 1116 | scanner_id=scanner_id, |
||
| 1117 | alterable=alterable, |
||
| 1118 | hosts_ordering=hosts_ordering, |
||
| 1119 | schedule_id=schedule_id, |
||
| 1120 | schedule_periods=schedule_periods, |
||
| 1121 | comment=comment, |
||
| 1122 | alert_ids=alert_ids, |
||
| 1123 | observers=observers, |
||
| 1124 | preferences=preferences, |
||
| 1125 | ) |
||
| 1126 | |||
| 1127 | def modify_permission( |
||
| 1128 | self, |
||
| 1129 | permission_id: str, |
||
| 1130 | *, |
||
| 1131 | comment: Optional[str] = None, |
||
| 1132 | name: Optional[str] = None, |
||
| 1133 | resource_id: Optional[str] = None, |
||
| 1134 | resource_type: Optional[EntityType] = None, |
||
| 1135 | subject_id: Optional[str] = None, |
||
| 1136 | subject_type: Optional[PermissionSubjectType] = None, |
||
| 1137 | ) -> Any: |
||
| 1138 | """Modifies an existing permission. |
||
| 1139 | |||
| 1140 | Arguments: |
||
| 1141 | permission_id: UUID of permission to be modified. |
||
| 1142 | comment: The comment on the permission. |
||
| 1143 | name: Permission name, currently the name of a command. |
||
| 1144 | subject_id: UUID of subject to whom the permission is granted |
||
| 1145 | subject_type: Type of the subject user, group or role |
||
| 1146 | resource_id: UUID of entity to which the permission applies |
||
| 1147 | resource_type: Type of the resource. For Super permissions user, |
||
| 1148 | group or role |
||
| 1149 | |||
| 1150 | Returns: |
||
| 1151 | The response. See :py:meth:`send_command` for details. |
||
| 1152 | """ |
||
| 1153 | if not permission_id: |
||
| 1154 | raise RequiredArgument( |
||
| 1155 | function=self.modify_permission.__name__, |
||
| 1156 | argument='permission_id', |
||
| 1157 | ) |
||
| 1158 | |||
| 1159 | cmd = XmlCommand("modify_permission") |
||
| 1160 | cmd.set_attribute("permission_id", permission_id) |
||
| 1161 | |||
| 1162 | if comment: |
||
| 1163 | cmd.add_element("comment", comment) |
||
| 1164 | |||
| 1165 | if name: |
||
| 1166 | cmd.add_element("name", name) |
||
| 1167 | |||
| 1168 | View Code Duplication | if resource_id or resource_type: |
|
| 1169 | if not resource_id: |
||
| 1170 | raise RequiredArgument( |
||
| 1171 | function=self.modify_permission.__name__, |
||
| 1172 | argument='resource_id', |
||
| 1173 | ) |
||
| 1174 | |||
| 1175 | if not resource_type: |
||
| 1176 | raise RequiredArgument( |
||
| 1177 | function=self.modify_permission.__name__, |
||
| 1178 | argument='resource_type', |
||
| 1179 | ) |
||
| 1180 | |||
| 1181 | if not isinstance(resource_type, self.types.EntityType): |
||
| 1182 | raise InvalidArgumentType( |
||
| 1183 | function=self.modify_permission.__name__, |
||
| 1184 | argument='resource_type', |
||
| 1185 | arg_type=self.types.EntityType.__name__, |
||
| 1186 | ) |
||
| 1187 | |||
| 1188 | _xmlresource = cmd.add_element( |
||
| 1189 | "resource", attrs={"id": resource_id} |
||
| 1190 | ) |
||
| 1191 | _actual_resource_type = resource_type |
||
| 1192 | if resource_type.value == EntityType.AUDIT.value: |
||
| 1193 | _actual_resource_type = EntityType.TASK |
||
| 1194 | elif resource_type.value == EntityType.POLICY.value: |
||
| 1195 | _actual_resource_type = EntityType.SCAN_CONFIG |
||
| 1196 | _xmlresource.add_element("type", _actual_resource_type.value) |
||
| 1197 | |||
| 1198 | if subject_id or subject_type: |
||
| 1199 | if not subject_id: |
||
| 1200 | raise RequiredArgument( |
||
| 1201 | function=self.modify_permission.__name__, |
||
| 1202 | argument='subject_id', |
||
| 1203 | ) |
||
| 1204 | |||
| 1205 | if not isinstance(subject_type, PermissionSubjectType): |
||
| 1206 | raise InvalidArgumentType( |
||
| 1207 | function=self.modify_permission.__name__, |
||
| 1208 | argument='subject_type', |
||
| 1209 | arg_type=PermissionSubjectType.__name__, |
||
| 1210 | ) |
||
| 1211 | |||
| 1212 | _xmlsubject = cmd.add_element("subject", attrs={"id": subject_id}) |
||
| 1213 | _xmlsubject.add_element("type", subject_type.value) |
||
| 1214 | |||
| 1215 | return self._send_xml_command(cmd) |
||
| 1216 | |||
| 1217 | def modify_policy_set_nvt_preference( |
||
| 1218 | self, |
||
| 1219 | policy_id: str, |
||
| 1220 | name: str, |
||
| 1221 | nvt_oid: str, |
||
| 1222 | *, |
||
| 1223 | value: Optional[str] = None, |
||
| 1224 | ) -> Any: |
||
| 1225 | """Modifies the nvt preferences of an existing policy. |
||
| 1226 | |||
| 1227 | Arguments: |
||
| 1228 | policy_id: UUID of policy to modify. |
||
| 1229 | name: Name for preference to change. |
||
| 1230 | nvt_oid: OID of the NVT associated with preference to modify |
||
| 1231 | value: New value for the preference. None to delete the preference |
||
| 1232 | and to use the default instead. |
||
| 1233 | """ |
||
| 1234 | self.modify_config_set_nvt_preference( |
||
| 1235 | config_id=policy_id, name=name, nvt_oid=nvt_oid, value=value |
||
| 1236 | ) |
||
| 1237 | |||
| 1238 | def modify_policy_set_name(self, policy_id: str, name: str) -> Any: |
||
| 1239 | """Modifies the name of an existing policy |
||
| 1240 | |||
| 1241 | Arguments: |
||
| 1242 | config_id: UUID of policy to modify. |
||
| 1243 | name: New name for the config. |
||
| 1244 | """ |
||
| 1245 | self.modify_config_set_name(config_id=policy_id, name=name) |
||
| 1246 | |||
| 1247 | def modify_policy_set_comment( |
||
| 1248 | self, policy_id: str, comment: Optional[str] = "" |
||
| 1249 | ) -> Any: |
||
| 1250 | """Modifies the comment of an existing policy |
||
| 1251 | |||
| 1252 | Arguments: |
||
| 1253 | policy_id: UUID of policy to modify. |
||
| 1254 | comment: Comment to set on a config. Default: '' |
||
| 1255 | """ |
||
| 1256 | self.modify_config_set_comment(config_id=policy_id, comment=comment) |
||
| 1257 | |||
| 1258 | def modify_policy_set_scanner_preference( |
||
| 1259 | self, policy_id: str, name: str, *, value: Optional[str] = None |
||
| 1260 | ) -> Any: |
||
| 1261 | """Modifies the scanner preferences of an existing policy |
||
| 1262 | |||
| 1263 | Arguments: |
||
| 1264 | policy_id: UUID of policy to modify. |
||
| 1265 | name: Name of the scanner preference to change |
||
| 1266 | value: New value for the preference. None to delete the preference |
||
| 1267 | and to use the default instead. |
||
| 1268 | |||
| 1269 | """ |
||
| 1270 | self.modify_config_set_scanner_preference( |
||
| 1271 | config_id=policy_id, name=name, value=value |
||
| 1272 | ) |
||
| 1273 | |||
| 1274 | def modify_policy_set_nvt_selection( |
||
| 1275 | self, policy_id: str, family: str, nvt_oids: List[str] |
||
| 1276 | ) -> Any: |
||
| 1277 | """Modifies the selected nvts of an existing policy |
||
| 1278 | |||
| 1279 | The manager updates the given family in the config to include only the |
||
| 1280 | given NVTs. |
||
| 1281 | |||
| 1282 | Arguments: |
||
| 1283 | policy_id: UUID of policy to modify. |
||
| 1284 | family: Name of the NVT family to include NVTs from |
||
| 1285 | nvt_oids: List of NVTs to select for the family. |
||
| 1286 | """ |
||
| 1287 | self.modify_config_set_nvt_selection( |
||
| 1288 | config_id=policy_id, family=family, nvt_oids=nvt_oids |
||
| 1289 | ) |
||
| 1290 | |||
| 1291 | def modify_policy_set_family_selection( |
||
| 1292 | self, |
||
| 1293 | policy_id: str, |
||
| 1294 | families: List[Tuple[str, bool, bool]], |
||
| 1295 | *, |
||
| 1296 | auto_add_new_families: Optional[bool] = True, |
||
| 1297 | ) -> Any: |
||
| 1298 | """ |
||
| 1299 | Selected the NVTs of a policy at a family level. |
||
| 1300 | |||
| 1301 | Arguments: |
||
| 1302 | policy_id: UUID of policy to modify. |
||
| 1303 | families: A list of tuples with the first entry being the name |
||
| 1304 | of the NVT family selected, second entry a boolean indicating |
||
| 1305 | whether new NVTs should be added to the family automatically, |
||
| 1306 | and third entry a boolean indicating whether all nvts from |
||
| 1307 | the family should be included. |
||
| 1308 | auto_add_new_families: Whether new families should be added to the |
||
| 1309 | policy automatically. Default: True. |
||
| 1310 | """ |
||
| 1311 | self.modify_config_set_family_selection( |
||
| 1312 | config_id=policy_id, |
||
| 1313 | families=families, |
||
| 1314 | auto_add_new_families=auto_add_new_families, |
||
| 1315 | ) |
||
| 1316 | |||
| 1317 | def modify_tag( |
||
| 1318 | self, |
||
| 1319 | tag_id: str, |
||
| 1320 | *, |
||
| 1321 | comment: Optional[str] = None, |
||
| 1322 | name: Optional[str] = None, |
||
| 1323 | value=None, |
||
| 1324 | active=None, |
||
| 1325 | resource_action: Optional[str] = None, |
||
| 1326 | resource_type: Optional[EntityType] = None, |
||
| 1327 | resource_filter: Optional[str] = None, |
||
| 1328 | resource_ids: Optional[List[str]] = None, |
||
| 1329 | ) -> Any: |
||
| 1330 | """Modifies an existing tag. |
||
| 1331 | |||
| 1332 | Arguments: |
||
| 1333 | tag_id: UUID of the tag. |
||
| 1334 | comment: Comment to add to the tag. |
||
| 1335 | name: Name of the tag. |
||
| 1336 | value: Value of the tag. |
||
| 1337 | active: Whether the tag is active. |
||
| 1338 | resource_action: Whether to add or remove resources instead of |
||
| 1339 | overwriting. One of '', 'add', 'set' or 'remove'. |
||
| 1340 | resource_type: Type of the resources to which to attach the tag. |
||
| 1341 | Required if resource_filter is set. |
||
| 1342 | resource_filter: Filter term to select resources the tag is to be |
||
| 1343 | attached to. |
||
| 1344 | resource_ids: IDs of the resources to which to attach the tag. |
||
| 1345 | |||
| 1346 | Returns: |
||
| 1347 | The response. See :py:meth:`send_command` for details. |
||
| 1348 | """ |
||
| 1349 | if not tag_id: |
||
| 1350 | raise RequiredArgument( |
||
| 1351 | function=self.modify_tag.__name__, argument='tag_id' |
||
| 1352 | ) |
||
| 1353 | |||
| 1354 | cmd = XmlCommand("modify_tag") |
||
| 1355 | cmd.set_attribute("tag_id", str(tag_id)) |
||
| 1356 | |||
| 1357 | if comment: |
||
| 1358 | cmd.add_element("comment", comment) |
||
| 1359 | |||
| 1360 | if name: |
||
| 1361 | cmd.add_element("name", name) |
||
| 1362 | |||
| 1363 | if value: |
||
| 1364 | cmd.add_element("value", value) |
||
| 1365 | |||
| 1366 | if active is not None: |
||
| 1367 | cmd.add_element("active", to_bool(active)) |
||
| 1368 | |||
| 1369 | if resource_action or resource_filter or resource_ids or resource_type: |
||
| 1370 | if resource_filter and not resource_type: |
||
| 1371 | raise RequiredArgument( |
||
| 1372 | function=self.modify_tag.__name__, argument='resource_type' |
||
| 1373 | ) |
||
| 1374 | |||
| 1375 | _xmlresources = cmd.add_element("resources") |
||
| 1376 | if resource_action is not None: |
||
| 1377 | _xmlresources.set_attribute("action", resource_action) |
||
| 1378 | |||
| 1379 | if resource_filter is not None: |
||
| 1380 | _xmlresources.set_attribute("filter", resource_filter) |
||
| 1381 | |||
| 1382 | for resource_id in resource_ids or []: |
||
| 1383 | _xmlresources.add_element( |
||
| 1384 | "resource", attrs={"id": str(resource_id)} |
||
| 1385 | ) |
||
| 1386 | |||
| 1387 | if resource_type is not None: |
||
| 1388 | if not isinstance(resource_type, self.types.EntityType): |
||
| 1389 | raise InvalidArgumentType( |
||
| 1390 | function=self.modify_tag.__name__, |
||
| 1391 | argument="resource_type", |
||
| 1392 | arg_type=EntityType.__name__, |
||
| 1393 | ) |
||
| 1394 | _actual_resource_type = resource_type |
||
| 1395 | if resource_type.value == EntityType.AUDIT.value: |
||
| 1396 | _actual_resource_type = EntityType.TASK |
||
| 1397 | elif resource_type.value == EntityType.POLICY.value: |
||
| 1398 | _actual_resource_type = EntityType.SCAN_CONFIG |
||
| 1399 | _xmlresources.add_element("type", _actual_resource_type.value) |
||
| 1400 | |||
| 1401 | return self._send_xml_command(cmd) |
||
| 1402 | |||
| 1403 | View Code Duplication | def modify_tls_certificate( |
|
| 1404 | self, |
||
| 1405 | tls_certificate_id: str, |
||
| 1406 | *, |
||
| 1407 | name: Optional[str] = None, |
||
| 1408 | comment: Optional[str] = None, |
||
| 1409 | trust: Optional[bool] = None, |
||
| 1410 | ) -> Any: |
||
| 1411 | """Modifies an existing TLS certificate. |
||
| 1412 | |||
| 1413 | Arguments: |
||
| 1414 | tls_certificate_id: UUID of the TLS certificate to be modified. |
||
| 1415 | name: Name of the TLS certificate, defaulting to the MD5 fingerprint |
||
| 1416 | comment: Comment for the TLS certificate. |
||
| 1417 | trust: Whether the certificate is trusted. |
||
| 1418 | |||
| 1419 | Returns: |
||
| 1420 | The response. See :py:meth:`send_command` for details. |
||
| 1421 | """ |
||
| 1422 | if not tls_certificate_id: |
||
| 1423 | raise RequiredArgument( |
||
| 1424 | function=self.modify_tls_certificate.__name__, |
||
| 1425 | argument='tls_certificate_id', |
||
| 1426 | ) |
||
| 1427 | |||
| 1428 | cmd = XmlCommand("modify_tls_certificate") |
||
| 1429 | cmd.set_attribute("tls_certificate_id", str(tls_certificate_id)) |
||
| 1430 | |||
| 1431 | if comment: |
||
| 1432 | cmd.add_element("comment", comment) |
||
| 1433 | |||
| 1434 | if name: |
||
| 1435 | cmd.add_element("name", name) |
||
| 1436 | |||
| 1437 | if trust: |
||
| 1438 | cmd.add_element("trust", to_bool(trust)) |
||
| 1439 | |||
| 1440 | return self._send_xml_command(cmd) |
||
| 1441 | |||
| 1442 | def clone_alert(self, alert_id: str) -> Any: |
||
| 1443 | """Clone an existing alert |
||
| 1444 | |||
| 1445 | Arguments: |
||
| 1446 | alert_id: UUID of an existing alert to clone from |
||
| 1447 | |||
| 1448 | Returns: |
||
| 1449 | The response. See :py:meth:`send_command` for details. |
||
| 1450 | """ |
||
| 1451 | if not alert_id: |
||
| 1452 | raise RequiredArgument( |
||
| 1453 | function=self.clone_alert.__name__, argument='alert_id' |
||
| 1454 | ) |
||
| 1455 | |||
| 1456 | cmd = XmlCommand("create_alert") |
||
| 1457 | cmd.add_element("copy", alert_id) |
||
| 1458 | return self._send_xml_command(cmd) |
||
| 1459 | |||
| 1460 | def clone_ticket(self, ticket_id: str) -> Any: |
||
| 1461 | """Clone an existing ticket |
||
| 1462 | |||
| 1463 | Arguments: |
||
| 1464 | ticket_id: UUID of an existing ticket to clone from |
||
| 1465 | |||
| 1466 | Returns: |
||
| 1467 | The response. See :py:meth:`send_command` for details. |
||
| 1468 | """ |
||
| 1469 | if not ticket_id: |
||
| 1470 | raise RequiredArgument( |
||
| 1471 | function=self.clone_ticket.__name__, argument='ticket_id' |
||
| 1472 | ) |
||
| 1473 | |||
| 1474 | cmd = XmlCommand("create_ticket") |
||
| 1475 | |||
| 1476 | _copy = cmd.add_element("copy", ticket_id) |
||
| 1477 | |||
| 1478 | return self._send_xml_command(cmd) |
||
| 1479 | |||
| 1480 | def clone_tls_certificate(self, tls_certificate_id: str) -> Any: |
||
| 1481 | """Modifies an existing TLS certificate. |
||
| 1482 | |||
| 1483 | Arguments: |
||
| 1484 | tls_certificate_id: The UUID of an existing TLS certificate |
||
| 1485 | |||
| 1486 | Returns: |
||
| 1487 | The response. See :py:meth:`send_command` for details. |
||
| 1488 | """ |
||
| 1489 | if not tls_certificate_id: |
||
| 1490 | raise RequiredArgument( |
||
| 1491 | function=self.clone_tls_certificate.__name__, |
||
| 1492 | argument='tls_certificate_id', |
||
| 1493 | ) |
||
| 1494 | |||
| 1495 | cmd = XmlCommand("create_tls_certificate") |
||
| 1496 | |||
| 1497 | cmd.add_element("copy", tls_certificate_id) |
||
| 1498 | |||
| 1499 | return self._send_xml_command(cmd) |
||
| 1500 | |||
| 1501 | def get_configs( |
||
| 1502 | self, |
||
| 1503 | *, |
||
| 1504 | filter: Optional[str] = None, |
||
| 1505 | filter_id: Optional[str] = None, |
||
| 1506 | trash: Optional[bool] = None, |
||
| 1507 | details: Optional[bool] = None, |
||
| 1508 | families: Optional[bool] = None, |
||
| 1509 | preferences: Optional[bool] = None, |
||
| 1510 | tasks: Optional[bool] = None, |
||
| 1511 | ) -> Any: |
||
| 1512 | """Request a list of scan configs |
||
| 1513 | |||
| 1514 | Arguments: |
||
| 1515 | filter: Filter term to use for the query |
||
| 1516 | filter_id: UUID of an existing filter to use for the query |
||
| 1517 | trash: Whether to get the trashcan scan configs instead |
||
| 1518 | details: Whether to get config families, preferences, nvt selectors |
||
| 1519 | and tasks. |
||
| 1520 | families: Whether to include the families if no details are |
||
| 1521 | requested |
||
| 1522 | preferences: Whether to include the preferences if no details are |
||
| 1523 | requested |
||
| 1524 | tasks: Whether to get tasks using this config |
||
| 1525 | |||
| 1526 | Returns: |
||
| 1527 | The response. See :py:meth:`send_command` for details. |
||
| 1528 | """ |
||
| 1529 | return self.__get_configs( |
||
| 1530 | UsageType.SCAN, |
||
| 1531 | filter=filter, |
||
| 1532 | filter_id=filter_id, |
||
| 1533 | trash=trash, |
||
| 1534 | details=details, |
||
| 1535 | families=families, |
||
| 1536 | preferences=preferences, |
||
| 1537 | tasks=tasks, |
||
| 1538 | ) |
||
| 1539 | |||
| 1540 | def get_policies( |
||
| 1541 | self, |
||
| 1542 | *, |
||
| 1543 | audits: Optional[bool] = None, |
||
| 1544 | filter: Optional[str] = None, |
||
| 1545 | filter_id: Optional[str] = None, |
||
| 1546 | details: Optional[bool] = None, |
||
| 1547 | families: Optional[bool] = None, |
||
| 1548 | preferences: Optional[bool] = None, |
||
| 1549 | trash: Optional[bool] = None, |
||
| 1550 | ) -> Any: |
||
| 1551 | """Request a list of policies |
||
| 1552 | |||
| 1553 | Arguments: |
||
| 1554 | audits: Whether to get audits using the policy |
||
| 1555 | filter: Filter term to use for the query |
||
| 1556 | filter_id: UUID of an existing filter to use for the query |
||
| 1557 | details: Whether to get families, preferences, nvt selectors |
||
| 1558 | and tasks. |
||
| 1559 | families: Whether to include the families if no details are |
||
| 1560 | requested |
||
| 1561 | preferences: Whether to include the preferences if no details are |
||
| 1562 | requested |
||
| 1563 | trash: Whether to get the trashcan audits instead |
||
| 1564 | |||
| 1565 | Returns: |
||
| 1566 | The response. See :py:meth:`send_command` for details. |
||
| 1567 | """ |
||
| 1568 | return self.__get_configs( |
||
| 1569 | UsageType.POLICY, |
||
| 1570 | filter=filter, |
||
| 1571 | filter_id=filter_id, |
||
| 1572 | details=details, |
||
| 1573 | families=families, |
||
| 1574 | preferences=preferences, |
||
| 1575 | tasks=audits, |
||
| 1576 | trash=trash, |
||
| 1577 | ) |
||
| 1578 | |||
| 1579 | def get_config( |
||
| 1580 | self, config_id: str, *, tasks: Optional[bool] = None |
||
| 1581 | ) -> Any: |
||
| 1582 | """Request a single scan config |
||
| 1583 | |||
| 1584 | Arguments: |
||
| 1585 | config_id: UUID of an existing scan config |
||
| 1586 | tasks: Whether to get tasks using this config |
||
| 1587 | |||
| 1588 | Returns: |
||
| 1589 | The response. See :py:meth:`send_command` for details. |
||
| 1590 | """ |
||
| 1591 | return self.__get_config( |
||
| 1592 | config_id=config_id, usage_type=UsageType.SCAN, tasks=tasks |
||
| 1593 | ) |
||
| 1594 | |||
| 1595 | def get_policy( |
||
| 1596 | self, policy_id: str, *, audits: Optional[bool] = None |
||
| 1597 | ) -> Any: |
||
| 1598 | """Request a single policy |
||
| 1599 | |||
| 1600 | Arguments: |
||
| 1601 | policy_id: UUID of an existing policy |
||
| 1602 | audits: Whether to get audits using this config |
||
| 1603 | |||
| 1604 | Returns: |
||
| 1605 | The response. See :py:meth:`send_command` for details. |
||
| 1606 | """ |
||
| 1607 | return self.__get_config(policy_id, UsageType.POLICY, tasks=audits) |
||
| 1608 | |||
| 1609 | def get_tasks( |
||
| 1610 | self, |
||
| 1611 | *, |
||
| 1612 | filter: Optional[str] = None, |
||
| 1613 | filter_id: Optional[str] = None, |
||
| 1614 | trash: Optional[bool] = None, |
||
| 1615 | details: Optional[bool] = None, |
||
| 1616 | schedules_only: Optional[bool] = None, |
||
| 1617 | ) -> Any: |
||
| 1618 | """Request a list of tasks |
||
| 1619 | |||
| 1620 | Arguments: |
||
| 1621 | filter: Filter term to use for the query |
||
| 1622 | filter_id: UUID of an existing filter to use for the query |
||
| 1623 | trash: Whether to get the trashcan tasks instead |
||
| 1624 | details: Whether to include full task details |
||
| 1625 | schedules_only: Whether to only include id, name and schedule |
||
| 1626 | details |
||
| 1627 | |||
| 1628 | Returns: |
||
| 1629 | The response. See :py:meth:`send_command` for details. |
||
| 1630 | """ |
||
| 1631 | return self.__get_tasks( |
||
| 1632 | UsageType.SCAN, |
||
| 1633 | filter=filter, |
||
| 1634 | filter_id=filter_id, |
||
| 1635 | trash=trash, |
||
| 1636 | details=details, |
||
| 1637 | schedules_only=schedules_only, |
||
| 1638 | ) |
||
| 1639 | |||
| 1640 | def get_audits( |
||
| 1641 | self, |
||
| 1642 | *, |
||
| 1643 | filter: Optional[str] = None, |
||
| 1644 | filter_id: Optional[str] = None, |
||
| 1645 | trash: Optional[bool] = None, |
||
| 1646 | details: Optional[bool] = None, |
||
| 1647 | schedules_only: Optional[bool] = None, |
||
| 1648 | ) -> Any: |
||
| 1649 | """Request a list of audits |
||
| 1650 | |||
| 1651 | Arguments: |
||
| 1652 | filter: Filter term to use for the query |
||
| 1653 | filter_id: UUID of an existing filter to use for the query |
||
| 1654 | trash: Whether to get the trashcan audits instead |
||
| 1655 | details: Whether to include full audit details |
||
| 1656 | schedules_only: Whether to only include id, name and schedule |
||
| 1657 | details |
||
| 1658 | |||
| 1659 | Returns: |
||
| 1660 | The response. See :py:meth:`send_command` for details. |
||
| 1661 | """ |
||
| 1662 | return self.__get_tasks( |
||
| 1663 | UsageType.AUDIT, |
||
| 1664 | filter=filter, |
||
| 1665 | filter_id=filter_id, |
||
| 1666 | trash=trash, |
||
| 1667 | details=details, |
||
| 1668 | schedules_only=schedules_only, |
||
| 1669 | ) |
||
| 1670 | |||
| 1671 | def get_task(self, task_id: str) -> Any: |
||
| 1672 | """Request a single task |
||
| 1673 | |||
| 1674 | Arguments: |
||
| 1675 | task_id: UUID of an existing task |
||
| 1676 | |||
| 1677 | Returns: |
||
| 1678 | The response. See :py:meth:`send_command` for details. |
||
| 1679 | """ |
||
| 1680 | return self.__get_task(task_id, UsageType.SCAN) |
||
| 1681 | |||
| 1682 | def get_audit(self, audit_id: str) -> Any: |
||
| 1683 | """Request a single audit |
||
| 1684 | |||
| 1685 | Arguments: |
||
| 1686 | audit_id: UUID of an existing audit |
||
| 1687 | |||
| 1688 | Returns: |
||
| 1689 | The response. See :py:meth:`send_command` for details. |
||
| 1690 | """ |
||
| 1691 | return self.__get_task(audit_id, UsageType.AUDIT) |
||
| 1692 | |||
| 1693 | def clone_audit(self, audit_id: str) -> Any: |
||
| 1694 | """Clone an existing audit |
||
| 1695 | |||
| 1696 | Arguments: |
||
| 1697 | audit_id: UUID of existing audit to clone from |
||
| 1698 | |||
| 1699 | Returns: |
||
| 1700 | The response. See :py:meth:`send_command` for details. |
||
| 1701 | """ |
||
| 1702 | if not audit_id: |
||
| 1703 | raise RequiredArgument( |
||
| 1704 | function=self.clone_audit.__name__, argument='audit_id' |
||
| 1705 | ) |
||
| 1706 | |||
| 1707 | cmd = XmlCommand("create_task") |
||
| 1708 | cmd.add_element("copy", audit_id) |
||
| 1709 | return self._send_xml_command(cmd) |
||
| 1710 | |||
| 1711 | def clone_policy(self, policy_id: str) -> Any: |
||
| 1712 | """Clone a policy from an existing one |
||
| 1713 | |||
| 1714 | Arguments: |
||
| 1715 | policy_id: UUID of the existing policy |
||
| 1716 | |||
| 1717 | Returns: |
||
| 1718 | The response. See :py:meth:`send_command` for details. |
||
| 1719 | """ |
||
| 1720 | if not policy_id: |
||
| 1721 | raise RequiredArgument( |
||
| 1722 | function=self.clone_policy.__name__, argument='policy_id' |
||
| 1723 | ) |
||
| 1724 | |||
| 1725 | cmd = XmlCommand("create_config") |
||
| 1726 | cmd.add_element("copy", policy_id) |
||
| 1727 | return self._send_xml_command(cmd) |
||
| 1728 | |||
| 1729 | def delete_audit( |
||
| 1730 | self, audit_id: str, *, ultimate: Optional[bool] = False |
||
| 1731 | ) -> Any: |
||
| 1732 | """Deletes an existing audit |
||
| 1733 | |||
| 1734 | Arguments: |
||
| 1735 | audit_id: UUID of the audit to be deleted. |
||
| 1736 | ultimate: Whether to remove entirely, or to the trashcan. |
||
| 1737 | """ |
||
| 1738 | if not audit_id: |
||
| 1739 | raise RequiredArgument( |
||
| 1740 | function=self.delete_audit.__name__, argument='audit_id' |
||
| 1741 | ) |
||
| 1742 | |||
| 1743 | cmd = XmlCommand("delete_task") |
||
| 1744 | cmd.set_attribute("task_id", audit_id) |
||
| 1745 | cmd.set_attribute("ultimate", to_bool(ultimate)) |
||
| 1746 | |||
| 1747 | return self._send_xml_command(cmd) |
||
| 1748 | |||
| 1749 | def delete_policy( |
||
| 1750 | self, policy_id: str, *, ultimate: Optional[bool] = False |
||
| 1751 | ) -> Any: |
||
| 1752 | """Deletes an existing policy |
||
| 1753 | |||
| 1754 | Arguments: |
||
| 1755 | policy_id: UUID of the policy to be deleted. |
||
| 1756 | ultimate: Whether to remove entirely, or to the trashcan. |
||
| 1757 | """ |
||
| 1758 | if not policy_id: |
||
| 1759 | raise RequiredArgument( |
||
| 1760 | function=self.delete_policy.__name__, argument='policy_id' |
||
| 1761 | ) |
||
| 1762 | |||
| 1763 | cmd = XmlCommand("delete_config") |
||
| 1764 | cmd.set_attribute("config_id", policy_id) |
||
| 1765 | cmd.set_attribute("ultimate", to_bool(ultimate)) |
||
| 1766 | |||
| 1767 | return self._send_xml_command(cmd) |
||
| 1768 | |||
| 1769 | def delete_tls_certificate(self, tls_certificate_id: str) -> Any: |
||
| 1770 | """Deletes an existing tls certificate |
||
| 1771 | |||
| 1772 | Arguments: |
||
| 1773 | tls_certificate_id: UUID of the tls certificate to be deleted. |
||
| 1774 | """ |
||
| 1775 | if not tls_certificate_id: |
||
| 1776 | raise RequiredArgument( |
||
| 1777 | function=self.delete_tls_certificate.__name__, |
||
| 1778 | argument='tls_certificate_id', |
||
| 1779 | ) |
||
| 1780 | |||
| 1781 | cmd = XmlCommand("delete_tls_certificate") |
||
| 1782 | cmd.set_attribute("tls_certificate_id", tls_certificate_id) |
||
| 1783 | |||
| 1784 | return self._send_xml_command(cmd) |
||
| 1785 | |||
| 1786 | def __create_task( |
||
| 1787 | self, |
||
| 1788 | name: str, |
||
| 1789 | config_id: str, |
||
| 1790 | target_id: str, |
||
| 1791 | scanner_id: str, |
||
| 1792 | usage_type: UsageType, |
||
| 1793 | function: str, |
||
| 1794 | *, |
||
| 1795 | alterable: Optional[bool] = None, |
||
| 1796 | hosts_ordering: Optional[HostsOrdering] = None, |
||
| 1797 | schedule_id: Optional[str] = None, |
||
| 1798 | alert_ids: Optional[List[str]] = None, |
||
| 1799 | comment: Optional[str] = None, |
||
| 1800 | schedule_periods: Optional[int] = None, |
||
| 1801 | observers: Optional[List[str]] = None, |
||
| 1802 | preferences: Optional[dict] = None, |
||
| 1803 | ) -> Any: |
||
| 1804 | if not name: |
||
| 1805 | raise RequiredArgument(function=function, argument='name') |
||
| 1806 | |||
| 1807 | if not config_id: |
||
| 1808 | raise RequiredArgument(function=function, argument='config_id') |
||
| 1809 | |||
| 1810 | if not target_id: |
||
| 1811 | raise RequiredArgument(function=function, argument='target_id') |
||
| 1812 | |||
| 1813 | if not scanner_id: |
||
| 1814 | raise RequiredArgument(function=function, argument='scanner_id') |
||
| 1815 | |||
| 1816 | # don't allow to create a container task with create_task |
||
| 1817 | if target_id == '0': |
||
| 1818 | raise InvalidArgument(function=function, argument='target_id') |
||
| 1819 | |||
| 1820 | cmd = XmlCommand("create_task") |
||
| 1821 | cmd.add_element("name", name) |
||
| 1822 | cmd.add_element("usage_type", usage_type.value) |
||
| 1823 | cmd.add_element("config", attrs={"id": config_id}) |
||
| 1824 | cmd.add_element("target", attrs={"id": target_id}) |
||
| 1825 | cmd.add_element("scanner", attrs={"id": scanner_id}) |
||
| 1826 | |||
| 1827 | if comment: |
||
| 1828 | cmd.add_element("comment", comment) |
||
| 1829 | |||
| 1830 | if alterable is not None: |
||
| 1831 | cmd.add_element("alterable", to_bool(alterable)) |
||
| 1832 | |||
| 1833 | if hosts_ordering: |
||
| 1834 | if not isinstance(hosts_ordering, self.types.HostsOrdering): |
||
| 1835 | raise InvalidArgumentType( |
||
| 1836 | function=function, |
||
| 1837 | argument='hosts_ordering', |
||
| 1838 | arg_type=HostsOrdering.__name__, |
||
| 1839 | ) |
||
| 1840 | cmd.add_element("hosts_ordering", hosts_ordering.value) |
||
| 1841 | |||
| 1842 | if alert_ids: |
||
| 1843 | if isinstance(alert_ids, str): |
||
| 1844 | deprecation( |
||
| 1845 | "Please pass a list as alert_ids parameter to {}. " |
||
| 1846 | "Passing a string is deprecated and will be removed in " |
||
| 1847 | "future.".format(function) |
||
| 1848 | ) |
||
| 1849 | |||
| 1850 | # if a single id is given as a string wrap it into a list |
||
| 1851 | alert_ids = [alert_ids] |
||
| 1852 | if is_list_like(alert_ids): |
||
| 1853 | # parse all given alert id's |
||
| 1854 | for alert in alert_ids: |
||
| 1855 | cmd.add_element("alert", attrs={"id": str(alert)}) |
||
| 1856 | |||
| 1857 | if schedule_id: |
||
| 1858 | cmd.add_element("schedule", attrs={"id": schedule_id}) |
||
| 1859 | |||
| 1860 | View Code Duplication | if schedule_periods is not None: |
|
| 1861 | if ( |
||
| 1862 | not isinstance(schedule_periods, numbers.Integral) |
||
| 1863 | or schedule_periods < 0 |
||
| 1864 | ): |
||
| 1865 | raise InvalidArgument( |
||
| 1866 | "schedule_periods must be an integer greater or equal " |
||
| 1867 | "than 0" |
||
| 1868 | ) |
||
| 1869 | cmd.add_element("schedule_periods", str(schedule_periods)) |
||
| 1870 | |||
| 1871 | if observers is not None: |
||
| 1872 | if not is_list_like(observers): |
||
| 1873 | raise InvalidArgumentType( |
||
| 1874 | function=function, argument='observers', arg_type='list' |
||
| 1875 | ) |
||
| 1876 | |||
| 1877 | # gvmd splits by comma and space |
||
| 1878 | # gvmd tries to lookup each value as user name and afterwards as |
||
| 1879 | # user id. So both user name and user id are possible |
||
| 1880 | cmd.add_element("observers", to_comma_list(observers)) |
||
| 1881 | |||
| 1882 | View Code Duplication | if preferences is not None: |
|
| 1883 | if not isinstance(preferences, collections.abc.Mapping): |
||
| 1884 | raise InvalidArgumentType( |
||
| 1885 | function=function, |
||
| 1886 | argument='preferences', |
||
| 1887 | arg_type=collections.abc.Mapping.__name__, |
||
| 1888 | ) |
||
| 1889 | |||
| 1890 | _xmlprefs = cmd.add_element("preferences") |
||
| 1891 | for pref_name, pref_value in preferences.items(): |
||
| 1892 | _xmlpref = _xmlprefs.add_element("preference") |
||
| 1893 | _xmlpref.add_element("scanner_name", pref_name) |
||
| 1894 | _xmlpref.add_element("value", str(pref_value)) |
||
| 1895 | |||
| 1896 | return self._send_xml_command(cmd) |
||
| 1897 | |||
| 1898 | def __create_config( |
||
| 1899 | self, |
||
| 1900 | config_id: str, |
||
| 1901 | name: str, |
||
| 1902 | usage_type: UsageType, |
||
| 1903 | function: str, |
||
| 1904 | *, |
||
| 1905 | comment: Optional[str] = None, |
||
| 1906 | ) -> Any: |
||
| 1907 | if not name: |
||
| 1908 | raise RequiredArgument(function=function, argument='name') |
||
| 1909 | |||
| 1910 | if not config_id: |
||
| 1911 | raise RequiredArgument(function=function, argument='config_id') |
||
| 1912 | |||
| 1913 | cmd = XmlCommand("create_config") |
||
| 1914 | if comment is not None: |
||
| 1915 | cmd.add_element("comment", comment) |
||
| 1916 | cmd.add_element("copy", config_id) |
||
| 1917 | cmd.add_element("name", name) |
||
| 1918 | cmd.add_element("usage_type", usage_type.value) |
||
| 1919 | return self._send_xml_command(cmd) |
||
| 1920 | |||
| 1921 | def __create_config_from_osp_scanner( |
||
| 1922 | self, |
||
| 1923 | scanner_id: str, |
||
| 1924 | name: str, |
||
| 1925 | usage_type: UsageType, |
||
| 1926 | function: str, |
||
| 1927 | *, |
||
| 1928 | comment: Optional[str] = None, |
||
| 1929 | ) -> Any: |
||
| 1930 | if not name: |
||
| 1931 | raise RequiredArgument(function=function, argument='name') |
||
| 1932 | |||
| 1933 | if not scanner_id: |
||
| 1934 | raise RequiredArgument(function=function, argument='scanner_id') |
||
| 1935 | |||
| 1936 | cmd = XmlCommand("create_config") |
||
| 1937 | if comment is not None: |
||
| 1938 | cmd.add_element("comment", comment) |
||
| 1939 | cmd.add_element("scanner", scanner_id) |
||
| 1940 | cmd.add_element("name", name) |
||
| 1941 | cmd.add_element("usage_type", usage_type.value) |
||
| 1942 | return self._send_xml_command(cmd) |
||
| 1943 | |||
| 1944 | def __get_configs( |
||
| 1945 | self, |
||
| 1946 | usage_type: UsageType, |
||
| 1947 | *, |
||
| 1948 | filter: Optional[str] = None, |
||
| 1949 | filter_id: Optional[str] = None, |
||
| 1950 | trash: Optional[bool] = None, |
||
| 1951 | details: Optional[bool] = None, |
||
| 1952 | families: Optional[bool] = None, |
||
| 1953 | preferences: Optional[bool] = None, |
||
| 1954 | tasks: Optional[bool] = None, |
||
| 1955 | ) -> Any: |
||
| 1956 | cmd = XmlCommand("get_configs") |
||
| 1957 | cmd.set_attribute("usage_type", usage_type.value) |
||
| 1958 | |||
| 1959 | add_filter(cmd, filter, filter_id) |
||
| 1960 | |||
| 1961 | if trash is not None: |
||
| 1962 | cmd.set_attribute("trash", to_bool(trash)) |
||
| 1963 | |||
| 1964 | if details is not None: |
||
| 1965 | cmd.set_attribute("details", to_bool(details)) |
||
| 1966 | |||
| 1967 | if families is not None: |
||
| 1968 | cmd.set_attribute("families", to_bool(families)) |
||
| 1969 | |||
| 1970 | if preferences is not None: |
||
| 1971 | cmd.set_attribute("preferences", to_bool(preferences)) |
||
| 1972 | |||
| 1973 | if tasks is not None: |
||
| 1974 | cmd.set_attribute("tasks", to_bool(tasks)) |
||
| 1975 | |||
| 1976 | return self._send_xml_command(cmd) |
||
| 1977 | |||
| 1978 | def __get_config( |
||
| 1979 | self, |
||
| 1980 | config_id: str, |
||
| 1981 | usage_type: UsageType, |
||
| 1982 | *, |
||
| 1983 | tasks: Optional[bool] = None, |
||
| 1984 | ) -> Any: |
||
| 1985 | if not config_id: |
||
| 1986 | raise RequiredArgument( |
||
| 1987 | function=self.get_config.__name__, argument='config_id' |
||
| 1988 | ) |
||
| 1989 | |||
| 1990 | cmd = XmlCommand("get_configs") |
||
| 1991 | cmd.set_attribute("config_id", config_id) |
||
| 1992 | |||
| 1993 | cmd.set_attribute("usage_type", usage_type.value) |
||
| 1994 | |||
| 1995 | if tasks is not None: |
||
| 1996 | cmd.set_attribute("tasks", to_bool(tasks)) |
||
| 1997 | |||
| 1998 | # for single entity always request all details |
||
| 1999 | cmd.set_attribute("details", "1") |
||
| 2000 | |||
| 2001 | return self._send_xml_command(cmd) |
||
| 2002 | |||
| 2003 | def __get_tasks( |
||
| 2004 | self, |
||
| 2005 | usage_type: UsageType, |
||
| 2006 | *, |
||
| 2007 | filter: Optional[str] = None, |
||
| 2008 | filter_id: Optional[str] = None, |
||
| 2009 | trash: Optional[bool] = None, |
||
| 2010 | details: Optional[bool] = None, |
||
| 2011 | schedules_only: Optional[bool] = None, |
||
| 2012 | ) -> Any: |
||
| 2013 | cmd = XmlCommand("get_tasks") |
||
| 2014 | cmd.set_attribute("usage_type", usage_type.value) |
||
| 2015 | |||
| 2016 | add_filter(cmd, filter, filter_id) |
||
| 2017 | |||
| 2018 | if trash is not None: |
||
| 2019 | cmd.set_attribute("trash", to_bool(trash)) |
||
| 2020 | |||
| 2021 | if details is not None: |
||
| 2022 | cmd.set_attribute("details", to_bool(details)) |
||
| 2023 | |||
| 2024 | if schedules_only is not None: |
||
| 2025 | cmd.set_attribute("schedules_only", to_bool(schedules_only)) |
||
| 2026 | |||
| 2027 | return self._send_xml_command(cmd) |
||
| 2028 | |||
| 2029 | def __get_task(self, task_id: str, usage_type: UsageType) -> Any: |
||
| 2030 | if not task_id: |
||
| 2031 | raise RequiredArgument( |
||
| 2032 | function=self.get_task.__name__, argument='task_id' |
||
| 2033 | ) |
||
| 2034 | |||
| 2035 | cmd = XmlCommand("get_tasks") |
||
| 2036 | cmd.set_attribute("task_id", task_id) |
||
| 2037 | cmd.set_attribute("usage_type", usage_type.value) |
||
| 2038 | |||
| 2039 | # for single entity always request all details |
||
| 2040 | cmd.set_attribute("details", "1") |
||
| 2041 | return self._send_xml_command(cmd) |
||
| 2042 | |||
| 2043 | def resume_audit(self, audit_id: str) -> Any: |
||
| 2044 | """Resume an existing stopped audit |
||
| 2045 | |||
| 2046 | Arguments: |
||
| 2047 | audit_id: UUID of the audit to be resumed |
||
| 2048 | |||
| 2049 | Returns: |
||
| 2050 | The response. See :py:meth:`send_command` for details. |
||
| 2051 | """ |
||
| 2052 | if not audit_id: |
||
| 2053 | raise RequiredArgument( |
||
| 2054 | function=self.resume_audit.__name__, argument='audit_id' |
||
| 2055 | ) |
||
| 2056 | |||
| 2057 | cmd = XmlCommand("resume_task") |
||
| 2058 | cmd.set_attribute("task_id", audit_id) |
||
| 2059 | |||
| 2060 | return self._send_xml_command(cmd) |
||
| 2061 | |||
| 2062 | def start_audit(self, audit_id: str) -> Any: |
||
| 2063 | """Start an existing audit |
||
| 2064 | |||
| 2065 | Arguments: |
||
| 2066 | audit_id: UUID of the audit to be started |
||
| 2067 | |||
| 2068 | Returns: |
||
| 2069 | The response. See :py:meth:`send_command` for details. |
||
| 2070 | """ |
||
| 2071 | if not audit_id: |
||
| 2072 | raise RequiredArgument( |
||
| 2073 | function=self.start_audit.__name__, argument='audit_id' |
||
| 2074 | ) |
||
| 2075 | |||
| 2076 | cmd = XmlCommand("start_task") |
||
| 2077 | cmd.set_attribute("task_id", audit_id) |
||
| 2078 | |||
| 2079 | return self._send_xml_command(cmd) |
||
| 2080 | |||
| 2081 | def stop_audit(self, audit_id: str) -> Any: |
||
| 2082 | """Stop an existing running audit |
||
| 2083 | |||
| 2084 | Arguments: |
||
| 2085 | audit_id: UUID of the audit to be stopped |
||
| 2086 | |||
| 2087 | Returns: |
||
| 2088 | The response. See :py:meth:`send_command` for details. |
||
| 2089 | """ |
||
| 2090 | if not audit_id: |
||
| 2091 | raise RequiredArgument( |
||
| 2092 | function=self.stop_audit.__name__, argument='audit_id' |
||
| 2093 | ) |
||
| 2094 | |||
| 2095 | cmd = XmlCommand("stop_task") |
||
| 2096 | cmd.set_attribute("task_id", audit_id) |
||
| 2097 | |||
| 2098 | return self._send_xml_command(cmd) |
||
| 2099 | |||
| 2100 | def import_report( |
||
| 2101 | self, |
||
| 2102 | report: str, |
||
| 2103 | *, |
||
| 2104 | task_id: Optional[str] = None, |
||
| 2105 | in_assets: Optional[bool] = None, |
||
| 2106 | ) -> Any: |
||
| 2107 | """Import a Report from XML |
||
| 2108 | |||
| 2109 | Arguments: |
||
| 2110 | report: Report XML as string to import. This XML must contain |
||
| 2111 | a :code:`<report>` root element. |
||
| 2112 | task_id: UUID of task to import report to |
||
| 2113 | in_asset: Whether to create or update assets using the report |
||
| 2114 | |||
| 2115 | Returns: |
||
| 2116 | The response. See :py:meth:`send_command` for details. |
||
| 2117 | """ |
||
| 2118 | if not report: |
||
| 2119 | raise RequiredArgument( |
||
| 2120 | function=self.import_report.__name__, argument='report' |
||
| 2121 | ) |
||
| 2122 | |||
| 2123 | cmd = XmlCommand("create_report") |
||
| 2124 | |||
| 2125 | if task_id: |
||
| 2126 | cmd.add_element("task", attrs={"id": task_id}) |
||
| 2127 | else: |
||
| 2128 | raise RequiredArgument( |
||
| 2129 | function=self.import_report.__name__, argument='task_id' |
||
| 2130 | ) |
||
| 2131 | |||
| 2132 | if in_assets is not None: |
||
| 2133 | cmd.add_element("in_assets", to_bool(in_assets)) |
||
| 2134 | |||
| 2135 | try: |
||
| 2136 | cmd.append_xml_str(report) |
||
| 2137 | except etree.XMLSyntaxError as e: |
||
| 2138 | raise InvalidArgument( |
||
| 2139 | "Invalid xml passed as report to import_report {}".format(e) |
||
| 2140 | ) from None |
||
| 2141 | |||
| 2142 | return self._send_xml_command(cmd) |
||
| 2143 | |||
| 2144 | def get_info_list( |
||
| 2145 | self, |
||
| 2146 | info_type: InfoType, |
||
| 2147 | *, |
||
| 2148 | filter: Optional[str] = None, |
||
| 2149 | filter_id: Optional[str] = None, |
||
| 2150 | name: Optional[str] = None, |
||
| 2151 | details: Optional[bool] = None, |
||
| 2152 | ) -> Any: |
||
| 2153 | """Request a list of security information |
||
| 2154 | |||
| 2155 | Arguments: |
||
| 2156 | info_type: Type must be either CERT_BUND_ADV, CPE, CVE, |
||
| 2157 | DFN_CERT_ADV, OVALDEF, NVT or ALLINFO |
||
| 2158 | filter: Filter term to use for the query |
||
| 2159 | filter_id: UUID of an existing filter to use for the query |
||
| 2160 | name: Name or identifier of the requested information |
||
| 2161 | details: Whether to include information about references to this |
||
| 2162 | information |
||
| 2163 | |||
| 2164 | Returns: |
||
| 2165 | The response. See :py:meth:`send_command` for details. |
||
| 2166 | """ |
||
| 2167 | if not info_type: |
||
| 2168 | raise RequiredArgument( |
||
| 2169 | function=self.get_info_list.__name__, argument='info_type' |
||
| 2170 | ) |
||
| 2171 | |||
| 2172 | if not isinstance(info_type, InfoType): |
||
| 2173 | raise InvalidArgumentType( |
||
| 2174 | function=self.get_info_list.__name__, |
||
| 2175 | argument='info_type', |
||
| 2176 | arg_type=InfoType.__name__, |
||
| 2177 | ) |
||
| 2178 | |||
| 2179 | cmd = XmlCommand("get_info") |
||
| 2180 | |||
| 2181 | cmd.set_attribute("type", info_type.value) |
||
| 2182 | |||
| 2183 | add_filter(cmd, filter, filter_id) |
||
| 2184 | |||
| 2185 | if name: |
||
| 2186 | cmd.set_attribute("name", name) |
||
| 2187 | |||
| 2188 | if details is not None: |
||
| 2189 | cmd.set_attribute("details", to_bool(details)) |
||
| 2190 | |||
| 2191 | return self._send_xml_command(cmd) |
||
| 2192 | |||
| 2193 | def get_info(self, info_id: str, info_type: InfoType) -> Any: |
||
| 2194 | """Request a single secinfo |
||
| 2195 | |||
| 2196 | Arguments: |
||
| 2197 | info_id: UUID of an existing secinfo |
||
| 2198 | info_type: Type must be either CERT_BUND_ADV, CPE, CVE, |
||
| 2199 | DFN_CERT_ADV, OVALDEF, NVT |
||
| 2200 | |||
| 2201 | Returns: |
||
| 2202 | The response. See :py:meth:`send_command` for details. |
||
| 2203 | """ |
||
| 2204 | if not info_type: |
||
| 2205 | raise RequiredArgument( |
||
| 2206 | function=self.get_info.__name__, argument='info_type' |
||
| 2207 | ) |
||
| 2208 | |||
| 2209 | if not isinstance(info_type, InfoType): |
||
| 2210 | raise InvalidArgumentType( |
||
| 2211 | function=self.get_info.__name__, |
||
| 2212 | argument='info_type', |
||
| 2213 | arg_type=InfoType.__name__, |
||
| 2214 | ) |
||
| 2215 | |||
| 2216 | if not info_id: |
||
| 2217 | raise RequiredArgument( |
||
| 2218 | function=self.get_info.__name__, argument='info_id' |
||
| 2219 | ) |
||
| 2220 | |||
| 2221 | cmd = XmlCommand("get_info") |
||
| 2222 | cmd.set_attribute("info_id", info_id) |
||
| 2223 | |||
| 2224 | cmd.set_attribute("type", info_type.value) |
||
| 2225 | |||
| 2226 | # for single entity always request all details |
||
| 2227 | cmd.set_attribute("details", "1") |
||
| 2228 | return self._send_xml_command(cmd) |
||
| 2229 | |||
| 2230 | def create_target( |
||
| 2231 | self, |
||
| 2232 | name: str, |
||
| 2233 | *, |
||
| 2234 | make_unique: Optional[bool] = None, |
||
| 2235 | asset_hosts_filter: Optional[str] = None, |
||
| 2236 | hosts: Optional[List[str]] = None, |
||
| 2237 | comment: Optional[str] = None, |
||
| 2238 | exclude_hosts: Optional[List[str]] = None, |
||
| 2239 | ssh_credential_id: Optional[str] = None, |
||
| 2240 | ssh_credential_port: Optional[int] = None, |
||
| 2241 | smb_credential_id: Optional[str] = None, |
||
| 2242 | esxi_credential_id: Optional[str] = None, |
||
| 2243 | snmp_credential_id: Optional[str] = None, |
||
| 2244 | alive_test: Optional[AliveTest] = None, |
||
| 2245 | reverse_lookup_only: Optional[bool] = None, |
||
| 2246 | reverse_lookup_unify: Optional[bool] = None, |
||
| 2247 | port_range: Optional[str] = None, |
||
| 2248 | port_list_id: Optional[str] = None, |
||
| 2249 | ) -> Any: |
||
| 2250 | """Create a new target |
||
| 2251 | |||
| 2252 | Arguments: |
||
| 2253 | name: Name of the target |
||
| 2254 | make_unique: Deprecated. Will be ignored. |
||
| 2255 | asset_hosts_filter: Filter to select target host from assets hosts |
||
| 2256 | hosts: List of hosts addresses to scan |
||
| 2257 | exclude_hosts: List of hosts addresses to exclude from scan |
||
| 2258 | comment: Comment for the target |
||
| 2259 | ssh_credential_id: UUID of a ssh credential to use on target |
||
| 2260 | ssh_credential_port: The port to use for ssh credential |
||
| 2261 | smb_credential_id: UUID of a smb credential to use on target |
||
| 2262 | snmp_credential_id: UUID of a snmp credential to use on target |
||
| 2263 | esxi_credential_id: UUID of a esxi credential to use on target |
||
| 2264 | alive_test: Which alive test to use |
||
| 2265 | reverse_lookup_only: Whether to scan only hosts that have names |
||
| 2266 | reverse_lookup_unify: Whether to scan only one IP when multiple IPs |
||
| 2267 | have the same name. |
||
| 2268 | port_range: Port range for the target |
||
| 2269 | port_list_id: UUID of the port list to use on target |
||
| 2270 | |||
| 2271 | Returns: |
||
| 2272 | The response. See :py:meth:`send_command` for details. |
||
| 2273 | """ |
||
| 2274 | |||
| 2275 | cmd = XmlCommand("create_target") |
||
| 2276 | _xmlname = cmd.add_element("name", name) |
||
| 2277 | |||
| 2278 | if make_unique is not None: |
||
| 2279 | warnings.warn( |
||
| 2280 | 'create_target make_unique argument is deprecated ' |
||
| 2281 | 'and will be ignored.', |
||
| 2282 | DeprecationWarning, |
||
| 2283 | ) |
||
| 2284 | |||
| 2285 | if not name: |
||
| 2286 | raise RequiredArgument( |
||
| 2287 | function=self.create_target.__name__, argument='name' |
||
| 2288 | ) |
||
| 2289 | |||
| 2290 | if asset_hosts_filter: |
||
| 2291 | cmd.add_element( |
||
| 2292 | "asset_hosts", attrs={"filter": str(asset_hosts_filter)} |
||
| 2293 | ) |
||
| 2294 | elif hosts: |
||
| 2295 | cmd.add_element("hosts", to_comma_list(hosts)) |
||
| 2296 | else: |
||
| 2297 | raise RequiredArgument( |
||
| 2298 | function=self.create_target.__name__, |
||
| 2299 | argument='hosts or asset_hosts_filter', |
||
| 2300 | ) |
||
| 2301 | |||
| 2302 | if comment: |
||
| 2303 | cmd.add_element("comment", comment) |
||
| 2304 | |||
| 2305 | if exclude_hosts: |
||
| 2306 | cmd.add_element("exclude_hosts", to_comma_list(exclude_hosts)) |
||
| 2307 | |||
| 2308 | if ssh_credential_id: |
||
| 2309 | _xmlssh = cmd.add_element( |
||
| 2310 | "ssh_credential", attrs={"id": ssh_credential_id} |
||
| 2311 | ) |
||
| 2312 | if ssh_credential_port: |
||
| 2313 | _xmlssh.add_element("port", str(ssh_credential_port)) |
||
| 2314 | |||
| 2315 | if smb_credential_id: |
||
| 2316 | cmd.add_element("smb_credential", attrs={"id": smb_credential_id}) |
||
| 2317 | |||
| 2318 | if esxi_credential_id: |
||
| 2319 | cmd.add_element("esxi_credential", attrs={"id": esxi_credential_id}) |
||
| 2320 | |||
| 2321 | if snmp_credential_id: |
||
| 2322 | cmd.add_element("snmp_credential", attrs={"id": snmp_credential_id}) |
||
| 2323 | |||
| 2324 | if alive_test: |
||
| 2325 | if not isinstance(alive_test, AliveTest): |
||
| 2326 | raise InvalidArgumentType( |
||
| 2327 | function=self.create_target.__name__, |
||
| 2328 | argument='alive_test', |
||
| 2329 | arg_type=AliveTest.__name__, |
||
| 2330 | ) |
||
| 2331 | |||
| 2332 | cmd.add_element("alive_tests", alive_test.value) |
||
| 2333 | |||
| 2334 | if reverse_lookup_only is not None: |
||
| 2335 | cmd.add_element("reverse_lookup_only", to_bool(reverse_lookup_only)) |
||
| 2336 | |||
| 2337 | if reverse_lookup_unify is not None: |
||
| 2338 | cmd.add_element( |
||
| 2339 | "reverse_lookup_unify", to_bool(reverse_lookup_unify) |
||
| 2340 | ) |
||
| 2341 | |||
| 2342 | # since 20.08 one of port_range or port_list_id is required! |
||
| 2343 | if not port_range and not port_list_id: |
||
| 2344 | raise RequiredArgument( |
||
| 2345 | function=self.create_target.__name__, |
||
| 2346 | argument='port_range or port_list_id', |
||
| 2347 | ) |
||
| 2348 | |||
| 2349 | if port_range: |
||
| 2350 | cmd.add_element("port_range", port_range) |
||
| 2351 | |||
| 2352 | if port_list_id: |
||
| 2353 | cmd.add_element("port_list", attrs={"id": port_list_id}) |
||
| 2354 | |||
| 2355 | return self._send_xml_command(cmd) |
||
| 2356 | |||
| 2357 | def get_feed(self, feed_type: Optional[FeedType]) -> Any: |
||
| 2358 | """Request a single feed |
||
| 2359 | |||
| 2360 | Arguments: |
||
| 2361 | feed_type: Type of single feed to get: NVT, CERT or SCAP |
||
| 2362 | |||
| 2363 | Returns: |
||
| 2364 | The response. See :py:meth:`send_command` for details. |
||
| 2365 | """ |
||
| 2366 | if not feed_type: |
||
| 2367 | raise RequiredArgument( |
||
| 2368 | function=self.get_feed.__name__, argument='feed_type' |
||
| 2369 | ) |
||
| 2370 | |||
| 2371 | if not isinstance(feed_type, FeedType): |
||
| 2372 | raise InvalidArgumentType( |
||
| 2373 | function=self.get_feed.__name__, |
||
| 2374 | argument='feed_type', |
||
| 2375 | arg_type=FeedType.__name__, |
||
| 2376 | ) |
||
| 2377 | |||
| 2378 | cmd = XmlCommand("get_feeds") |
||
| 2379 | cmd.set_attribute("type", feed_type.value) |
||
| 2380 | |||
| 2381 | return self._send_xml_command(cmd) |
||
| 2382 | |||
| 2383 | def create_credential( |
||
| 2384 | self, |
||
| 2385 | name: str, |
||
| 2386 | credential_type: CredentialType, |
||
| 2387 | *, |
||
| 2388 | comment: Optional[str] = None, |
||
| 2389 | allow_insecure: Optional[bool] = None, |
||
| 2390 | certificate: Optional[str] = None, |
||
| 2391 | key_phrase: Optional[str] = None, |
||
| 2392 | private_key: Optional[str] = None, |
||
| 2393 | login: Optional[str] = None, |
||
| 2394 | password: Optional[str] = None, |
||
| 2395 | auth_algorithm: Optional[SnmpAuthAlgorithm] = None, |
||
| 2396 | community: Optional[str] = None, |
||
| 2397 | privacy_algorithm: Optional[SnmpPrivacyAlgorithm] = None, |
||
| 2398 | privacy_password: Optional[str] = None, |
||
| 2399 | public_key: Optional[str] = None, |
||
| 2400 | ) -> Any: |
||
| 2401 | """Create a new credential |
||
| 2402 | |||
| 2403 | Create a new credential e.g. to be used in the method of an alert. |
||
| 2404 | |||
| 2405 | Currently the following credential types are supported: |
||
| 2406 | |||
| 2407 | - Username + Password |
||
| 2408 | - Username + SSH-Key |
||
| 2409 | - Client Certificates |
||
| 2410 | - SNMPv1 or SNMPv2c protocol |
||
| 2411 | - S/MIME Certificate |
||
| 2412 | - OpenPGP Key |
||
| 2413 | - Password only |
||
| 2414 | |||
| 2415 | Arguments: |
||
| 2416 | name: Name of the new credential |
||
| 2417 | credential_type: The credential type. |
||
| 2418 | comment: Comment for the credential |
||
| 2419 | allow_insecure: Whether to allow insecure use of the credential |
||
| 2420 | certificate: Certificate for the credential. |
||
| 2421 | Required for client-certificate and smime credential types. |
||
| 2422 | key_phrase: Key passphrase for the private key. |
||
| 2423 | Used for the username+ssh-key credential type. |
||
| 2424 | private_key: Private key to use for login. Required |
||
| 2425 | for usk credential type. Also used for the cc credential type. |
||
| 2426 | The supported key types (dsa, rsa, ecdsa, ...) and formats (PEM, |
||
| 2427 | PKC#12, OpenSSL, ...) depend on your installed GnuTLS version. |
||
| 2428 | login: Username for the credential. Required for username+password, |
||
| 2429 | username+ssh-key and snmp credential type. |
||
| 2430 | password: Password for the credential. Used for username+password |
||
| 2431 | and snmp credential types. |
||
| 2432 | community: The SNMP community |
||
| 2433 | auth_algorithm: The SNMP authentication algorithm. Required for snmp |
||
| 2434 | credential type. |
||
| 2435 | privacy_algorithm: The SNMP privacy algorithm |
||
| 2436 | privacy_password: The SNMP privacy password |
||
| 2437 | public_key: PGP public key in *armor* plain text format. Required |
||
| 2438 | for pgp credential type. |
||
| 2439 | |||
| 2440 | Examples: |
||
| 2441 | Creating a Username + Password credential |
||
| 2442 | |||
| 2443 | .. code-block:: python |
||
| 2444 | |||
| 2445 | gmp.create_credential( |
||
| 2446 | name='UP Credential', |
||
| 2447 | credential_type=CredentialType.USERNAME_PASSWORD, |
||
| 2448 | login='foo', |
||
| 2449 | password='bar', |
||
| 2450 | ) |
||
| 2451 | |||
| 2452 | Creating a Username + SSH Key credential |
||
| 2453 | |||
| 2454 | .. code-block:: python |
||
| 2455 | |||
| 2456 | with open('path/to/private-ssh-key') as f: |
||
| 2457 | key = f.read() |
||
| 2458 | |||
| 2459 | gmp.create_credential( |
||
| 2460 | name='USK Credential', |
||
| 2461 | credential_type=CredentialType.USERNAME_SSH_KEY, |
||
| 2462 | login='foo', |
||
| 2463 | key_phrase='foobar', |
||
| 2464 | private_key=key, |
||
| 2465 | ) |
||
| 2466 | |||
| 2467 | Creating a PGP credential |
||
| 2468 | |||
| 2469 | .. note:: |
||
| 2470 | |||
| 2471 | A compatible public pgp key file can be exported with GnuPG via |
||
| 2472 | :: |
||
| 2473 | |||
| 2474 | $ gpg --armor --export [email protected] > alice.asc |
||
| 2475 | |||
| 2476 | .. code-block:: python |
||
| 2477 | |||
| 2478 | with open('path/to/pgp.key.asc') as f: |
||
| 2479 | key = f.read() |
||
| 2480 | |||
| 2481 | gmp.create_credential( |
||
| 2482 | name='PGP Credential', |
||
| 2483 | credential_type=CredentialType.PGP_ENCRYPTION_KEY, |
||
| 2484 | public_key=key, |
||
| 2485 | ) |
||
| 2486 | |||
| 2487 | Creating a S/MIME credential |
||
| 2488 | |||
| 2489 | .. code-block:: python |
||
| 2490 | |||
| 2491 | with open('path/to/smime-cert') as f: |
||
| 2492 | cert = f.read() |
||
| 2493 | |||
| 2494 | gmp.create_credential( |
||
| 2495 | name='SMIME Credential', |
||
| 2496 | credential_type=CredentialType.SMIME_CERTIFICATE, |
||
| 2497 | certificate=cert, |
||
| 2498 | ) |
||
| 2499 | |||
| 2500 | Creating a Password-Only credential |
||
| 2501 | |||
| 2502 | .. code-block:: python |
||
| 2503 | |||
| 2504 | gmp.create_credential( |
||
| 2505 | name='Password-Only Credential', |
||
| 2506 | credential_type=CredentialType.PASSWORD_ONLY, |
||
| 2507 | password='foo', |
||
| 2508 | ) |
||
| 2509 | Returns: |
||
| 2510 | The response. See :py:meth:`send_command` for details. |
||
| 2511 | """ |
||
| 2512 | if not name: |
||
| 2513 | raise RequiredArgument( |
||
| 2514 | function=self.create_credential.__name__, argument='name' |
||
| 2515 | ) |
||
| 2516 | |||
| 2517 | if not isinstance(credential_type, self.types.CredentialType): |
||
| 2518 | raise InvalidArgumentType( |
||
| 2519 | function=self.create_credential.__name__, |
||
| 2520 | argument='credential_type', |
||
| 2521 | arg_type=CredentialType.__name__, |
||
| 2522 | ) |
||
| 2523 | |||
| 2524 | cmd = XmlCommand("create_credential") |
||
| 2525 | cmd.add_element("name", name) |
||
| 2526 | |||
| 2527 | cmd.add_element("type", credential_type.value) |
||
| 2528 | |||
| 2529 | if comment: |
||
| 2530 | cmd.add_element("comment", comment) |
||
| 2531 | |||
| 2532 | if allow_insecure is not None: |
||
| 2533 | cmd.add_element("allow_insecure", to_bool(allow_insecure)) |
||
| 2534 | |||
| 2535 | if ( |
||
| 2536 | credential_type == CredentialType.CLIENT_CERTIFICATE |
||
| 2537 | or credential_type == CredentialType.SMIME_CERTIFICATE |
||
| 2538 | ): |
||
| 2539 | if not certificate: |
||
| 2540 | raise RequiredArgument( |
||
| 2541 | function=self.create_credential.__name__, |
||
| 2542 | argument='certificate', |
||
| 2543 | ) |
||
| 2544 | |||
| 2545 | cmd.add_element("certificate", certificate) |
||
| 2546 | |||
| 2547 | if ( |
||
| 2548 | credential_type == CredentialType.USERNAME_PASSWORD |
||
| 2549 | or credential_type == CredentialType.USERNAME_SSH_KEY |
||
| 2550 | or credential_type == CredentialType.SNMP |
||
| 2551 | ): |
||
| 2552 | if not login: |
||
| 2553 | raise RequiredArgument( |
||
| 2554 | function=self.create_credential.__name__, argument='login' |
||
| 2555 | ) |
||
| 2556 | |||
| 2557 | cmd.add_element("login", login) |
||
| 2558 | |||
| 2559 | if credential_type == CredentialType.PASSWORD_ONLY and not password: |
||
| 2560 | raise RequiredArgument( |
||
| 2561 | function=self.create_credential.__name__, argument='password' |
||
| 2562 | ) |
||
| 2563 | |||
| 2564 | if ( |
||
| 2565 | credential_type == CredentialType.USERNAME_PASSWORD |
||
| 2566 | or credential_type == CredentialType.SNMP |
||
| 2567 | or credential_type == CredentialType.PASSWORD_ONLY |
||
| 2568 | ) and password: |
||
| 2569 | cmd.add_element("password", password) |
||
| 2570 | |||
| 2571 | if credential_type == CredentialType.USERNAME_SSH_KEY: |
||
| 2572 | if not private_key: |
||
| 2573 | raise RequiredArgument( |
||
| 2574 | function=self.create_credential.__name__, |
||
| 2575 | argument='private_key', |
||
| 2576 | ) |
||
| 2577 | |||
| 2578 | _xmlkey = cmd.add_element("key") |
||
| 2579 | _xmlkey.add_element("private", private_key) |
||
| 2580 | |||
| 2581 | if key_phrase: |
||
| 2582 | _xmlkey.add_element("phrase", key_phrase) |
||
| 2583 | |||
| 2584 | if credential_type == CredentialType.CLIENT_CERTIFICATE and private_key: |
||
| 2585 | _xmlkey = cmd.add_element("key") |
||
| 2586 | _xmlkey.add_element("private", private_key) |
||
| 2587 | |||
| 2588 | if credential_type == CredentialType.SNMP: |
||
| 2589 | if not isinstance(auth_algorithm, self.types.SnmpAuthAlgorithm): |
||
| 2590 | raise InvalidArgumentType( |
||
| 2591 | function=self.create_credential.__name__, |
||
| 2592 | argument='auth_algorithm', |
||
| 2593 | arg_type=SnmpAuthAlgorithm.__name__, |
||
| 2594 | ) |
||
| 2595 | |||
| 2596 | cmd.add_element("auth_algorithm", auth_algorithm.value) |
||
| 2597 | |||
| 2598 | if community: |
||
| 2599 | cmd.add_element("community", community) |
||
| 2600 | |||
| 2601 | View Code Duplication | if privacy_algorithm is not None or privacy_password: |
|
| 2602 | _xmlprivacy = cmd.add_element("privacy") |
||
| 2603 | |||
| 2604 | if privacy_algorithm is not None: |
||
| 2605 | if not isinstance( |
||
| 2606 | privacy_algorithm, self.types.SnmpPrivacyAlgorithm |
||
| 2607 | ): |
||
| 2608 | raise InvalidArgumentType( |
||
| 2609 | function=self.create_credential.__name__, |
||
| 2610 | argument='privacy_algorithm', |
||
| 2611 | arg_type=SnmpPrivacyAlgorithm.__name__, |
||
| 2612 | ) |
||
| 2613 | |||
| 2614 | _xmlprivacy.add_element( |
||
| 2615 | "algorithm", privacy_algorithm.value |
||
| 2616 | ) |
||
| 2617 | |||
| 2618 | if privacy_password: |
||
| 2619 | _xmlprivacy.add_element("password", privacy_password) |
||
| 2620 | |||
| 2621 | if credential_type == CredentialType.PGP_ENCRYPTION_KEY: |
||
| 2622 | if not public_key: |
||
| 2623 | raise RequiredArgument( |
||
| 2624 | function=self.create_credential.__name__, |
||
| 2625 | argument='public_key', |
||
| 2626 | ) |
||
| 2627 | |||
| 2628 | _xmlkey = cmd.add_element("key") |
||
| 2629 | _xmlkey.add_element("public", public_key) |
||
| 2630 | |||
| 2631 | return self._send_xml_command(cmd) |
||
| 2632 | |||
| 2633 | def modify_credential( |
||
| 2634 | self, |
||
| 2635 | credential_id: str, |
||
| 2636 | *, |
||
| 2637 | name: Optional[str] = None, |
||
| 2638 | comment: Optional[str] = None, |
||
| 2639 | allow_insecure: Optional[bool] = None, |
||
| 2640 | certificate: Optional[str] = None, |
||
| 2641 | key_phrase: Optional[str] = None, |
||
| 2642 | private_key: Optional[str] = None, |
||
| 2643 | login: Optional[str] = None, |
||
| 2644 | password: Optional[str] = None, |
||
| 2645 | auth_algorithm: Optional[SnmpAuthAlgorithm] = None, |
||
| 2646 | community: Optional[str] = None, |
||
| 2647 | privacy_algorithm: Optional[SnmpPrivacyAlgorithm] = None, |
||
| 2648 | privacy_password: Optional[str] = None, |
||
| 2649 | public_key: Optional[str] = None, |
||
| 2650 | ) -> Any: |
||
| 2651 | """Modifies an existing credential. |
||
| 2652 | |||
| 2653 | Arguments: |
||
| 2654 | credential_id: UUID of the credential |
||
| 2655 | name: Name of the credential |
||
| 2656 | comment: Comment for the credential |
||
| 2657 | allow_insecure: Whether to allow insecure use of the credential |
||
| 2658 | certificate: Certificate for the credential |
||
| 2659 | key_phrase: Key passphrase for the private key |
||
| 2660 | private_key: Private key to use for login |
||
| 2661 | login: Username for the credential |
||
| 2662 | password: Password for the credential |
||
| 2663 | auth_algorithm: The authentication algorithm for SNMP |
||
| 2664 | community: The SNMP community |
||
| 2665 | privacy_algorithm: The privacy algorithm for SNMP |
||
| 2666 | privacy_password: The SNMP privacy password |
||
| 2667 | public_key: PGP public key in *armor* plain text format |
||
| 2668 | |||
| 2669 | Returns: |
||
| 2670 | The response. See :py:meth:`send_command` for details. |
||
| 2671 | """ |
||
| 2672 | if not credential_id: |
||
| 2673 | raise RequiredArgument( |
||
| 2674 | function=self.modify_credential.__name__, |
||
| 2675 | argument='credential_id', |
||
| 2676 | ) |
||
| 2677 | |||
| 2678 | cmd = XmlCommand("modify_credential") |
||
| 2679 | cmd.set_attribute("credential_id", credential_id) |
||
| 2680 | |||
| 2681 | if comment: |
||
| 2682 | cmd.add_element("comment", comment) |
||
| 2683 | |||
| 2684 | if name: |
||
| 2685 | cmd.add_element("name", name) |
||
| 2686 | |||
| 2687 | if allow_insecure is not None: |
||
| 2688 | cmd.add_element("allow_insecure", to_bool(allow_insecure)) |
||
| 2689 | |||
| 2690 | if certificate: |
||
| 2691 | cmd.add_element("certificate", certificate) |
||
| 2692 | |||
| 2693 | if key_phrase and private_key: |
||
| 2694 | _xmlkey = cmd.add_element("key") |
||
| 2695 | _xmlkey.add_element("phrase", key_phrase) |
||
| 2696 | _xmlkey.add_element("private", private_key) |
||
| 2697 | elif (not key_phrase and private_key) or ( |
||
| 2698 | key_phrase and not private_key |
||
| 2699 | ): |
||
| 2700 | raise RequiredArgument( |
||
| 2701 | function=self.modify_credential.__name__, |
||
| 2702 | argument='key_phrase and private_key', |
||
| 2703 | ) |
||
| 2704 | |||
| 2705 | if login: |
||
| 2706 | cmd.add_element("login", login) |
||
| 2707 | |||
| 2708 | if password: |
||
| 2709 | cmd.add_element("password", password) |
||
| 2710 | |||
| 2711 | if auth_algorithm: |
||
| 2712 | if not isinstance(auth_algorithm, self.types.SnmpAuthAlgorithm): |
||
| 2713 | raise InvalidArgumentType( |
||
| 2714 | function=self.modify_credential.__name__, |
||
| 2715 | argument='auth_algorithm', |
||
| 2716 | arg_type=SnmpAuthAlgorithm.__name__, |
||
| 2717 | ) |
||
| 2718 | cmd.add_element("auth_algorithm", auth_algorithm.value) |
||
| 2719 | |||
| 2720 | if community: |
||
| 2721 | cmd.add_element("community", community) |
||
| 2722 | |||
| 2723 | View Code Duplication | if privacy_algorithm is not None or privacy_password is not None: |
|
| 2724 | _xmlprivacy = cmd.add_element("privacy") |
||
| 2725 | |||
| 2726 | if privacy_algorithm is not None: |
||
| 2727 | if not isinstance( |
||
| 2728 | privacy_algorithm, self.types.SnmpPrivacyAlgorithm |
||
| 2729 | ): |
||
| 2730 | raise InvalidArgumentType( |
||
| 2731 | function=self.modify_credential.__name__, |
||
| 2732 | argument='privacy_algorithm', |
||
| 2733 | arg_type=SnmpPrivacyAlgorithm.__name__, |
||
| 2734 | ) |
||
| 2735 | |||
| 2736 | _xmlprivacy.add_element("algorithm", privacy_algorithm.value) |
||
| 2737 | |||
| 2738 | if privacy_password is not None: |
||
| 2739 | _xmlprivacy.add_element("password", privacy_password) |
||
| 2740 | |||
| 2741 | if public_key: |
||
| 2742 | _xmlkey = cmd.add_element("key") |
||
| 2743 | _xmlkey.add_element("public", public_key) |
||
| 2744 | |||
| 2745 | return self._send_xml_command(cmd) |
||
| 2746 | |||
| 2747 | def create_ticket( |
||
| 2748 | self, |
||
| 2749 | *, |
||
| 2750 | result_id: str, |
||
| 2751 | assigned_to_user_id: str, |
||
| 2752 | note: str, |
||
| 2753 | comment: Optional[str] = None, |
||
| 2754 | ) -> Any: |
||
| 2755 | """Create a new ticket |
||
| 2756 | |||
| 2757 | Arguments: |
||
| 2758 | result_id: UUID of the result the ticket applies to |
||
| 2759 | assigned_to_user_id: UUID of a user the ticket should be assigned to |
||
| 2760 | note: A note about opening the ticket |
||
| 2761 | comment: Comment for the ticket |
||
| 2762 | |||
| 2763 | Returns: |
||
| 2764 | The response. See :py:meth:`send_command` for details. |
||
| 2765 | """ |
||
| 2766 | if not result_id: |
||
| 2767 | raise RequiredArgument( |
||
| 2768 | function=self.create_ticket.__name__, argument='result_id' |
||
| 2769 | ) |
||
| 2770 | |||
| 2771 | if not assigned_to_user_id: |
||
| 2772 | raise RequiredArgument( |
||
| 2773 | function=self.create_ticket.__name__, |
||
| 2774 | argument='assigned_to_user_id', |
||
| 2775 | ) |
||
| 2776 | |||
| 2777 | if not note: |
||
| 2778 | raise RequiredArgument( |
||
| 2779 | function=self.create_ticket.__name__, argument='note' |
||
| 2780 | ) |
||
| 2781 | |||
| 2782 | cmd = XmlCommand("create_ticket") |
||
| 2783 | |||
| 2784 | _result = cmd.add_element("result") |
||
| 2785 | _result.set_attribute("id", result_id) |
||
| 2786 | |||
| 2787 | _assigned = cmd.add_element("assigned_to") |
||
| 2788 | _user = _assigned.add_element("user") |
||
| 2789 | _user.set_attribute("id", assigned_to_user_id) |
||
| 2790 | |||
| 2791 | _note = cmd.add_element("open_note", note) |
||
| 2792 | |||
| 2793 | if comment: |
||
| 2794 | cmd.add_element("comment", comment) |
||
| 2795 | |||
| 2796 | return self._send_xml_command(cmd) |
||
| 2797 | |||
| 2798 | def delete_ticket( |
||
| 2799 | self, ticket_id: str, *, ultimate: Optional[bool] = False |
||
| 2800 | ): |
||
| 2801 | """Deletes an existing ticket |
||
| 2802 | |||
| 2803 | Arguments: |
||
| 2804 | ticket_id: UUID of the ticket to be deleted. |
||
| 2805 | ultimate: Whether to remove entirely, or to the trashcan. |
||
| 2806 | """ |
||
| 2807 | if not ticket_id: |
||
| 2808 | raise RequiredArgument( |
||
| 2809 | function=self.delete_ticket.__name__, argument='ticket_id' |
||
| 2810 | ) |
||
| 2811 | |||
| 2812 | cmd = XmlCommand("delete_ticket") |
||
| 2813 | cmd.set_attribute("ticket_id", ticket_id) |
||
| 2814 | cmd.set_attribute("ultimate", to_bool(ultimate)) |
||
| 2815 | |||
| 2816 | return self._send_xml_command(cmd) |
||
| 2817 | |||
| 2818 | View Code Duplication | def get_tickets( |
|
| 2819 | self, |
||
| 2820 | *, |
||
| 2821 | trash: Optional[bool] = None, |
||
| 2822 | filter: Optional[str] = None, |
||
| 2823 | filter_id: Optional[str] = None, |
||
| 2824 | ) -> Any: |
||
| 2825 | """Request a list of tickets |
||
| 2826 | |||
| 2827 | Arguments: |
||
| 2828 | filter: Filter term to use for the query |
||
| 2829 | filter_id: UUID of an existing filter to use for the query |
||
| 2830 | trash: True to request the tickets in the trashcan |
||
| 2831 | |||
| 2832 | Returns: |
||
| 2833 | The response. See :py:meth:`send_command` for details. |
||
| 2834 | """ |
||
| 2835 | cmd = XmlCommand("get_tickets") |
||
| 2836 | |||
| 2837 | add_filter(cmd, filter, filter_id) |
||
| 2838 | |||
| 2839 | if trash is not None: |
||
| 2840 | cmd.set_attribute("trash", to_bool(trash)) |
||
| 2841 | |||
| 2842 | return self._send_xml_command(cmd) |
||
| 2843 | |||
| 2844 | def get_ticket(self, ticket_id: str) -> Any: |
||
| 2845 | """Request a single ticket |
||
| 2846 | |||
| 2847 | Arguments: |
||
| 2848 | ticket_id: UUID of an existing ticket |
||
| 2849 | |||
| 2850 | Returns: |
||
| 2851 | The response. See :py:meth:`send_command` for details. |
||
| 2852 | """ |
||
| 2853 | if not ticket_id: |
||
| 2854 | raise RequiredArgument( |
||
| 2855 | function=self.get_ticket.__name__, argument='ticket_id' |
||
| 2856 | ) |
||
| 2857 | |||
| 2858 | cmd = XmlCommand("get_tickets") |
||
| 2859 | cmd.set_attribute("ticket_id", ticket_id) |
||
| 2860 | return self._send_xml_command(cmd) |
||
| 2861 | |||
| 2862 | def get_vulnerabilities( |
||
| 2863 | self, *, filter: Optional[str] = None, filter_id: Optional[str] = None |
||
| 2864 | ) -> Any: |
||
| 2865 | """Request a list of vulnerabilities |
||
| 2866 | |||
| 2867 | Arguments: |
||
| 2868 | filter: Filter term to use for the query |
||
| 2869 | filter_id: UUID of an existing filter to use for the query |
||
| 2870 | Returns: |
||
| 2871 | The response. See :py:meth:`send_command` for details. |
||
| 2872 | """ |
||
| 2873 | cmd = XmlCommand("get_vulns") |
||
| 2874 | |||
| 2875 | add_filter(cmd, filter, filter_id) |
||
| 2876 | |||
| 2877 | return self._send_xml_command(cmd) |
||
| 2878 | |||
| 2879 | def get_vulnerability(self, vulnerability_id: str) -> Any: |
||
| 2880 | """Request a single vulnerability |
||
| 2881 | |||
| 2882 | Arguments: |
||
| 2883 | vulnerability_id: ID of an existing vulnerability |
||
| 2884 | |||
| 2885 | Returns: |
||
| 2886 | The response. See :py:meth:`send_command` for details. |
||
| 2887 | """ |
||
| 2888 | if not vulnerability_id: |
||
| 2889 | raise RequiredArgument( |
||
| 2890 | function=self.get_vulnerability.__name__, |
||
| 2891 | argument='vulnerability_id', |
||
| 2892 | ) |
||
| 2893 | |||
| 2894 | cmd = XmlCommand("get_vulns") |
||
| 2895 | cmd.set_attribute("vuln_id", vulnerability_id) |
||
| 2896 | return self._send_xml_command(cmd) |
||
| 2897 | |||
| 2898 | def modify_ticket( |
||
| 2899 | self, |
||
| 2900 | ticket_id: str, |
||
| 2901 | *, |
||
| 2902 | status: Optional[TicketStatus] = None, |
||
| 2903 | note: Optional[str] = None, |
||
| 2904 | assigned_to_user_id: Optional[str] = None, |
||
| 2905 | comment: Optional[str] = None, |
||
| 2906 | ) -> Any: |
||
| 2907 | """Modify a single ticket |
||
| 2908 | |||
| 2909 | Arguments: |
||
| 2910 | ticket_id: UUID of an existing ticket |
||
| 2911 | status: New status for the ticket |
||
| 2912 | note: Note for the status change. Required if status is set. |
||
| 2913 | assigned_to_user_id: UUID of the user the ticket should be assigned |
||
| 2914 | to |
||
| 2915 | comment: Comment for the ticket |
||
| 2916 | |||
| 2917 | Returns: |
||
| 2918 | The response. See :py:meth:`send_command` for details. |
||
| 2919 | """ |
||
| 2920 | if not ticket_id: |
||
| 2921 | raise RequiredArgument( |
||
| 2922 | function=self.modify_ticket.__name__, argument='ticket_id' |
||
| 2923 | ) |
||
| 2924 | |||
| 2925 | if status and not note: |
||
| 2926 | raise RequiredArgument( |
||
| 2927 | function=self.modify_ticket.__name__, argument='note' |
||
| 2928 | ) |
||
| 2929 | |||
| 2930 | if note and not status: |
||
| 2931 | raise RequiredArgument( |
||
| 2932 | function=self.modify_ticket.__name__, argument='status' |
||
| 2933 | ) |
||
| 2934 | |||
| 2935 | cmd = XmlCommand("modify_ticket") |
||
| 2936 | cmd.set_attribute("ticket_id", ticket_id) |
||
| 2937 | |||
| 2938 | if assigned_to_user_id: |
||
| 2939 | _assigned = cmd.add_element("assigned_to") |
||
| 2940 | _user = _assigned.add_element("user") |
||
| 2941 | _user.set_attribute("id", assigned_to_user_id) |
||
| 2942 | |||
| 2943 | if status: |
||
| 2944 | if not isinstance(status, self.types.TicketStatus): |
||
| 2945 | raise InvalidArgumentType( |
||
| 2946 | function=self.modify_ticket.__name__, |
||
| 2947 | argument='status', |
||
| 2948 | arg_type=TicketStatus.__name__, |
||
| 2949 | ) |
||
| 2950 | |||
| 2951 | cmd.add_element('status', status.value) |
||
| 2952 | cmd.add_element('{}_note'.format(status.name.lower()), note) |
||
| 2953 | |||
| 2954 | if comment: |
||
| 2955 | cmd.add_element("comment", comment) |
||
| 2956 | |||
| 2957 | return self._send_xml_command(cmd) |
||
| 2958 | |||
| 2959 | View Code Duplication | def create_filter( |
|
| 2960 | self, |
||
| 2961 | name: str, |
||
| 2962 | *, |
||
| 2963 | filter_type: Optional[FilterType] = None, |
||
| 2964 | comment: Optional[str] = None, |
||
| 2965 | term: Optional[str] = None, |
||
| 2966 | ) -> Any: |
||
| 2967 | """Create a new filter |
||
| 2968 | |||
| 2969 | Arguments: |
||
| 2970 | name: Name of the new filter |
||
| 2971 | filter_type: Filter for entity type |
||
| 2972 | comment: Comment for the filter |
||
| 2973 | term: Filter term e.g. 'name=foo' |
||
| 2974 | |||
| 2975 | Returns: |
||
| 2976 | The response. See :py:meth:`send_command` for details. |
||
| 2977 | """ |
||
| 2978 | if not name: |
||
| 2979 | raise RequiredArgument( |
||
| 2980 | function=self.create_filter.__name__, argument="name" |
||
| 2981 | ) |
||
| 2982 | |||
| 2983 | cmd = XmlCommand("create_filter") |
||
| 2984 | _xmlname = cmd.add_element("name", name) |
||
| 2985 | |||
| 2986 | if comment: |
||
| 2987 | cmd.add_element("comment", comment) |
||
| 2988 | |||
| 2989 | if term: |
||
| 2990 | cmd.add_element("term", term) |
||
| 2991 | |||
| 2992 | if filter_type: |
||
| 2993 | if not isinstance(filter_type, self.types.FilterType): |
||
| 2994 | raise InvalidArgumentType( |
||
| 2995 | function=self.create_filter.__name__, |
||
| 2996 | argument="filter_type", |
||
| 2997 | arg_type=self.types.FilterType.__name__, |
||
| 2998 | ) |
||
| 2999 | |||
| 3000 | cmd.add_element("type", filter_type.value) |
||
| 3001 | |||
| 3002 | return self._send_xml_command(cmd) |
||
| 3003 | |||
| 3004 | View Code Duplication | def modify_filter( |
|
| 3005 | self, |
||
| 3006 | filter_id: str, |
||
| 3007 | *, |
||
| 3008 | comment: Optional[str] = None, |
||
| 3009 | name: Optional[str] = None, |
||
| 3010 | term: Optional[str] = None, |
||
| 3011 | filter_type: Optional[FilterType] = None, |
||
| 3012 | ) -> Any: |
||
| 3013 | """Modifies an existing filter. |
||
| 3014 | |||
| 3015 | Arguments: |
||
| 3016 | filter_id: UUID of the filter to be modified |
||
| 3017 | comment: Comment on filter. |
||
| 3018 | name: Name of filter. |
||
| 3019 | term: Filter term. |
||
| 3020 | filter_type: Resource type filter applies to. |
||
| 3021 | |||
| 3022 | Returns: |
||
| 3023 | The response. See :py:meth:`send_command` for details. |
||
| 3024 | """ |
||
| 3025 | if not filter_id: |
||
| 3026 | raise RequiredArgument( |
||
| 3027 | function=self.modify_filter.__name__, argument='filter_id' |
||
| 3028 | ) |
||
| 3029 | |||
| 3030 | cmd = XmlCommand("modify_filter") |
||
| 3031 | cmd.set_attribute("filter_id", filter_id) |
||
| 3032 | |||
| 3033 | if comment: |
||
| 3034 | cmd.add_element("comment", comment) |
||
| 3035 | |||
| 3036 | if name: |
||
| 3037 | cmd.add_element("name", name) |
||
| 3038 | |||
| 3039 | if term: |
||
| 3040 | cmd.add_element("term", term) |
||
| 3041 | |||
| 3042 | if filter_type: |
||
| 3043 | if not isinstance(filter_type, self.types.FilterType): |
||
| 3044 | raise InvalidArgumentType( |
||
| 3045 | function=self.modify_filter.__name__, |
||
| 3046 | argument='filter_type', |
||
| 3047 | arg_type=FilterType.__name__, |
||
| 3048 | ) |
||
| 3049 | cmd.add_element("type", filter_type.value) |
||
| 3050 | |||
| 3051 | return self._send_xml_command(cmd) |
||
| 3052 | |||
| 3053 | def create_schedule( |
||
| 3054 | self, |
||
| 3055 | name: str, |
||
| 3056 | icalendar: str, |
||
| 3057 | timezone: str, |
||
| 3058 | *, |
||
| 3059 | comment: Optional[str] = None, |
||
| 3060 | ) -> Any: |
||
| 3061 | """Create a new schedule based in `iCalendar`_ data. |
||
| 3062 | |||
| 3063 | Example: |
||
| 3064 | Requires https://pypi.org/project/icalendar/ |
||
| 3065 | |||
| 3066 | .. code-block:: python |
||
| 3067 | |||
| 3068 | import pytz |
||
| 3069 | |||
| 3070 | from datetime import datetime |
||
| 3071 | |||
| 3072 | from icalendar import Calendar, Event |
||
| 3073 | |||
| 3074 | cal = Calendar() |
||
| 3075 | |||
| 3076 | cal.add('prodid', '-//Foo Bar//') |
||
| 3077 | cal.add('version', '2.0') |
||
| 3078 | |||
| 3079 | event = Event() |
||
| 3080 | event.add('dtstamp', datetime.now(tz=pytz.UTC)) |
||
| 3081 | event.add('dtstart', datetime(2020, 1, 1, tzinfo=pytz.utc)) |
||
| 3082 | |||
| 3083 | cal.add_component(event) |
||
| 3084 | |||
| 3085 | gmp.create_schedule( |
||
| 3086 | name="My Schedule", |
||
| 3087 | icalendar=cal.to_ical(), |
||
| 3088 | timezone='UTC' |
||
| 3089 | ) |
||
| 3090 | |||
| 3091 | |||
| 3092 | Arguments: |
||
| 3093 | name: Name of the new schedule |
||
| 3094 | icalendar: `iCalendar`_ (RFC 5545) based data. |
||
| 3095 | timezone: Timezone to use for the icalender events e.g |
||
| 3096 | Europe/Berlin. If the datetime values in the icalendar data are |
||
| 3097 | missing timezone information this timezone gets applied. |
||
| 3098 | Otherwise the datetime values from the icalendar data are |
||
| 3099 | displayed in this timezone |
||
| 3100 | comment: Comment on schedule. |
||
| 3101 | |||
| 3102 | Returns: |
||
| 3103 | The response. See :py:meth:`send_command` for details. |
||
| 3104 | |||
| 3105 | .. _iCalendar: |
||
| 3106 | https://tools.ietf.org/html/rfc5545 |
||
| 3107 | """ |
||
| 3108 | if not name: |
||
| 3109 | raise RequiredArgument( |
||
| 3110 | function=self.create_schedule.__name__, argument='name' |
||
| 3111 | ) |
||
| 3112 | if not icalendar: |
||
| 3113 | raise RequiredArgument( |
||
| 3114 | function=self.create_schedule.__name__, argument='icalendar' |
||
| 3115 | ) |
||
| 3116 | if not timezone: |
||
| 3117 | raise RequiredArgument( |
||
| 3118 | function=self.create_schedule.__name__, argument='timezone' |
||
| 3119 | ) |
||
| 3120 | |||
| 3121 | cmd = XmlCommand("create_schedule") |
||
| 3122 | |||
| 3123 | cmd.add_element("name", name) |
||
| 3124 | cmd.add_element("icalendar", icalendar) |
||
| 3125 | cmd.add_element("timezone", timezone) |
||
| 3126 | |||
| 3127 | if comment: |
||
| 3128 | cmd.add_element("comment", comment) |
||
| 3129 | |||
| 3130 | return self._send_xml_command(cmd) |
||
| 3131 | |||
| 3132 | def modify_schedule( |
||
| 3133 | self, |
||
| 3134 | schedule_id: str, |
||
| 3135 | *, |
||
| 3136 | name: Optional[str] = None, |
||
| 3137 | icalendar: Optional[str] = None, |
||
| 3138 | timezone: Optional[str] = None, |
||
| 3139 | comment: Optional[str] = None, |
||
| 3140 | ) -> Any: |
||
| 3141 | """Modifies an existing schedule |
||
| 3142 | |||
| 3143 | Arguments: |
||
| 3144 | schedule_id: UUID of the schedule to be modified |
||
| 3145 | name: Name of the schedule |
||
| 3146 | icalendar: `iCalendar`_ (RFC 5545) based data. |
||
| 3147 | timezone: Timezone to use for the icalender events e.g |
||
| 3148 | Europe/Berlin. If the datetime values in the icalendar data are |
||
| 3149 | missing timezone information this timezone gets applied. |
||
| 3150 | Otherwise the datetime values from the icalendar data are |
||
| 3151 | displayed in this timezone |
||
| 3152 | commenhedule. |
||
| 3153 | |||
| 3154 | Returns: |
||
| 3155 | The response. See :py:meth:`send_command` for details. |
||
| 3156 | |||
| 3157 | .. _iCalendar: |
||
| 3158 | https://tools.ietf.org/html/rfc5545 |
||
| 3159 | """ |
||
| 3160 | if not schedule_id: |
||
| 3161 | raise RequiredArgument( |
||
| 3162 | function=self.modify_schedule.__name__, argument='schedule_id' |
||
| 3163 | ) |
||
| 3164 | |||
| 3165 | cmd = XmlCommand("modify_schedule") |
||
| 3166 | cmd.set_attribute("schedule_id", schedule_id) |
||
| 3167 | |||
| 3168 | if name: |
||
| 3169 | cmd.add_element("name", name) |
||
| 3170 | |||
| 3171 | if icalendar: |
||
| 3172 | cmd.add_element("icalendar", icalendar) |
||
| 3173 | |||
| 3174 | if timezone: |
||
| 3175 | cmd.add_element("timezone", timezone) |
||
| 3176 | |||
| 3177 | if comment: |
||
| 3178 | cmd.add_element("comment", comment) |
||
| 3179 | |||
| 3180 | return self._send_xml_command(cmd) |
||
| 3181 | |||
| 3182 | def clone_config(self, config_id: str) -> Any: |
||
| 3183 | """Clone a scan config from an existing one |
||
| 3184 | |||
| 3185 | Arguments: |
||
| 3186 | config_id: UUID of the existing scan config |
||
| 3187 | |||
| 3188 | Returns: |
||
| 3189 | The response. See :py:meth:`send_command` for details. |
||
| 3190 | """ |
||
| 3191 | if not config_id: |
||
| 3192 | raise RequiredArgument( |
||
| 3193 | function=self.clone_config.__name__, argument='config_id' |
||
| 3194 | ) |
||
| 3195 | |||
| 3196 | cmd = XmlCommand("create_config") |
||
| 3197 | cmd.add_element("copy", config_id) |
||
| 3198 | return self._send_xml_command(cmd) |
||
| 3199 | |||
| 3200 | def import_config(self, config: str) -> Any: |
||
| 3201 | """Import a scan config from XML |
||
| 3202 | |||
| 3203 | Arguments: |
||
| 3204 | config: Scan Config XML as string to import. This XML must |
||
| 3205 | contain a :code:`<get_configs_response>` root element. |
||
| 3206 | |||
| 3207 | Returns: |
||
| 3208 | The response. See :py:meth:`send_command` for details. |
||
| 3209 | """ |
||
| 3210 | if not config: |
||
| 3211 | raise RequiredArgument( |
||
| 3212 | function=self.import_config.__name__, argument='config' |
||
| 3213 | ) |
||
| 3214 | |||
| 3215 | cmd = XmlCommand("create_config") |
||
| 3216 | |||
| 3217 | try: |
||
| 3218 | cmd.append_xml_str(config) |
||
| 3219 | except etree.XMLSyntaxError as e: |
||
| 3220 | raise InvalidArgument( |
||
| 3221 | function=self.import_config.__name__, argument='config' |
||
| 3222 | ) from e |
||
| 3223 | |||
| 3224 | return self._send_xml_command(cmd) |
||
| 3225 | |||
| 3226 | def clone_credential(self, credential_id: str) -> Any: |
||
| 3227 | """Clone an existing credential |
||
| 3228 | |||
| 3229 | Arguments: |
||
| 3230 | credential_id: UUID of an existing credential to clone from |
||
| 3231 | |||
| 3232 | Returns: |
||
| 3233 | The response. See :py:meth:`send_command` for details. |
||
| 3234 | """ |
||
| 3235 | if not credential_id: |
||
| 3236 | raise RequiredArgument( |
||
| 3237 | function=self.clone_credential.__name__, |
||
| 3238 | argument='credential_id', |
||
| 3239 | ) |
||
| 3240 | |||
| 3241 | cmd = XmlCommand("create_credential") |
||
| 3242 | cmd.add_element("copy", credential_id) |
||
| 3243 | return self._send_xml_command(cmd) |
||
| 3244 | |||
| 3245 | def clone_filter(self, filter_id: str) -> Any: |
||
| 3246 | """Clone an existing filter |
||
| 3247 | |||
| 3248 | Arguments: |
||
| 3249 | filter_id: UUID of an existing filter to clone from |
||
| 3250 | |||
| 3251 | Returns: |
||
| 3252 | The response. See :py:meth:`send_command` for details. |
||
| 3253 | """ |
||
| 3254 | if not filter_id: |
||
| 3255 | raise RequiredArgument( |
||
| 3256 | function=self.clone_filter.__name__, argument='filter_id' |
||
| 3257 | ) |
||
| 3258 | |||
| 3259 | cmd = XmlCommand("create_filter") |
||
| 3260 | cmd.add_element("copy", filter_id) |
||
| 3261 | return self._send_xml_command(cmd) |
||
| 3262 | |||
| 3263 | def create_group( |
||
| 3264 | self, |
||
| 3265 | name: str, |
||
| 3266 | *, |
||
| 3267 | comment: Optional[str] = None, |
||
| 3268 | special: Optional[bool] = False, |
||
| 3269 | users: Optional[List[str]] = None, |
||
| 3270 | ) -> Any: |
||
| 3271 | """Create a new group |
||
| 3272 | |||
| 3273 | Arguments: |
||
| 3274 | name: Name of the new group |
||
| 3275 | comment: Comment for the group |
||
| 3276 | special: Create permission giving members full access to each |
||
| 3277 | other's entities |
||
| 3278 | users: List of user names to be in the group |
||
| 3279 | |||
| 3280 | Returns: |
||
| 3281 | The response. See :py:meth:`send_command` for details. |
||
| 3282 | """ |
||
| 3283 | if not name: |
||
| 3284 | raise RequiredArgument( |
||
| 3285 | function=self.create_group.__name__, argument='name' |
||
| 3286 | ) |
||
| 3287 | |||
| 3288 | cmd = XmlCommand("create_group") |
||
| 3289 | cmd.add_element("name", name) |
||
| 3290 | |||
| 3291 | if comment: |
||
| 3292 | cmd.add_element("comment", comment) |
||
| 3293 | |||
| 3294 | if special: |
||
| 3295 | _xmlspecial = cmd.add_element("specials") |
||
| 3296 | _xmlspecial.add_element("full") |
||
| 3297 | |||
| 3298 | if users: |
||
| 3299 | cmd.add_element("users", to_comma_list(users)) |
||
| 3300 | |||
| 3301 | return self._send_xml_command(cmd) |
||
| 3302 | |||
| 3303 | def clone_group(self, group_id: str) -> Any: |
||
| 3304 | """Clone an existing group |
||
| 3305 | |||
| 3306 | Arguments: |
||
| 3307 | group_id: UUID of an existing group to clone from |
||
| 3308 | |||
| 3309 | Returns: |
||
| 3310 | The response. See :py:meth:`send_command` for details. |
||
| 3311 | """ |
||
| 3312 | if not group_id: |
||
| 3313 | raise RequiredArgument( |
||
| 3314 | function=self.clone_group.__name__, argument='group_id' |
||
| 3315 | ) |
||
| 3316 | |||
| 3317 | cmd = XmlCommand("create_group") |
||
| 3318 | cmd.add_element("copy", group_id) |
||
| 3319 | return self._send_xml_command(cmd) |
||
| 3320 | |||
| 3321 | def create_host(self, name: str, *, comment: Optional[str] = None) -> Any: |
||
| 3322 | """Create a new host asset |
||
| 3323 | |||
| 3324 | Arguments: |
||
| 3325 | name: Name for the new host asset |
||
| 3326 | comment: Comment for the new host asset |
||
| 3327 | |||
| 3328 | Returns: |
||
| 3329 | The response. See :py:meth:`send_command` for details. |
||
| 3330 | """ |
||
| 3331 | if not name: |
||
| 3332 | raise RequiredArgument( |
||
| 3333 | function=self.create_host.__name__, argument='name' |
||
| 3334 | ) |
||
| 3335 | |||
| 3336 | cmd = XmlCommand("create_asset") |
||
| 3337 | asset = cmd.add_element("asset") |
||
| 3338 | asset.add_element("type", "host") # ignored for gmp7, required for gmp8 |
||
| 3339 | asset.add_element("name", name) |
||
| 3340 | |||
| 3341 | if comment: |
||
| 3342 | asset.add_element("comment", comment) |
||
| 3343 | |||
| 3344 | return self._send_xml_command(cmd) |
||
| 3345 | |||
| 3346 | View Code Duplication | def create_note( |
|
| 3347 | self, |
||
| 3348 | text: str, |
||
| 3349 | nvt_oid: str, |
||
| 3350 | *, |
||
| 3351 | days_active: Optional[int] = None, |
||
| 3352 | hosts: Optional[List[str]] = None, |
||
| 3353 | port: Optional[int] = None, |
||
| 3354 | result_id: Optional[str] = None, |
||
| 3355 | severity: Optional[Severity] = None, |
||
| 3356 | task_id: Optional[str] = None, |
||
| 3357 | threat: Optional[SeverityLevel] = None, |
||
| 3358 | ) -> Any: |
||
| 3359 | """Create a new note |
||
| 3360 | |||
| 3361 | Arguments: |
||
| 3362 | text: Text of the new note |
||
| 3363 | nvt_id: OID of the nvt to which note applies |
||
| 3364 | days_active: Days note will be active. -1 on |
||
| 3365 | always, 0 off |
||
| 3366 | hosts: A list of hosts addresses |
||
| 3367 | port: Port to which the note applies |
||
| 3368 | result_id: UUID of a result to which note applies |
||
| 3369 | severity: Severity to which note applies |
||
| 3370 | task_id: UUID of task to which note applies |
||
| 3371 | threat: Severity level to which note applies. Will be converted to |
||
| 3372 | severity. |
||
| 3373 | |||
| 3374 | Returns: |
||
| 3375 | The response. See :py:meth:`send_command` for details. |
||
| 3376 | """ |
||
| 3377 | if not text: |
||
| 3378 | raise RequiredArgument( |
||
| 3379 | function=self.create_note.__name__, argument='text' |
||
| 3380 | ) |
||
| 3381 | |||
| 3382 | if not nvt_oid: |
||
| 3383 | raise RequiredArgument( |
||
| 3384 | function=self.create_note.__name__, argument='nvt_oid' |
||
| 3385 | ) |
||
| 3386 | |||
| 3387 | cmd = XmlCommand("create_note") |
||
| 3388 | cmd.add_element("text", text) |
||
| 3389 | cmd.add_element("nvt", attrs={"oid": nvt_oid}) |
||
| 3390 | |||
| 3391 | if days_active is not None: |
||
| 3392 | cmd.add_element("active", str(days_active)) |
||
| 3393 | |||
| 3394 | if hosts: |
||
| 3395 | cmd.add_element("hosts", to_comma_list(hosts)) |
||
| 3396 | |||
| 3397 | if port: |
||
| 3398 | cmd.add_element("port", str(port)) |
||
| 3399 | |||
| 3400 | if result_id: |
||
| 3401 | cmd.add_element("result", attrs={"id": result_id}) |
||
| 3402 | |||
| 3403 | if severity: |
||
| 3404 | cmd.add_element("severity", str(severity)) |
||
| 3405 | |||
| 3406 | if task_id: |
||
| 3407 | cmd.add_element("task", attrs={"id": task_id}) |
||
| 3408 | |||
| 3409 | if threat is not None: |
||
| 3410 | if not isinstance(threat, SeverityLevel): |
||
| 3411 | raise InvalidArgumentType( |
||
| 3412 | function="create_note", |
||
| 3413 | argument="threat", |
||
| 3414 | arg_type=SeverityLevel.__name__, |
||
| 3415 | ) |
||
| 3416 | |||
| 3417 | cmd.add_element("threat", threat.value) |
||
| 3418 | |||
| 3419 | return self._send_xml_command(cmd) |
||
| 3420 | |||
| 3421 | def clone_note(self, note_id: str) -> Any: |
||
| 3422 | """Clone an existing note |
||
| 3423 | |||
| 3424 | Arguments: |
||
| 3425 | note_id: UUID of an existing note to clone from |
||
| 3426 | |||
| 3427 | Returns: |
||
| 3428 | The response. See :py:meth:`send_command` for details. |
||
| 3429 | """ |
||
| 3430 | if not note_id: |
||
| 3431 | raise RequiredArgument( |
||
| 3432 | function=self.clone_note.__name__, argument='note_id' |
||
| 3433 | ) |
||
| 3434 | |||
| 3435 | cmd = XmlCommand("create_note") |
||
| 3436 | cmd.add_element("copy", note_id) |
||
| 3437 | return self._send_xml_command(cmd) |
||
| 3438 | |||
| 3439 | View Code Duplication | def create_override( |
|
| 3440 | self, |
||
| 3441 | text: str, |
||
| 3442 | nvt_oid: str, |
||
| 3443 | *, |
||
| 3444 | days_active: Optional[int] = None, |
||
| 3445 | hosts: Optional[List[str]] = None, |
||
| 3446 | port: Optional[int] = None, |
||
| 3447 | result_id: Optional[str] = None, |
||
| 3448 | severity: Optional[Severity] = None, |
||
| 3449 | new_severity: Optional[Severity] = None, |
||
| 3450 | task_id: Optional[str] = None, |
||
| 3451 | threat: Optional[SeverityLevel] = None, |
||
| 3452 | new_threat: Optional[SeverityLevel] = None, |
||
| 3453 | ) -> Any: |
||
| 3454 | """Create a new override |
||
| 3455 | |||
| 3456 | Arguments: |
||
| 3457 | text: Text of the new override |
||
| 3458 | nvt_id: OID of the nvt to which override applies |
||
| 3459 | days_active: Days override will be active. -1 on always, 0 off |
||
| 3460 | hosts: A list of host addresses |
||
| 3461 | port: Port to which the override applies |
||
| 3462 | result_id: UUID of a result to which override applies |
||
| 3463 | severity: Severity to which override applies |
||
| 3464 | new_severity: New severity for result |
||
| 3465 | task_id: UUID of task to which override applies |
||
| 3466 | threat: Severity level to which override applies. Will be converted |
||
| 3467 | to severity. |
||
| 3468 | new_threat: New severity level for results. Will be converted to |
||
| 3469 | new_severity. |
||
| 3470 | |||
| 3471 | Returns: |
||
| 3472 | The response. See :py:meth:`send_command` for details. |
||
| 3473 | """ |
||
| 3474 | if not text: |
||
| 3475 | raise RequiredArgument( |
||
| 3476 | function=self.create_override.__name__, argument='text' |
||
| 3477 | ) |
||
| 3478 | |||
| 3479 | if not nvt_oid: |
||
| 3480 | raise RequiredArgument( |
||
| 3481 | function=self.create_override.__name__, argument='nvt_oid' |
||
| 3482 | ) |
||
| 3483 | |||
| 3484 | cmd = XmlCommand("create_override") |
||
| 3485 | cmd.add_element("text", text) |
||
| 3486 | cmd.add_element("nvt", attrs={"oid": nvt_oid}) |
||
| 3487 | |||
| 3488 | if days_active is not None: |
||
| 3489 | cmd.add_element("active", str(days_active)) |
||
| 3490 | |||
| 3491 | if hosts: |
||
| 3492 | cmd.add_element("hosts", to_comma_list(hosts)) |
||
| 3493 | |||
| 3494 | if port: |
||
| 3495 | cmd.add_element("port", str(port)) |
||
| 3496 | |||
| 3497 | if result_id: |
||
| 3498 | cmd.add_element("result", attrs={"id": result_id}) |
||
| 3499 | |||
| 3500 | if severity: |
||
| 3501 | cmd.add_element("severity", str(severity)) |
||
| 3502 | |||
| 3503 | if new_severity: |
||
| 3504 | cmd.add_element("new_severity", str(new_severity)) |
||
| 3505 | |||
| 3506 | if task_id: |
||
| 3507 | cmd.add_element("task", attrs={"id": task_id}) |
||
| 3508 | |||
| 3509 | if threat is not None: |
||
| 3510 | if not isinstance(threat, SeverityLevel): |
||
| 3511 | raise InvalidArgumentType( |
||
| 3512 | function=self.create_override.__name__, |
||
| 3513 | argument="threat", |
||
| 3514 | arg_type=SeverityLevel.__name__, |
||
| 3515 | ) |
||
| 3516 | |||
| 3517 | cmd.add_element("threat", threat.value) |
||
| 3518 | |||
| 3519 | if new_threat is not None: |
||
| 3520 | if not isinstance(new_threat, SeverityLevel): |
||
| 3521 | raise InvalidArgumentType( |
||
| 3522 | function=self.create_override.__name__, |
||
| 3523 | argument="new_threat", |
||
| 3524 | arg_type=SeverityLevel.__name__, |
||
| 3525 | ) |
||
| 3526 | |||
| 3527 | cmd.add_element("new_threat", new_threat.value) |
||
| 3528 | |||
| 3529 | return self._send_xml_command(cmd) |
||
| 3530 | |||
| 3531 | def clone_override(self, override_id: str) -> Any: |
||
| 3532 | """Clone an existing override |
||
| 3533 | |||
| 3534 | Arguments: |
||
| 3535 | override_id: UUID of an existing override to clone from |
||
| 3536 | |||
| 3537 | Returns: |
||
| 3538 | The response. See :py:meth:`send_command` for details. |
||
| 3539 | """ |
||
| 3540 | if not override_id: |
||
| 3541 | raise RequiredArgument( |
||
| 3542 | function=self.clone_override.__name__, argument='override_id' |
||
| 3543 | ) |
||
| 3544 | |||
| 3545 | cmd = XmlCommand("create_override") |
||
| 3546 | cmd.add_element("copy", override_id) |
||
| 3547 | return self._send_xml_command(cmd) |
||
| 3548 | |||
| 3549 | def clone_permission(self, permission_id: str) -> Any: |
||
| 3550 | """Clone an existing permission |
||
| 3551 | |||
| 3552 | Arguments: |
||
| 3553 | permission_id: UUID of an existing permission to clone from |
||
| 3554 | |||
| 3555 | Returns: |
||
| 3556 | The response. See :py:meth:`send_command` for details. |
||
| 3557 | """ |
||
| 3558 | if not permission_id: |
||
| 3559 | raise RequiredArgument( |
||
| 3560 | function=self.clone_permission.__name__, |
||
| 3561 | argument='permission_id', |
||
| 3562 | ) |
||
| 3563 | |||
| 3564 | cmd = XmlCommand("create_permission") |
||
| 3565 | cmd.add_element("copy", permission_id) |
||
| 3566 | return self._send_xml_command(cmd) |
||
| 3567 | |||
| 3568 | def create_port_list( |
||
| 3569 | self, name: str, port_range: str, *, comment: Optional[str] = None |
||
| 3570 | ) -> Any: |
||
| 3571 | """Create a new port list |
||
| 3572 | |||
| 3573 | Arguments: |
||
| 3574 | name: Name of the new port list |
||
| 3575 | port_range: Port list ranges e.g. `"T: 1-1234"` for tcp port |
||
| 3576 | 1 - 1234 |
||
| 3577 | comment: Comment for the port list |
||
| 3578 | |||
| 3579 | Returns: |
||
| 3580 | The response. See :py:meth:`send_command` for details. |
||
| 3581 | """ |
||
| 3582 | if not name: |
||
| 3583 | raise RequiredArgument( |
||
| 3584 | function=self.create_port_list.__name__, argument='name' |
||
| 3585 | ) |
||
| 3586 | |||
| 3587 | if not port_range: |
||
| 3588 | raise RequiredArgument( |
||
| 3589 | function=self.create_port_list.__name__, argument='port_range' |
||
| 3590 | ) |
||
| 3591 | |||
| 3592 | cmd = XmlCommand("create_port_list") |
||
| 3593 | cmd.add_element("name", name) |
||
| 3594 | cmd.add_element("port_range", port_range) |
||
| 3595 | |||
| 3596 | if comment: |
||
| 3597 | cmd.add_element("comment", comment) |
||
| 3598 | |||
| 3599 | return self._send_xml_command(cmd) |
||
| 3600 | |||
| 3601 | def clone_port_list(self, port_list_id: str) -> Any: |
||
| 3602 | """Clone an existing port list |
||
| 3603 | |||
| 3604 | Arguments: |
||
| 3605 | port_list_id: UUID of an existing port list to clone from |
||
| 3606 | |||
| 3607 | Returns: |
||
| 3608 | The response. See :py:meth:`send_command` for details. |
||
| 3609 | """ |
||
| 3610 | if not port_list_id: |
||
| 3611 | raise RequiredArgument( |
||
| 3612 | function=self.clone_port_list.__name__, argument='port_list_id' |
||
| 3613 | ) |
||
| 3614 | |||
| 3615 | cmd = XmlCommand("create_port_list") |
||
| 3616 | cmd.add_element("copy", port_list_id) |
||
| 3617 | return self._send_xml_command(cmd) |
||
| 3618 | |||
| 3619 | def create_port_range( |
||
| 3620 | self, |
||
| 3621 | port_list_id: str, |
||
| 3622 | start: int, |
||
| 3623 | end: int, |
||
| 3624 | port_range_type: PortRangeType, |
||
| 3625 | *, |
||
| 3626 | comment: Optional[str] = None, |
||
| 3627 | ) -> Any: |
||
| 3628 | """Create new port range |
||
| 3629 | |||
| 3630 | Arguments: |
||
| 3631 | port_list_id: UUID of the port list to which to add the range |
||
| 3632 | start: The first port in the range |
||
| 3633 | end: The last port in the range |
||
| 3634 | port_range_type: The type of the ports: TCP, UDP, ... |
||
| 3635 | comment: Comment for the port range |
||
| 3636 | |||
| 3637 | Returns: |
||
| 3638 | The response. See :py:meth:`send_command` for details. |
||
| 3639 | """ |
||
| 3640 | if not port_list_id: |
||
| 3641 | raise RequiredArgument( |
||
| 3642 | function=self.create_port_range.__name__, |
||
| 3643 | argument='port_list_id', |
||
| 3644 | ) |
||
| 3645 | |||
| 3646 | if not port_range_type: |
||
| 3647 | raise RequiredArgument( |
||
| 3648 | function=self.create_port_range.__name__, |
||
| 3649 | argument='port_range_type', |
||
| 3650 | ) |
||
| 3651 | |||
| 3652 | if not start: |
||
| 3653 | raise RequiredArgument( |
||
| 3654 | function=self.create_port_range.__name__, argument='start' |
||
| 3655 | ) |
||
| 3656 | |||
| 3657 | if not end: |
||
| 3658 | raise RequiredArgument( |
||
| 3659 | function=self.create_port_range.__name__, argument='end' |
||
| 3660 | ) |
||
| 3661 | |||
| 3662 | if not isinstance(port_range_type, PortRangeType): |
||
| 3663 | raise InvalidArgumentType( |
||
| 3664 | function=self.create_port_range.__name__, |
||
| 3665 | argument='port_range_type', |
||
| 3666 | arg_type=PortRangeType.__name__, |
||
| 3667 | ) |
||
| 3668 | |||
| 3669 | cmd = XmlCommand("create_port_range") |
||
| 3670 | cmd.add_element("port_list", attrs={"id": port_list_id}) |
||
| 3671 | cmd.add_element("start", str(start)) |
||
| 3672 | cmd.add_element("end", str(end)) |
||
| 3673 | cmd.add_element("type", port_range_type.value) |
||
| 3674 | |||
| 3675 | if comment: |
||
| 3676 | cmd.add_element("comment", comment) |
||
| 3677 | |||
| 3678 | return self._send_xml_command(cmd) |
||
| 3679 | |||
| 3680 | def clone_report_format( |
||
| 3681 | self, report_format_id: [Union[str, ReportFormatType]] |
||
| 3682 | ) -> Any: |
||
| 3683 | """Clone a report format from an existing one |
||
| 3684 | |||
| 3685 | Arguments: |
||
| 3686 | report_format_id: UUID of the existing report format |
||
| 3687 | or ReportFormatType (enum) |
||
| 3688 | |||
| 3689 | Returns: |
||
| 3690 | The response. See :py:meth:`send_command` for details. |
||
| 3691 | """ |
||
| 3692 | if not report_format_id: |
||
| 3693 | raise RequiredArgument( |
||
| 3694 | function=self.clone_report_format.__name__, |
||
| 3695 | argument='report_format_id', |
||
| 3696 | ) |
||
| 3697 | |||
| 3698 | cmd = XmlCommand("create_report_format") |
||
| 3699 | |||
| 3700 | if isinstance(report_format_id, ReportFormatType): |
||
| 3701 | report_format_id = report_format_id.value |
||
| 3702 | |||
| 3703 | cmd.add_element("copy", report_format_id) |
||
| 3704 | return self._send_xml_command(cmd) |
||
| 3705 | |||
| 3706 | def import_report_format(self, report_format: str) -> Any: |
||
| 3707 | """Import a report format from XML |
||
| 3708 | |||
| 3709 | Arguments: |
||
| 3710 | report_format: Report format XML as string to import. This XML must |
||
| 3711 | contain a :code:`<get_report_formats_response>` root element. |
||
| 3712 | |||
| 3713 | Returns: |
||
| 3714 | The response. See :py:meth:`send_command` for details. |
||
| 3715 | """ |
||
| 3716 | if not report_format: |
||
| 3717 | raise RequiredArgument( |
||
| 3718 | function=self.import_report_format.__name__, |
||
| 3719 | argument='report_format', |
||
| 3720 | ) |
||
| 3721 | |||
| 3722 | cmd = XmlCommand("create_report_format") |
||
| 3723 | |||
| 3724 | try: |
||
| 3725 | cmd.append_xml_str(report_format) |
||
| 3726 | except etree.XMLSyntaxError as e: |
||
| 3727 | raise InvalidArgument( |
||
| 3728 | function=self.import_report_format.__name__, |
||
| 3729 | argument='report_format', |
||
| 3730 | ) from e |
||
| 3731 | |||
| 3732 | return self._send_xml_command(cmd) |
||
| 3733 | |||
| 3734 | def create_role( |
||
| 3735 | self, |
||
| 3736 | name: str, |
||
| 3737 | *, |
||
| 3738 | comment: Optional[str] = None, |
||
| 3739 | users: Optional[List[str]] = None, |
||
| 3740 | ) -> Any: |
||
| 3741 | """Create a new role |
||
| 3742 | |||
| 3743 | Arguments: |
||
| 3744 | name: Name of the role |
||
| 3745 | comment: Comment for the role |
||
| 3746 | users: List of user names to add to the role |
||
| 3747 | |||
| 3748 | Returns: |
||
| 3749 | The response. See :py:meth:`send_command` for details. |
||
| 3750 | """ |
||
| 3751 | |||
| 3752 | if not name: |
||
| 3753 | raise RequiredArgument( |
||
| 3754 | function=self.create_role.__name__, argument='name' |
||
| 3755 | ) |
||
| 3756 | |||
| 3757 | cmd = XmlCommand("create_role") |
||
| 3758 | cmd.add_element("name", name) |
||
| 3759 | |||
| 3760 | if comment: |
||
| 3761 | cmd.add_element("comment", comment) |
||
| 3762 | |||
| 3763 | if users: |
||
| 3764 | cmd.add_element("users", to_comma_list(users)) |
||
| 3765 | |||
| 3766 | return self._send_xml_command(cmd) |
||
| 3767 | |||
| 3768 | def clone_role(self, role_id: str) -> Any: |
||
| 3769 | """Clone an existing role |
||
| 3770 | |||
| 3771 | Arguments: |
||
| 3772 | role_id: UUID of an existing role to clone from |
||
| 3773 | |||
| 3774 | Returns: |
||
| 3775 | The response. See :py:meth:`send_command` for details. |
||
| 3776 | """ |
||
| 3777 | if not role_id: |
||
| 3778 | raise RequiredArgument( |
||
| 3779 | function=self.clone_role.__name__, argument='role_id' |
||
| 3780 | ) |
||
| 3781 | |||
| 3782 | cmd = XmlCommand("create_role") |
||
| 3783 | cmd.add_element("copy", role_id) |
||
| 3784 | return self._send_xml_command(cmd) |
||
| 3785 | |||
| 3786 | def create_scanner( |
||
| 3787 | self, |
||
| 3788 | name: str, |
||
| 3789 | host: str, |
||
| 3790 | port: int, |
||
| 3791 | scanner_type: ScannerType, |
||
| 3792 | credential_id: str, |
||
| 3793 | *, |
||
| 3794 | ca_pub: Optional[str] = None, |
||
| 3795 | comment: Optional[str] = None, |
||
| 3796 | ) -> Any: |
||
| 3797 | """Create a new scanner |
||
| 3798 | |||
| 3799 | Arguments: |
||
| 3800 | name: Name of the scanner |
||
| 3801 | host: The host of the scanner |
||
| 3802 | port: The port of the scanner |
||
| 3803 | scanner_type: Type of the scanner. |
||
| 3804 | credential_id: UUID of client certificate credential for the |
||
| 3805 | scanner |
||
| 3806 | ca_pub: Certificate of CA to verify scanner certificate |
||
| 3807 | comment: Comment for the scanner |
||
| 3808 | |||
| 3809 | Returns: |
||
| 3810 | The response. See :py:meth:`send_command` for details. |
||
| 3811 | """ |
||
| 3812 | if not name: |
||
| 3813 | raise RequiredArgument( |
||
| 3814 | function=self.create_scanner.__name__, argument='name' |
||
| 3815 | ) |
||
| 3816 | |||
| 3817 | if not host: |
||
| 3818 | raise RequiredArgument( |
||
| 3819 | function=self.create_scanner.__name__, argument='host' |
||
| 3820 | ) |
||
| 3821 | |||
| 3822 | if not port: |
||
| 3823 | raise RequiredArgument( |
||
| 3824 | function=self.create_scanner.__name__, argument='port' |
||
| 3825 | ) |
||
| 3826 | |||
| 3827 | if not scanner_type: |
||
| 3828 | raise RequiredArgument( |
||
| 3829 | function=self.create_scanner.__name__, argument='scanner_type' |
||
| 3830 | ) |
||
| 3831 | |||
| 3832 | if not credential_id: |
||
| 3833 | raise RequiredArgument( |
||
| 3834 | function=self.create_scanner.__name__, argument='credential_id' |
||
| 3835 | ) |
||
| 3836 | |||
| 3837 | if not isinstance(scanner_type, self.types.ScannerType): |
||
| 3838 | raise InvalidArgumentType( |
||
| 3839 | function=self.create_scanner.__name__, |
||
| 3840 | argument='scanner_type', |
||
| 3841 | arg_type=self.types.ScannerType.__name__, |
||
| 3842 | ) |
||
| 3843 | |||
| 3844 | cmd = XmlCommand("create_scanner") |
||
| 3845 | cmd.add_element("name", name) |
||
| 3846 | cmd.add_element("host", host) |
||
| 3847 | cmd.add_element("port", str(port)) |
||
| 3848 | cmd.add_element("type", scanner_type.value) |
||
| 3849 | |||
| 3850 | if ca_pub: |
||
| 3851 | cmd.add_element("ca_pub", ca_pub) |
||
| 3852 | |||
| 3853 | cmd.add_element("credential", attrs={"id": str(credential_id)}) |
||
| 3854 | |||
| 3855 | if comment: |
||
| 3856 | cmd.add_element("comment", comment) |
||
| 3857 | |||
| 3858 | return self._send_xml_command(cmd) |
||
| 3859 | |||
| 3860 | def clone_scanner(self, scanner_id: str) -> Any: |
||
| 3861 | """Clone an existing scanner |
||
| 3862 | |||
| 3863 | Arguments: |
||
| 3864 | scanner_id: UUID of an existing scanner to clone from |
||
| 3865 | |||
| 3866 | Returns: |
||
| 3867 | The response. See :py:meth:`send_command` for details. |
||
| 3868 | """ |
||
| 3869 | if not scanner_id: |
||
| 3870 | raise RequiredArgument( |
||
| 3871 | function=self.clone_scanner.__name__, argument='scanner_id' |
||
| 3872 | ) |
||
| 3873 | |||
| 3874 | cmd = XmlCommand("create_scanner") |
||
| 3875 | cmd.add_element("copy", scanner_id) |
||
| 3876 | return self._send_xml_command(cmd) |
||
| 3877 | |||
| 3878 | def clone_schedule(self, schedule_id: str) -> Any: |
||
| 3879 | """Clone an existing schedule |
||
| 3880 | |||
| 3881 | Arguments: |
||
| 3882 | schedule_id: UUID of an existing schedule to clone from |
||
| 3883 | |||
| 3884 | Returns: |
||
| 3885 | The response. See :py:meth:`send_command` for details. |
||
| 3886 | """ |
||
| 3887 | if not schedule_id: |
||
| 3888 | raise RequiredArgument( |
||
| 3889 | function=self.clone_schedule.__name__, argument='schedule_id' |
||
| 3890 | ) |
||
| 3891 | |||
| 3892 | cmd = XmlCommand("create_schedule") |
||
| 3893 | cmd.add_element("copy", schedule_id) |
||
| 3894 | return self._send_xml_command(cmd) |
||
| 3895 | |||
| 3896 | def clone_tag(self, tag_id: str) -> Any: |
||
| 3897 | """Clone an existing tag |
||
| 3898 | |||
| 3899 | Arguments: |
||
| 3900 | tag_id: UUID of an existing tag to clone from |
||
| 3901 | |||
| 3902 | Returns: |
||
| 3903 | The response. See :py:meth:`send_command` for details. |
||
| 3904 | """ |
||
| 3905 | if not tag_id: |
||
| 3906 | raise RequiredArgument( |
||
| 3907 | function=self.clone_tag.__name__, argument='tag_id' |
||
| 3908 | ) |
||
| 3909 | |||
| 3910 | cmd = XmlCommand("create_tag") |
||
| 3911 | cmd.add_element("copy", tag_id) |
||
| 3912 | return self._send_xml_command(cmd) |
||
| 3913 | |||
| 3914 | def clone_target(self, target_id: str) -> Any: |
||
| 3915 | """Clone an existing target |
||
| 3916 | |||
| 3917 | Arguments: |
||
| 3918 | target_id: UUID of an existing target to clone from |
||
| 3919 | |||
| 3920 | Returns: |
||
| 3921 | The response. See :py:meth:`send_command` for details. |
||
| 3922 | """ |
||
| 3923 | if not target_id: |
||
| 3924 | raise RequiredArgument( |
||
| 3925 | function=self.clone_target.__name__, argument='target_id' |
||
| 3926 | ) |
||
| 3927 | |||
| 3928 | cmd = XmlCommand("create_target") |
||
| 3929 | cmd.add_element("copy", target_id) |
||
| 3930 | return self._send_xml_command(cmd) |
||
| 3931 | |||
| 3932 | def create_container_task( |
||
| 3933 | self, name: str, *, comment: Optional[str] = None |
||
| 3934 | ) -> Any: |
||
| 3935 | """Create a new container task |
||
| 3936 | |||
| 3937 | A container task is a "meta" task to import and view reports from other |
||
| 3938 | systems. |
||
| 3939 | |||
| 3940 | Arguments: |
||
| 3941 | name: Name of the task |
||
| 3942 | comment: Comment for the task |
||
| 3943 | |||
| 3944 | Returns: |
||
| 3945 | The response. See :py:meth:`send_command` for details. |
||
| 3946 | """ |
||
| 3947 | if not name: |
||
| 3948 | raise RequiredArgument( |
||
| 3949 | function=self.create_container_task.__name__, argument='name' |
||
| 3950 | ) |
||
| 3951 | |||
| 3952 | cmd = XmlCommand("create_task") |
||
| 3953 | cmd.add_element("name", name) |
||
| 3954 | cmd.add_element("target", attrs={"id": "0"}) |
||
| 3955 | |||
| 3956 | if comment: |
||
| 3957 | cmd.add_element("comment", comment) |
||
| 3958 | |||
| 3959 | return self._send_xml_command(cmd) |
||
| 3960 | |||
| 3961 | def clone_task(self, task_id: str) -> Any: |
||
| 3962 | """Clone an existing task |
||
| 3963 | |||
| 3964 | Arguments: |
||
| 3965 | task_id: UUID of existing task to clone from |
||
| 3966 | |||
| 3967 | Returns: |
||
| 3968 | The response. See :py:meth:`send_command` for details. |
||
| 3969 | """ |
||
| 3970 | if not task_id: |
||
| 3971 | raise RequiredArgument( |
||
| 3972 | function=self.clone_task.__name__, argument='task_id' |
||
| 3973 | ) |
||
| 3974 | |||
| 3975 | cmd = XmlCommand("create_task") |
||
| 3976 | cmd.add_element("copy", task_id) |
||
| 3977 | return self._send_xml_command(cmd) |
||
| 3978 | |||
| 3979 | def create_user( |
||
| 3980 | self, |
||
| 3981 | name: str, |
||
| 3982 | *, |
||
| 3983 | password: Optional[str] = None, |
||
| 3984 | hosts: Optional[List[str]] = None, |
||
| 3985 | hosts_allow: Optional[bool] = False, |
||
| 3986 | ifaces: Optional[List[str]] = None, |
||
| 3987 | ifaces_allow: Optional[bool] = False, |
||
| 3988 | role_ids: Optional[List[str]] = None, |
||
| 3989 | ) -> Any: |
||
| 3990 | """Create a new user |
||
| 3991 | |||
| 3992 | Arguments: |
||
| 3993 | name: Name of the user |
||
| 3994 | password: Password of the user |
||
| 3995 | hosts: A list of host addresses (IPs, DNS names) |
||
| 3996 | hosts_allow: If True allow only access to passed hosts otherwise |
||
| 3997 | deny access. Default is False for deny hosts. |
||
| 3998 | ifaces: A list of interface names |
||
| 3999 | ifaces_allow: If True allow only access to passed interfaces |
||
| 4000 | otherwise deny access. Default is False for deny interfaces. |
||
| 4001 | role_ids: A list of role UUIDs for the user |
||
| 4002 | |||
| 4003 | Returns: |
||
| 4004 | The response. See :py:meth:`send_command` for details. |
||
| 4005 | """ |
||
| 4006 | if not name: |
||
| 4007 | raise RequiredArgument( |
||
| 4008 | function=self.create_user.__name__, argument='name' |
||
| 4009 | ) |
||
| 4010 | |||
| 4011 | cmd = XmlCommand("create_user") |
||
| 4012 | cmd.add_element("name", name) |
||
| 4013 | |||
| 4014 | if password: |
||
| 4015 | cmd.add_element("password", password) |
||
| 4016 | |||
| 4017 | if hosts: |
||
| 4018 | cmd.add_element( |
||
| 4019 | "hosts", |
||
| 4020 | to_comma_list(hosts), |
||
| 4021 | attrs={"allow": to_bool(hosts_allow)}, |
||
| 4022 | ) |
||
| 4023 | |||
| 4024 | if ifaces: |
||
| 4025 | cmd.add_element( |
||
| 4026 | "ifaces", |
||
| 4027 | to_comma_list(ifaces), |
||
| 4028 | attrs={"allow": to_bool(ifaces_allow)}, |
||
| 4029 | ) |
||
| 4030 | |||
| 4031 | if role_ids: |
||
| 4032 | for role in role_ids: |
||
| 4033 | cmd.add_element("role", attrs={"id": role}) |
||
| 4034 | |||
| 4035 | return self._send_xml_command(cmd) |
||
| 4036 | |||
| 4037 | def clone_user(self, user_id: str) -> Any: |
||
| 4038 | """Clone an existing user |
||
| 4039 | |||
| 4040 | Arguments: |
||
| 4041 | user_id: UUID of existing user to clone from |
||
| 4042 | |||
| 4043 | Returns: |
||
| 4044 | The response. See :py:meth:`send_command` for details. |
||
| 4045 | """ |
||
| 4046 | if not user_id: |
||
| 4047 | raise RequiredArgument( |
||
| 4048 | function=self.clone_user.__name__, argument='user_id' |
||
| 4049 | ) |
||
| 4050 | |||
| 4051 | cmd = XmlCommand("create_user") |
||
| 4052 | cmd.add_element("copy", user_id) |
||
| 4053 | return self._send_xml_command(cmd) |
||
| 4054 | |||
| 4055 | def delete_alert( |
||
| 4056 | self, alert_id: str, *, ultimate: Optional[bool] = False |
||
| 4057 | ) -> Any: |
||
| 4058 | """Deletes an existing alert |
||
| 4059 | |||
| 4060 | Arguments: |
||
| 4061 | alert_id: UUID of the alert to be deleted. |
||
| 4062 | ultimate: Whether to remove entirely, or to the trashcan. |
||
| 4063 | """ |
||
| 4064 | if not alert_id: |
||
| 4065 | raise RequiredArgument( |
||
| 4066 | function=self.delete_alert.__name__, argument='alert_id' |
||
| 4067 | ) |
||
| 4068 | |||
| 4069 | cmd = XmlCommand("delete_alert") |
||
| 4070 | cmd.set_attribute("alert_id", alert_id) |
||
| 4071 | cmd.set_attribute("ultimate", to_bool(ultimate)) |
||
| 4072 | |||
| 4073 | return self._send_xml_command(cmd) |
||
| 4074 | |||
| 4075 | def delete_asset( |
||
| 4076 | self, *, asset_id: Optional[str] = None, report_id: Optional[str] = None |
||
| 4077 | ) -> Any: |
||
| 4078 | """Deletes an existing asset |
||
| 4079 | |||
| 4080 | Arguments: |
||
| 4081 | asset_id: UUID of the single asset to delete. |
||
| 4082 | report_id: UUID of report from which to get all |
||
| 4083 | assets to delete. |
||
| 4084 | """ |
||
| 4085 | if not asset_id and not report_id: |
||
| 4086 | raise RequiredArgument( |
||
| 4087 | function=self.delete_asset.__name__, |
||
| 4088 | argument='asset_id or report_id', |
||
| 4089 | ) |
||
| 4090 | |||
| 4091 | cmd = XmlCommand("delete_asset") |
||
| 4092 | if asset_id: |
||
| 4093 | cmd.set_attribute("asset_id", asset_id) |
||
| 4094 | else: |
||
| 4095 | cmd.set_attribute("report_id", report_id) |
||
| 4096 | |||
| 4097 | return self._send_xml_command(cmd) |
||
| 4098 | |||
| 4099 | def delete_config( |
||
| 4100 | self, config_id: str, *, ultimate: Optional[bool] = False |
||
| 4101 | ) -> Any: |
||
| 4102 | """Deletes an existing config |
||
| 4103 | |||
| 4104 | Arguments: |
||
| 4105 | config_id: UUID of the config to be deleted. |
||
| 4106 | ultimate: Whether to remove entirely, or to the trashcan. |
||
| 4107 | """ |
||
| 4108 | if not config_id: |
||
| 4109 | raise RequiredArgument( |
||
| 4110 | function=self.delete_config.__name__, argument='config_id' |
||
| 4111 | ) |
||
| 4112 | |||
| 4113 | cmd = XmlCommand("delete_config") |
||
| 4114 | cmd.set_attribute("config_id", config_id) |
||
| 4115 | cmd.set_attribute("ultimate", to_bool(ultimate)) |
||
| 4116 | |||
| 4117 | return self._send_xml_command(cmd) |
||
| 4118 | |||
| 4119 | def delete_credential( |
||
| 4120 | self, credential_id: str, *, ultimate: Optional[bool] = False |
||
| 4121 | ) -> Any: |
||
| 4122 | """Deletes an existing credential |
||
| 4123 | |||
| 4124 | Arguments: |
||
| 4125 | credential_id: UUID of the credential to be deleted. |
||
| 4126 | ultimate: Whether to remove entirely, or to the trashcan. |
||
| 4127 | """ |
||
| 4128 | if not credential_id: |
||
| 4129 | raise RequiredArgument( |
||
| 4130 | function=self.delete_credential.__name__, |
||
| 4131 | argument='credential_id', |
||
| 4132 | ) |
||
| 4133 | |||
| 4134 | cmd = XmlCommand("delete_credential") |
||
| 4135 | cmd.set_attribute("credential_id", credential_id) |
||
| 4136 | cmd.set_attribute("ultimate", to_bool(ultimate)) |
||
| 4137 | |||
| 4138 | return self._send_xml_command(cmd) |
||
| 4139 | |||
| 4140 | def delete_filter( |
||
| 4141 | self, filter_id: str, *, ultimate: Optional[bool] = False |
||
| 4142 | ) -> Any: |
||
| 4143 | """Deletes an existing filter |
||
| 4144 | |||
| 4145 | Arguments: |
||
| 4146 | filter_id: UUID of the filter to be deleted. |
||
| 4147 | ultimate: Whether to remove entirely, or to the trashcan. |
||
| 4148 | """ |
||
| 4149 | if not filter_id: |
||
| 4150 | raise RequiredArgument( |
||
| 4151 | function=self.delete_filter.__name__, argument='filter_id' |
||
| 4152 | ) |
||
| 4153 | |||
| 4154 | cmd = XmlCommand("delete_filter") |
||
| 4155 | cmd.set_attribute("filter_id", filter_id) |
||
| 4156 | cmd.set_attribute("ultimate", to_bool(ultimate)) |
||
| 4157 | |||
| 4158 | return self._send_xml_command(cmd) |
||
| 4159 | |||
| 4160 | def delete_group( |
||
| 4161 | self, group_id: str, *, ultimate: Optional[bool] = False |
||
| 4162 | ) -> Any: |
||
| 4163 | """Deletes an existing group |
||
| 4164 | |||
| 4165 | Arguments: |
||
| 4166 | group_id: UUID of the group to be deleted. |
||
| 4167 | ultimate: Whether to remove entirely, or to the trashcan. |
||
| 4168 | """ |
||
| 4169 | if not group_id: |
||
| 4170 | raise RequiredArgument( |
||
| 4171 | function=self.delete_group.__name__, argument='group_id' |
||
| 4172 | ) |
||
| 4173 | |||
| 4174 | cmd = XmlCommand("delete_group") |
||
| 4175 | cmd.set_attribute("group_id", group_id) |
||
| 4176 | cmd.set_attribute("ultimate", to_bool(ultimate)) |
||
| 4177 | |||
| 4178 | return self._send_xml_command(cmd) |
||
| 4179 | |||
| 4180 | def delete_note( |
||
| 4181 | self, note_id: str, *, ultimate: Optional[bool] = False |
||
| 4182 | ) -> Any: |
||
| 4183 | """Deletes an existing note |
||
| 4184 | |||
| 4185 | Arguments: |
||
| 4186 | note_id: UUID of the note to be deleted. |
||
| 4187 | ultimate: Whether to remove entirely,or to the trashcan. |
||
| 4188 | """ |
||
| 4189 | if not note_id: |
||
| 4190 | raise RequiredArgument( |
||
| 4191 | function=self.delete_note.__name__, argument='note_id' |
||
| 4192 | ) |
||
| 4193 | |||
| 4194 | cmd = XmlCommand("delete_note") |
||
| 4195 | cmd.set_attribute("note_id", note_id) |
||
| 4196 | cmd.set_attribute("ultimate", to_bool(ultimate)) |
||
| 4197 | |||
| 4198 | return self._send_xml_command(cmd) |
||
| 4199 | |||
| 4200 | def delete_override( |
||
| 4201 | self, override_id: str, *, ultimate: Optional[bool] = False |
||
| 4202 | ) -> Any: |
||
| 4203 | """Deletes an existing override |
||
| 4204 | |||
| 4205 | Arguments: |
||
| 4206 | override_id: UUID of the override to be deleted. |
||
| 4207 | ultimate: Whether to remove entirely, or to the trashcan. |
||
| 4208 | """ |
||
| 4209 | if not override_id: |
||
| 4210 | raise RequiredArgument( |
||
| 4211 | function=self.delete_override.__name__, argument='override_id' |
||
| 4212 | ) |
||
| 4213 | |||
| 4214 | cmd = XmlCommand("delete_override") |
||
| 4215 | cmd.set_attribute("override_id", override_id) |
||
| 4216 | cmd.set_attribute("ultimate", to_bool(ultimate)) |
||
| 4217 | |||
| 4218 | return self._send_xml_command(cmd) |
||
| 4219 | |||
| 4220 | def delete_permission( |
||
| 4221 | self, permission_id: str, *, ultimate: Optional[bool] = False |
||
| 4222 | ) -> Any: |
||
| 4223 | """Deletes an existing permission |
||
| 4224 | |||
| 4225 | Arguments: |
||
| 4226 | permission_id: UUID of the permission to be deleted. |
||
| 4227 | ultimate: Whether to remove entirely, or to the trashcan. |
||
| 4228 | """ |
||
| 4229 | if not permission_id: |
||
| 4230 | raise RequiredArgument( |
||
| 4231 | function=self.delete_permission.__name__, |
||
| 4232 | argument='permission_id', |
||
| 4233 | ) |
||
| 4234 | |||
| 4235 | cmd = XmlCommand("delete_permission") |
||
| 4236 | cmd.set_attribute("permission_id", permission_id) |
||
| 4237 | cmd.set_attribute("ultimate", to_bool(ultimate)) |
||
| 4238 | |||
| 4239 | return self._send_xml_command(cmd) |
||
| 4240 | |||
| 4241 | def delete_port_list( |
||
| 4242 | self, port_list_id: str, *, ultimate: Optional[bool] = False |
||
| 4243 | ) -> Any: |
||
| 4244 | """Deletes an existing port list |
||
| 4245 | |||
| 4246 | Arguments: |
||
| 4247 | port_list_id: UUID of the port list to be deleted. |
||
| 4248 | ultimate: Whether to remove entirely, or to the trashcan. |
||
| 4249 | """ |
||
| 4250 | if not port_list_id: |
||
| 4251 | raise RequiredArgument( |
||
| 4252 | function=self.delete_port_list.__name__, argument='port_list_id' |
||
| 4253 | ) |
||
| 4254 | |||
| 4255 | cmd = XmlCommand("delete_port_list") |
||
| 4256 | cmd.set_attribute("port_list_id", port_list_id) |
||
| 4257 | cmd.set_attribute("ultimate", to_bool(ultimate)) |
||
| 4258 | |||
| 4259 | return self._send_xml_command(cmd) |
||
| 4260 | |||
| 4261 | def delete_port_range(self, port_range_id: str) -> Any: |
||
| 4262 | """Deletes an existing port range |
||
| 4263 | |||
| 4264 | Arguments: |
||
| 4265 | port_range_id: UUID of the port range to be deleted. |
||
| 4266 | """ |
||
| 4267 | if not port_range_id: |
||
| 4268 | raise RequiredArgument( |
||
| 4269 | function=self.delete_port_range.__name__, |
||
| 4270 | argument='port_range_id', |
||
| 4271 | ) |
||
| 4272 | |||
| 4273 | cmd = XmlCommand("delete_port_range") |
||
| 4274 | cmd.set_attribute("port_range_id", port_range_id) |
||
| 4275 | |||
| 4276 | return self._send_xml_command(cmd) |
||
| 4277 | |||
| 4278 | def delete_report(self, report_id: str) -> Any: |
||
| 4279 | """Deletes an existing report |
||
| 4280 | |||
| 4281 | Arguments: |
||
| 4282 | report_id: UUID of the report to be deleted. |
||
| 4283 | """ |
||
| 4284 | if not report_id: |
||
| 4285 | raise RequiredArgument( |
||
| 4286 | function=self.delete_report.__name__, argument='report_id' |
||
| 4287 | ) |
||
| 4288 | |||
| 4289 | cmd = XmlCommand("delete_report") |
||
| 4290 | cmd.set_attribute("report_id", report_id) |
||
| 4291 | |||
| 4292 | return self._send_xml_command(cmd) |
||
| 4293 | |||
| 4294 | def delete_report_format( |
||
| 4295 | self, |
||
| 4296 | report_format_id: Optional[Union[str, ReportFormatType]] = None, |
||
| 4297 | *, |
||
| 4298 | ultimate: Optional[bool] = False, |
||
| 4299 | ) -> Any: |
||
| 4300 | """Deletes an existing report format |
||
| 4301 | |||
| 4302 | Arguments: |
||
| 4303 | report_format_id: UUID of the report format to be deleted. |
||
| 4304 | or ReportFormatType (enum) |
||
| 4305 | ultimate: Whether to remove entirely, or to the trashcan. |
||
| 4306 | """ |
||
| 4307 | if not report_format_id: |
||
| 4308 | raise RequiredArgument( |
||
| 4309 | function=self.delete_report_format.__name__, |
||
| 4310 | argument='report_format_id', |
||
| 4311 | ) |
||
| 4312 | |||
| 4313 | cmd = XmlCommand("delete_report_format") |
||
| 4314 | |||
| 4315 | if isinstance(report_format_id, ReportFormatType): |
||
| 4316 | report_format_id = report_format_id.value |
||
| 4317 | |||
| 4318 | cmd.set_attribute("report_format_id", report_format_id) |
||
| 4319 | |||
| 4320 | cmd.set_attribute("ultimate", to_bool(ultimate)) |
||
| 4321 | |||
| 4322 | return self._send_xml_command(cmd) |
||
| 4323 | |||
| 4324 | def delete_role( |
||
| 4325 | self, role_id: str, *, ultimate: Optional[bool] = False |
||
| 4326 | ) -> Any: |
||
| 4327 | """Deletes an existing role |
||
| 4328 | |||
| 4329 | Arguments: |
||
| 4330 | role_id: UUID of the role to be deleted. |
||
| 4331 | ultimate: Whether to remove entirely, or to the trashcan. |
||
| 4332 | """ |
||
| 4333 | if not role_id: |
||
| 4334 | raise RequiredArgument( |
||
| 4335 | function=self.delete_role.__name__, argument='role_id' |
||
| 4336 | ) |
||
| 4337 | |||
| 4338 | cmd = XmlCommand("delete_role") |
||
| 4339 | cmd.set_attribute("role_id", role_id) |
||
| 4340 | cmd.set_attribute("ultimate", to_bool(ultimate)) |
||
| 4341 | |||
| 4342 | return self._send_xml_command(cmd) |
||
| 4343 | |||
| 4344 | def delete_scanner( |
||
| 4345 | self, scanner_id: str, *, ultimate: Optional[bool] = False |
||
| 4346 | ) -> Any: |
||
| 4347 | """Deletes an existing scanner |
||
| 4348 | |||
| 4349 | Arguments: |
||
| 4350 | scanner_id: UUID of the scanner to be deleted. |
||
| 4351 | ultimate: Whether to remove entirely, or to the trashcan. |
||
| 4352 | """ |
||
| 4353 | if not scanner_id: |
||
| 4354 | raise RequiredArgument( |
||
| 4355 | function=self.delete_scanner.__name__, argument='scanner_id' |
||
| 4356 | ) |
||
| 4357 | |||
| 4358 | cmd = XmlCommand("delete_scanner") |
||
| 4359 | cmd.set_attribute("scanner_id", scanner_id) |
||
| 4360 | cmd.set_attribute("ultimate", to_bool(ultimate)) |
||
| 4361 | |||
| 4362 | return self._send_xml_command(cmd) |
||
| 4363 | |||
| 4364 | def delete_schedule( |
||
| 4365 | self, schedule_id: str, *, ultimate: Optional[bool] = False |
||
| 4366 | ) -> Any: |
||
| 4367 | """Deletes an existing schedule |
||
| 4368 | |||
| 4369 | Arguments: |
||
| 4370 | schedule_id: UUID of the schedule to be deleted. |
||
| 4371 | ultimate: Whether to remove entirely, or to the trashcan. |
||
| 4372 | """ |
||
| 4373 | if not schedule_id: |
||
| 4374 | raise RequiredArgument( |
||
| 4375 | function=self.delete_schedule.__name__, argument='schedule_id' |
||
| 4376 | ) |
||
| 4377 | |||
| 4378 | cmd = XmlCommand("delete_schedule") |
||
| 4379 | cmd.set_attribute("schedule_id", schedule_id) |
||
| 4380 | cmd.set_attribute("ultimate", to_bool(ultimate)) |
||
| 4381 | |||
| 4382 | return self._send_xml_command(cmd) |
||
| 4383 | |||
| 4384 | def delete_tag( |
||
| 4385 | self, tag_id: str, *, ultimate: Optional[bool] = False |
||
| 4386 | ) -> Any: |
||
| 4387 | """Deletes an existing tag |
||
| 4388 | |||
| 4389 | Arguments: |
||
| 4390 | tag_id: UUID of the tag to be deleted. |
||
| 4391 | ultimate: Whether to remove entirely, or to the trashcan. |
||
| 4392 | """ |
||
| 4393 | if not tag_id: |
||
| 4394 | raise RequiredArgument( |
||
| 4395 | function=self.delete_tag.__name__, argument='tag_id' |
||
| 4396 | ) |
||
| 4397 | |||
| 4398 | cmd = XmlCommand("delete_tag") |
||
| 4399 | cmd.set_attribute("tag_id", tag_id) |
||
| 4400 | cmd.set_attribute("ultimate", to_bool(ultimate)) |
||
| 4401 | |||
| 4402 | return self._send_xml_command(cmd) |
||
| 4403 | |||
| 4404 | def delete_target( |
||
| 4405 | self, target_id: str, *, ultimate: Optional[bool] = False |
||
| 4406 | ) -> Any: |
||
| 4407 | """Deletes an existing target |
||
| 4408 | |||
| 4409 | Arguments: |
||
| 4410 | target_id: UUID of the target to be deleted. |
||
| 4411 | ultimate: Whether to remove entirely, or to the trashcan. |
||
| 4412 | """ |
||
| 4413 | if not target_id: |
||
| 4414 | raise RequiredArgument( |
||
| 4415 | function=self.delete_target.__name__, argument='target_id' |
||
| 4416 | ) |
||
| 4417 | |||
| 4418 | cmd = XmlCommand("delete_target") |
||
| 4419 | cmd.set_attribute("target_id", target_id) |
||
| 4420 | cmd.set_attribute("ultimate", to_bool(ultimate)) |
||
| 4421 | |||
| 4422 | return self._send_xml_command(cmd) |
||
| 4423 | |||
| 4424 | def delete_task( |
||
| 4425 | self, task_id: str, *, ultimate: Optional[bool] = False |
||
| 4426 | ) -> Any: |
||
| 4427 | """Deletes an existing task |
||
| 4428 | |||
| 4429 | Arguments: |
||
| 4430 | task_id: UUID of the task to be deleted. |
||
| 4431 | ultimate: Whether to remove entirely, or to the trashcan. |
||
| 4432 | """ |
||
| 4433 | if not task_id: |
||
| 4434 | raise RequiredArgument( |
||
| 4435 | function=self.delete_task.__name__, argument='task_id' |
||
| 4436 | ) |
||
| 4437 | |||
| 4438 | cmd = XmlCommand("delete_task") |
||
| 4439 | cmd.set_attribute("task_id", task_id) |
||
| 4440 | cmd.set_attribute("ultimate", to_bool(ultimate)) |
||
| 4441 | |||
| 4442 | return self._send_xml_command(cmd) |
||
| 4443 | |||
| 4444 | def delete_user( |
||
| 4445 | self, |
||
| 4446 | user_id: str = None, |
||
| 4447 | *, |
||
| 4448 | name: Optional[str] = None, |
||
| 4449 | inheritor_id: Optional[str] = None, |
||
| 4450 | inheritor_name: Optional[str] = None, |
||
| 4451 | ) -> Any: |
||
| 4452 | """Deletes an existing user |
||
| 4453 | |||
| 4454 | Either user_id or name must be passed. |
||
| 4455 | |||
| 4456 | Arguments: |
||
| 4457 | user_id: UUID of the task to be deleted. |
||
| 4458 | name: The name of the user to be deleted. |
||
| 4459 | inheritor_id: The ID of the inheriting user or "self". Overrides |
||
| 4460 | inheritor_name. |
||
| 4461 | inheritor_name: The name of the inheriting user. |
||
| 4462 | |||
| 4463 | """ |
||
| 4464 | if not user_id and not name: |
||
| 4465 | raise RequiredArgument( |
||
| 4466 | function=self.delete_user.__name__, argument='user_id or name' |
||
| 4467 | ) |
||
| 4468 | |||
| 4469 | cmd = XmlCommand("delete_user") |
||
| 4470 | |||
| 4471 | if user_id: |
||
| 4472 | cmd.set_attribute("user_id", user_id) |
||
| 4473 | |||
| 4474 | if name: |
||
| 4475 | cmd.set_attribute("name", name) |
||
| 4476 | |||
| 4477 | if inheritor_id: |
||
| 4478 | cmd.set_attribute("inheritor_id", inheritor_id) |
||
| 4479 | |||
| 4480 | if inheritor_name: |
||
| 4481 | cmd.set_attribute("inheritor_name", inheritor_name) |
||
| 4482 | |||
| 4483 | return self._send_xml_command(cmd) |
||
| 4484 | |||
| 4485 | def describe_auth(self) -> Any: |
||
| 4486 | """Describe authentication methods |
||
| 4487 | |||
| 4488 | Returns a list of all used authentication methods if such a list is |
||
| 4489 | available. |
||
| 4490 | |||
| 4491 | Returns: |
||
| 4492 | The response. See :py:meth:`send_command` for details. |
||
| 4493 | """ |
||
| 4494 | return self._send_xml_command(XmlCommand("describe_auth")) |
||
| 4495 | |||
| 4496 | def empty_trashcan(self) -> Any: |
||
| 4497 | """Empty the trashcan |
||
| 4498 | |||
| 4499 | Remove all entities from the trashcan. **Attention:** this command can |
||
| 4500 | not be reverted |
||
| 4501 | |||
| 4502 | Returns: |
||
| 4503 | The response. See :py:meth:`send_command` for details. |
||
| 4504 | """ |
||
| 4505 | return self._send_xml_command(XmlCommand("empty_trashcan")) |
||
| 4506 | |||
| 4507 | def get_alerts( |
||
| 4508 | self, |
||
| 4509 | *, |
||
| 4510 | filter: Optional[str] = None, |
||
| 4511 | filter_id: Optional[str] = None, |
||
| 4512 | trash: Optional[bool] = None, |
||
| 4513 | tasks: Optional[bool] = None, |
||
| 4514 | ) -> Any: |
||
| 4515 | """Request a list of alerts |
||
| 4516 | |||
| 4517 | Arguments: |
||
| 4518 | filter: Filter term to use for the query |
||
| 4519 | filter_id: UUID of an existing filter to use for the query |
||
| 4520 | trash: True to request the alerts in the trashcan |
||
| 4521 | tasks: Whether to include the tasks using the alerts |
||
| 4522 | Returns: |
||
| 4523 | The response. See :py:meth:`send_command` for details. |
||
| 4524 | """ |
||
| 4525 | cmd = XmlCommand("get_alerts") |
||
| 4526 | |||
| 4527 | add_filter(cmd, filter, filter_id) |
||
| 4528 | |||
| 4529 | if trash is not None: |
||
| 4530 | cmd.set_attribute("trash", to_bool(trash)) |
||
| 4531 | |||
| 4532 | if tasks is not None: |
||
| 4533 | cmd.set_attribute("tasks", to_bool(tasks)) |
||
| 4534 | |||
| 4535 | return self._send_xml_command(cmd) |
||
| 4536 | |||
| 4537 | def get_alert(self, alert_id: str, *, tasks: Optional[bool] = None) -> Any: |
||
| 4538 | """Request a single alert |
||
| 4539 | |||
| 4540 | Arguments: |
||
| 4541 | alert_id: UUID of an existing alert |
||
| 4542 | |||
| 4543 | Returns: |
||
| 4544 | The response. See :py:meth:`send_command` for details. |
||
| 4545 | """ |
||
| 4546 | cmd = XmlCommand("get_alerts") |
||
| 4547 | |||
| 4548 | if not alert_id: |
||
| 4549 | raise RequiredArgument( |
||
| 4550 | function=self.get_alert.__name__, argument='alert_id' |
||
| 4551 | ) |
||
| 4552 | |||
| 4553 | cmd.set_attribute("alert_id", alert_id) |
||
| 4554 | |||
| 4555 | if tasks is not None: |
||
| 4556 | cmd.set_attribute("tasks", to_bool(tasks)) |
||
| 4557 | |||
| 4558 | return self._send_xml_command(cmd) |
||
| 4559 | |||
| 4560 | def get_assets( |
||
| 4561 | self, |
||
| 4562 | asset_type: AssetType, |
||
| 4563 | *, |
||
| 4564 | filter: Optional[str] = None, |
||
| 4565 | filter_id: Optional[str] = None, |
||
| 4566 | ) -> Any: |
||
| 4567 | """Request a list of assets |
||
| 4568 | |||
| 4569 | Arguments: |
||
| 4570 | asset_type: Either 'os' or 'host' |
||
| 4571 | filter: Filter term to use for the query |
||
| 4572 | filter_id: UUID of an existing filter to use for the query |
||
| 4573 | |||
| 4574 | Returns: |
||
| 4575 | The response. See :py:meth:`send_command` for details. |
||
| 4576 | """ |
||
| 4577 | if not isinstance(asset_type, AssetType): |
||
| 4578 | raise InvalidArgumentType( |
||
| 4579 | function=self.get_assets.__name__, |
||
| 4580 | argument='asset_type', |
||
| 4581 | arg_type=AssetType.__name__, |
||
| 4582 | ) |
||
| 4583 | |||
| 4584 | cmd = XmlCommand("get_assets") |
||
| 4585 | |||
| 4586 | cmd.set_attribute("type", asset_type.value) |
||
| 4587 | |||
| 4588 | add_filter(cmd, filter, filter_id) |
||
| 4589 | |||
| 4590 | return self._send_xml_command(cmd) |
||
| 4591 | |||
| 4592 | def get_asset(self, asset_id: str, asset_type: AssetType) -> Any: |
||
| 4593 | """Request a single asset |
||
| 4594 | |||
| 4595 | Arguments: |
||
| 4596 | asset_id: UUID of an existing asset |
||
| 4597 | asset_type: Either 'os' or 'host' |
||
| 4598 | |||
| 4599 | Returns: |
||
| 4600 | The response. See :py:meth:`send_command` for details. |
||
| 4601 | """ |
||
| 4602 | cmd = XmlCommand("get_assets") |
||
| 4603 | |||
| 4604 | if not isinstance(asset_type, AssetType): |
||
| 4605 | raise InvalidArgumentType( |
||
| 4606 | function=self.get_asset.__name__, |
||
| 4607 | argument='asset_type', |
||
| 4608 | arg_type=AssetType.__name__, |
||
| 4609 | ) |
||
| 4610 | |||
| 4611 | if not asset_id: |
||
| 4612 | raise RequiredArgument( |
||
| 4613 | function=self.get_asset.__name__, argument='asset_id' |
||
| 4614 | ) |
||
| 4615 | |||
| 4616 | cmd.set_attribute("asset_id", asset_id) |
||
| 4617 | cmd.set_attribute("type", asset_type.value) |
||
| 4618 | |||
| 4619 | return self._send_xml_command(cmd) |
||
| 4620 | |||
| 4621 | View Code Duplication | def get_credentials( |
|
| 4622 | self, |
||
| 4623 | *, |
||
| 4624 | filter: Optional[str] = None, |
||
| 4625 | filter_id: Optional[str] = None, |
||
| 4626 | scanners: Optional[bool] = None, |
||
| 4627 | trash: Optional[bool] = None, |
||
| 4628 | targets: Optional[bool] = None, |
||
| 4629 | ) -> Any: |
||
| 4630 | """Request a list of credentials |
||
| 4631 | |||
| 4632 | Arguments: |
||
| 4633 | filter: Filter term to use for the query |
||
| 4634 | filter_id: UUID of an existing filter to use for the query |
||
| 4635 | scanners: Whether to include a list of scanners using the |
||
| 4636 | credentials |
||
| 4637 | trash: Whether to get the trashcan credentials instead |
||
| 4638 | targets: Whether to include a list of targets using the credentials |
||
| 4639 | |||
| 4640 | Returns: |
||
| 4641 | The response. See :py:meth:`send_command` for details. |
||
| 4642 | """ |
||
| 4643 | cmd = XmlCommand("get_credentials") |
||
| 4644 | |||
| 4645 | add_filter(cmd, filter, filter_id) |
||
| 4646 | |||
| 4647 | if scanners is not None: |
||
| 4648 | cmd.set_attribute("scanners", to_bool(scanners)) |
||
| 4649 | |||
| 4650 | if trash is not None: |
||
| 4651 | cmd.set_attribute("trash", to_bool(trash)) |
||
| 4652 | |||
| 4653 | if targets is not None: |
||
| 4654 | cmd.set_attribute("targets", to_bool(targets)) |
||
| 4655 | |||
| 4656 | return self._send_xml_command(cmd) |
||
| 4657 | |||
| 4658 | def get_credential( |
||
| 4659 | self, |
||
| 4660 | credential_id: str, |
||
| 4661 | *, |
||
| 4662 | scanners: Optional[bool] = None, |
||
| 4663 | targets: Optional[bool] = None, |
||
| 4664 | credential_format: Optional[CredentialFormat] = None, |
||
| 4665 | ) -> Any: |
||
| 4666 | """Request a single credential |
||
| 4667 | |||
| 4668 | Arguments: |
||
| 4669 | credential_id: UUID of an existing credential |
||
| 4670 | scanners: Whether to include a list of scanners using the |
||
| 4671 | credentials |
||
| 4672 | targets: Whether to include a list of targets using the credentials |
||
| 4673 | credential_format: One of "key", "rpm", "deb", "exe" or "pem" |
||
| 4674 | |||
| 4675 | Returns: |
||
| 4676 | The response. See :py:meth:`send_command` for details. |
||
| 4677 | """ |
||
| 4678 | if not credential_id: |
||
| 4679 | raise RequiredArgument( |
||
| 4680 | function=self.get_credential.__name__, argument='credential_id' |
||
| 4681 | ) |
||
| 4682 | |||
| 4683 | cmd = XmlCommand("get_credentials") |
||
| 4684 | cmd.set_attribute("credential_id", credential_id) |
||
| 4685 | |||
| 4686 | if credential_format: |
||
| 4687 | if not isinstance(credential_format, CredentialFormat): |
||
| 4688 | raise InvalidArgumentType( |
||
| 4689 | function=self.get_credential.__name__, |
||
| 4690 | argument='credential_format', |
||
| 4691 | arg_type=CredentialFormat.__name__, |
||
| 4692 | ) |
||
| 4693 | |||
| 4694 | cmd.set_attribute("format", credential_format.value) |
||
| 4695 | |||
| 4696 | if scanners is not None: |
||
| 4697 | cmd.set_attribute("scanners", to_bool(scanners)) |
||
| 4698 | |||
| 4699 | if targets is not None: |
||
| 4700 | cmd.set_attribute("targets", to_bool(targets)) |
||
| 4701 | |||
| 4702 | return self._send_xml_command(cmd) |
||
| 4703 | |||
| 4704 | def get_feeds(self) -> Any: |
||
| 4705 | """Request the list of feeds |
||
| 4706 | |||
| 4707 | Returns: |
||
| 4708 | The response. See :py:meth:`send_command` for details. |
||
| 4709 | """ |
||
| 4710 | return self._send_xml_command(XmlCommand("get_feeds")) |
||
| 4711 | |||
| 4712 | def get_filters( |
||
| 4713 | self, |
||
| 4714 | *, |
||
| 4715 | filter: Optional[str] = None, |
||
| 4716 | filter_id: Optional[str] = None, |
||
| 4717 | trash: Optional[bool] = None, |
||
| 4718 | alerts: Optional[bool] = None, |
||
| 4719 | ) -> Any: |
||
| 4720 | """Request a list of filters |
||
| 4721 | |||
| 4722 | Arguments: |
||
| 4723 | filter: Filter term to use for the query |
||
| 4724 | filter_id: UUID of an existing filter to use for the query |
||
| 4725 | trash: Whether to get the trashcan filters instead |
||
| 4726 | alerts: Whether to include list of alerts that use the filter. |
||
| 4727 | |||
| 4728 | Returns: |
||
| 4729 | The response. See :py:meth:`send_command` for details. |
||
| 4730 | """ |
||
| 4731 | cmd = XmlCommand("get_filters") |
||
| 4732 | |||
| 4733 | add_filter(cmd, filter, filter_id) |
||
| 4734 | |||
| 4735 | if trash is not None: |
||
| 4736 | cmd.set_attribute("trash", to_bool(trash)) |
||
| 4737 | |||
| 4738 | if alerts is not None: |
||
| 4739 | cmd.set_attribute("alerts", to_bool(alerts)) |
||
| 4740 | |||
| 4741 | return self._send_xml_command(cmd) |
||
| 4742 | |||
| 4743 | def get_filter( |
||
| 4744 | self, filter_id: str, *, alerts: Optional[bool] = None |
||
| 4745 | ) -> Any: |
||
| 4746 | """Request a single filter |
||
| 4747 | |||
| 4748 | Arguments: |
||
| 4749 | filter_id: UUID of an existing filter |
||
| 4750 | alerts: Whether to include list of alerts that use the filter. |
||
| 4751 | |||
| 4752 | Returns: |
||
| 4753 | The response. See :py:meth:`send_command` for details. |
||
| 4754 | """ |
||
| 4755 | cmd = XmlCommand("get_filters") |
||
| 4756 | |||
| 4757 | if not filter_id: |
||
| 4758 | raise RequiredArgument( |
||
| 4759 | function=self.get_filter.__name__, argument='filter_id' |
||
| 4760 | ) |
||
| 4761 | |||
| 4762 | cmd.set_attribute("filter_id", filter_id) |
||
| 4763 | |||
| 4764 | if alerts is not None: |
||
| 4765 | cmd.set_attribute("alerts", to_bool(alerts)) |
||
| 4766 | |||
| 4767 | return self._send_xml_command(cmd) |
||
| 4768 | |||
| 4769 | View Code Duplication | def get_groups( |
|
| 4770 | self, |
||
| 4771 | *, |
||
| 4772 | filter: Optional[str] = None, |
||
| 4773 | filter_id: Optional[str] = None, |
||
| 4774 | trash: Optional[bool] = None, |
||
| 4775 | ) -> Any: |
||
| 4776 | """Request a list of groups |
||
| 4777 | |||
| 4778 | Arguments: |
||
| 4779 | filter: Filter term to use for the query |
||
| 4780 | filter_id: UUID of an existing filter to use for the query |
||
| 4781 | trash: Whether to get the trashcan groups instead |
||
| 4782 | |||
| 4783 | Returns: |
||
| 4784 | The response. See :py:meth:`send_command` for details. |
||
| 4785 | """ |
||
| 4786 | cmd = XmlCommand("get_groups") |
||
| 4787 | |||
| 4788 | add_filter(cmd, filter, filter_id) |
||
| 4789 | |||
| 4790 | if trash is not None: |
||
| 4791 | cmd.set_attribute("trash", to_bool(trash)) |
||
| 4792 | |||
| 4793 | return self._send_xml_command(cmd) |
||
| 4794 | |||
| 4795 | def get_group(self, group_id: str) -> Any: |
||
| 4796 | """Request a single group |
||
| 4797 | |||
| 4798 | Arguments: |
||
| 4799 | group_id: UUID of an existing group |
||
| 4800 | |||
| 4801 | Returns: |
||
| 4802 | The response. See :py:meth:`send_command` for details. |
||
| 4803 | """ |
||
| 4804 | cmd = XmlCommand("get_groups") |
||
| 4805 | |||
| 4806 | if not group_id: |
||
| 4807 | raise RequiredArgument( |
||
| 4808 | function=self.get_group.__name__, argument='group_id' |
||
| 4809 | ) |
||
| 4810 | |||
| 4811 | cmd.set_attribute("group_id", group_id) |
||
| 4812 | return self._send_xml_command(cmd) |
||
| 4813 | |||
| 4814 | View Code Duplication | def get_notes( |
|
| 4815 | self, |
||
| 4816 | *, |
||
| 4817 | filter: Optional[str] = None, |
||
| 4818 | filter_id: Optional[str] = None, |
||
| 4819 | details: Optional[bool] = None, |
||
| 4820 | result: Optional[bool] = None, |
||
| 4821 | ) -> Any: |
||
| 4822 | """Request a list of notes |
||
| 4823 | |||
| 4824 | Arguments: |
||
| 4825 | filter: Filter term to use for the query |
||
| 4826 | filter_id: UUID of an existing filter to use for the query |
||
| 4827 | details: Add info about connected results and tasks |
||
| 4828 | result: Return the details of possible connected results. |
||
| 4829 | |||
| 4830 | Returns: |
||
| 4831 | The response. See :py:meth:`send_command` for details. |
||
| 4832 | """ |
||
| 4833 | cmd = XmlCommand("get_notes") |
||
| 4834 | |||
| 4835 | add_filter(cmd, filter, filter_id) |
||
| 4836 | |||
| 4837 | if details is not None: |
||
| 4838 | cmd.set_attribute("details", to_bool(details)) |
||
| 4839 | |||
| 4840 | if result is not None: |
||
| 4841 | cmd.set_attribute("result", to_bool(result)) |
||
| 4842 | |||
| 4843 | return self._send_xml_command(cmd) |
||
| 4844 | |||
| 4845 | def get_note(self, note_id: str) -> Any: |
||
| 4846 | """Request a single note |
||
| 4847 | |||
| 4848 | Arguments: |
||
| 4849 | note_id: UUID of an existing note |
||
| 4850 | |||
| 4851 | Returns: |
||
| 4852 | The response. See :py:meth:`send_command` for details. |
||
| 4853 | """ |
||
| 4854 | if not note_id: |
||
| 4855 | raise RequiredArgument( |
||
| 4856 | function=self.get_note.__name__, argument='note_id' |
||
| 4857 | ) |
||
| 4858 | |||
| 4859 | cmd = XmlCommand("get_notes") |
||
| 4860 | cmd.set_attribute("note_id", note_id) |
||
| 4861 | |||
| 4862 | # for single entity always request all details |
||
| 4863 | cmd.set_attribute("details", "1") |
||
| 4864 | return self._send_xml_command(cmd) |
||
| 4865 | |||
| 4866 | def get_nvts( |
||
| 4867 | self, |
||
| 4868 | *, |
||
| 4869 | details: Optional[bool] = None, |
||
| 4870 | preferences: Optional[bool] = None, |
||
| 4871 | preference_count: Optional[bool] = None, |
||
| 4872 | timeout: Optional[bool] = None, |
||
| 4873 | config_id: Optional[str] = None, |
||
| 4874 | preferences_config_id: Optional[str] = None, |
||
| 4875 | family: Optional[str] = None, |
||
| 4876 | sort_order: Optional[str] = None, |
||
| 4877 | sort_field: Optional[str] = None, |
||
| 4878 | ): |
||
| 4879 | """Request a list of nvts |
||
| 4880 | |||
| 4881 | Arguments: |
||
| 4882 | details: Whether to include full details |
||
| 4883 | preferences: Whether to include nvt preferences |
||
| 4884 | preference_count: Whether to include preference count |
||
| 4885 | timeout: Whether to include the special timeout preference |
||
| 4886 | config_id: UUID of scan config to which to limit the NVT listing |
||
| 4887 | preferences_config_id: UUID of scan config to use for preference |
||
| 4888 | values |
||
| 4889 | family: Family to which to limit NVT listing |
||
| 4890 | sort_order: Sort order |
||
| 4891 | sort_field: Sort field |
||
| 4892 | |||
| 4893 | Returns: |
||
| 4894 | The response. See :py:meth:`send_command` for details. |
||
| 4895 | """ |
||
| 4896 | cmd = XmlCommand("get_nvts") |
||
| 4897 | |||
| 4898 | if details is not None: |
||
| 4899 | cmd.set_attribute("details", to_bool(details)) |
||
| 4900 | |||
| 4901 | if preferences is not None: |
||
| 4902 | cmd.set_attribute("preferences", to_bool(preferences)) |
||
| 4903 | |||
| 4904 | if preference_count is not None: |
||
| 4905 | cmd.set_attribute("preference_count", to_bool(preference_count)) |
||
| 4906 | |||
| 4907 | if timeout is not None: |
||
| 4908 | cmd.set_attribute("timeout", to_bool(timeout)) |
||
| 4909 | |||
| 4910 | if config_id: |
||
| 4911 | cmd.set_attribute("config_id", config_id) |
||
| 4912 | |||
| 4913 | if preferences_config_id: |
||
| 4914 | cmd.set_attribute("preferences_config_id", preferences_config_id) |
||
| 4915 | |||
| 4916 | if family: |
||
| 4917 | cmd.set_attribute("family", family) |
||
| 4918 | |||
| 4919 | if sort_order: |
||
| 4920 | cmd.set_attribute("sort_order", sort_order) |
||
| 4921 | |||
| 4922 | if sort_field: |
||
| 4923 | cmd.set_attribute("sort_field", sort_field) |
||
| 4924 | |||
| 4925 | return self._send_xml_command(cmd) |
||
| 4926 | |||
| 4927 | def get_nvt(self, nvt_oid: str): |
||
| 4928 | """Request a single nvt |
||
| 4929 | |||
| 4930 | Arguments: |
||
| 4931 | nvt_oid: OID of an existing nvt |
||
| 4932 | |||
| 4933 | Returns: |
||
| 4934 | The response. See :py:meth:`send_command` for details. |
||
| 4935 | """ |
||
| 4936 | cmd = XmlCommand("get_nvts") |
||
| 4937 | |||
| 4938 | if not nvt_oid: |
||
| 4939 | raise RequiredArgument( |
||
| 4940 | function=self.get_nvt.__name__, argument='nvt_oid' |
||
| 4941 | ) |
||
| 4942 | |||
| 4943 | cmd.set_attribute("nvt_oid", nvt_oid) |
||
| 4944 | |||
| 4945 | # for single entity always request all details |
||
| 4946 | cmd.set_attribute("details", "1") |
||
| 4947 | cmd.set_attribute("preferences", "1") |
||
| 4948 | cmd.set_attribute("preference_count", "1") |
||
| 4949 | return self._send_xml_command(cmd) |
||
| 4950 | |||
| 4951 | def get_nvt_families(self, *, sort_order: Optional[str] = None): |
||
| 4952 | """Request a list of nvt families |
||
| 4953 | |||
| 4954 | Arguments: |
||
| 4955 | sort_order: Sort order |
||
| 4956 | |||
| 4957 | Returns: |
||
| 4958 | The response. See :py:meth:`send_command` for details. |
||
| 4959 | """ |
||
| 4960 | cmd = XmlCommand("get_nvt_families") |
||
| 4961 | |||
| 4962 | if sort_order: |
||
| 4963 | cmd.set_attribute("sort_order", sort_order) |
||
| 4964 | |||
| 4965 | return self._send_xml_command(cmd) |
||
| 4966 | |||
| 4967 | View Code Duplication | def get_overrides( |
|
| 4968 | self, |
||
| 4969 | *, |
||
| 4970 | filter: Optional[str] = None, |
||
| 4971 | filter_id: Optional[str] = None, |
||
| 4972 | details: Optional[bool] = None, |
||
| 4973 | result: Optional[bool] = None, |
||
| 4974 | ) -> Any: |
||
| 4975 | """Request a list of overrides |
||
| 4976 | |||
| 4977 | Arguments: |
||
| 4978 | filter: Filter term to use for the query |
||
| 4979 | filter_id: UUID of an existing filter to use for the query |
||
| 4980 | details: Whether to include full details |
||
| 4981 | result: Whether to include results using the override |
||
| 4982 | |||
| 4983 | Returns: |
||
| 4984 | The response. See :py:meth:`send_command` for details. |
||
| 4985 | """ |
||
| 4986 | cmd = XmlCommand("get_overrides") |
||
| 4987 | |||
| 4988 | add_filter(cmd, filter, filter_id) |
||
| 4989 | |||
| 4990 | if details is not None: |
||
| 4991 | cmd.set_attribute("details", to_bool(details)) |
||
| 4992 | |||
| 4993 | if result is not None: |
||
| 4994 | cmd.set_attribute("result", to_bool(result)) |
||
| 4995 | |||
| 4996 | return self._send_xml_command(cmd) |
||
| 4997 | |||
| 4998 | def get_override(self, override_id: str) -> Any: |
||
| 4999 | """Request a single override |
||
| 5000 | |||
| 5001 | Arguments: |
||
| 5002 | override_id: UUID of an existing override |
||
| 5003 | |||
| 5004 | Returns: |
||
| 5005 | The response. See :py:meth:`send_command` for details. |
||
| 5006 | """ |
||
| 5007 | cmd = XmlCommand("get_overrides") |
||
| 5008 | |||
| 5009 | if not override_id: |
||
| 5010 | raise RequiredArgument( |
||
| 5011 | function=self.get_override.__name__, argument='override_id' |
||
| 5012 | ) |
||
| 5013 | |||
| 5014 | cmd.set_attribute("override_id", override_id) |
||
| 5015 | |||
| 5016 | # for single entity always request all details |
||
| 5017 | cmd.set_attribute("details", "1") |
||
| 5018 | return self._send_xml_command(cmd) |
||
| 5019 | |||
| 5020 | View Code Duplication | def get_permissions( |
|
| 5021 | self, |
||
| 5022 | *, |
||
| 5023 | filter: Optional[str] = None, |
||
| 5024 | filter_id: Optional[str] = None, |
||
| 5025 | trash: Optional[bool] = None, |
||
| 5026 | ) -> Any: |
||
| 5027 | """Request a list of permissions |
||
| 5028 | |||
| 5029 | Arguments: |
||
| 5030 | filter: Filter term to use for the query |
||
| 5031 | filter_id: UUID of an existing filter to use for the query |
||
| 5032 | trash: Whether to get permissions in the trashcan instead |
||
| 5033 | |||
| 5034 | Returns: |
||
| 5035 | The response. See :py:meth:`send_command` for details. |
||
| 5036 | """ |
||
| 5037 | cmd = XmlCommand("get_permissions") |
||
| 5038 | |||
| 5039 | add_filter(cmd, filter, filter_id) |
||
| 5040 | |||
| 5041 | if trash is not None: |
||
| 5042 | cmd.set_attribute("trash", to_bool(trash)) |
||
| 5043 | |||
| 5044 | return self._send_xml_command(cmd) |
||
| 5045 | |||
| 5046 | def get_permission(self, permission_id: str) -> Any: |
||
| 5047 | """Request a single permission |
||
| 5048 | |||
| 5049 | Arguments: |
||
| 5050 | permission_id: UUID of an existing permission |
||
| 5051 | |||
| 5052 | Returns: |
||
| 5053 | The response. See :py:meth:`send_command` for details. |
||
| 5054 | """ |
||
| 5055 | cmd = XmlCommand("get_permissions") |
||
| 5056 | |||
| 5057 | if not permission_id: |
||
| 5058 | raise RequiredArgument( |
||
| 5059 | function=self.get_permission.__name__, argument='permission_id' |
||
| 5060 | ) |
||
| 5061 | |||
| 5062 | cmd.set_attribute("permission_id", permission_id) |
||
| 5063 | return self._send_xml_command(cmd) |
||
| 5064 | |||
| 5065 | View Code Duplication | def get_port_lists( |
|
| 5066 | self, |
||
| 5067 | *, |
||
| 5068 | filter: Optional[str] = None, |
||
| 5069 | filter_id: Optional[str] = None, |
||
| 5070 | details: Optional[bool] = None, |
||
| 5071 | targets: Optional[bool] = None, |
||
| 5072 | trash: Optional[bool] = None, |
||
| 5073 | ) -> Any: |
||
| 5074 | """Request a list of port lists |
||
| 5075 | |||
| 5076 | Arguments: |
||
| 5077 | filter: Filter term to use for the query |
||
| 5078 | filter_id: UUID of an existing filter to use for the query |
||
| 5079 | details: Whether to include full port list details |
||
| 5080 | targets: Whether to include targets using this port list |
||
| 5081 | trash: Whether to get port lists in the trashcan instead |
||
| 5082 | |||
| 5083 | Returns: |
||
| 5084 | The response. See :py:meth:`send_command` for details. |
||
| 5085 | """ |
||
| 5086 | cmd = XmlCommand("get_port_lists") |
||
| 5087 | |||
| 5088 | add_filter(cmd, filter, filter_id) |
||
| 5089 | |||
| 5090 | if details is not None: |
||
| 5091 | cmd.set_attribute("details", to_bool(details)) |
||
| 5092 | |||
| 5093 | if targets is not None: |
||
| 5094 | cmd.set_attribute("targets", to_bool(targets)) |
||
| 5095 | |||
| 5096 | if trash is not None: |
||
| 5097 | cmd.set_attribute("trash", to_bool(trash)) |
||
| 5098 | |||
| 5099 | return self._send_xml_command(cmd) |
||
| 5100 | |||
| 5101 | def get_port_list(self, port_list_id: str): |
||
| 5102 | """Request a single port list |
||
| 5103 | |||
| 5104 | Arguments: |
||
| 5105 | port_list_id: UUID of an existing port list |
||
| 5106 | |||
| 5107 | Returns: |
||
| 5108 | The response. See :py:meth:`send_command` for details. |
||
| 5109 | """ |
||
| 5110 | cmd = XmlCommand("get_port_lists") |
||
| 5111 | |||
| 5112 | if not port_list_id: |
||
| 5113 | raise RequiredArgument( |
||
| 5114 | function=self.get_port_list.__name__, argument='port_list_id' |
||
| 5115 | ) |
||
| 5116 | |||
| 5117 | cmd.set_attribute("port_list_id", port_list_id) |
||
| 5118 | |||
| 5119 | # for single entity always request all details |
||
| 5120 | cmd.set_attribute("details", "1") |
||
| 5121 | return self._send_xml_command(cmd) |
||
| 5122 | |||
| 5123 | def get_preferences( |
||
| 5124 | self, *, nvt_oid: Optional[str] = None, config_id: Optional[str] = None |
||
| 5125 | ) -> Any: |
||
| 5126 | """Request a list of preferences |
||
| 5127 | |||
| 5128 | When the command includes a config_id attribute, the preference element |
||
| 5129 | includes the preference name, type and value, and the NVT to which the |
||
| 5130 | preference applies. Otherwise, the preference element includes just the |
||
| 5131 | name and value, with the NVT and type built into the name. |
||
| 5132 | |||
| 5133 | Arguments: |
||
| 5134 | nvt_oid: OID of nvt |
||
| 5135 | config_id: UUID of scan config of which to show preference values |
||
| 5136 | |||
| 5137 | Returns: |
||
| 5138 | The response. See :py:meth:`send_command` for details. |
||
| 5139 | """ |
||
| 5140 | cmd = XmlCommand("get_preferences") |
||
| 5141 | |||
| 5142 | if nvt_oid: |
||
| 5143 | cmd.set_attribute("nvt_oid", nvt_oid) |
||
| 5144 | |||
| 5145 | if config_id: |
||
| 5146 | cmd.set_attribute("config_id", config_id) |
||
| 5147 | |||
| 5148 | return self._send_xml_command(cmd) |
||
| 5149 | |||
| 5150 | def get_preference( |
||
| 5151 | self, |
||
| 5152 | name: str, |
||
| 5153 | *, |
||
| 5154 | nvt_oid: Optional[str] = None, |
||
| 5155 | config_id: Optional[str] = None, |
||
| 5156 | ) -> Any: |
||
| 5157 | """Request a nvt preference |
||
| 5158 | |||
| 5159 | Arguments: |
||
| 5160 | name: name of a particular preference |
||
| 5161 | nvt_oid: OID of nvt |
||
| 5162 | config_id: UUID of scan config of which to show preference values |
||
| 5163 | |||
| 5164 | Returns: |
||
| 5165 | The response. See :py:meth:`send_command` for details. |
||
| 5166 | """ |
||
| 5167 | cmd = XmlCommand("get_preferences") |
||
| 5168 | |||
| 5169 | if not name: |
||
| 5170 | raise RequiredArgument( |
||
| 5171 | function=self.get_preference.__name__, argument='name' |
||
| 5172 | ) |
||
| 5173 | |||
| 5174 | cmd.set_attribute("preference", name) |
||
| 5175 | |||
| 5176 | if nvt_oid: |
||
| 5177 | cmd.set_attribute("nvt_oid", nvt_oid) |
||
| 5178 | |||
| 5179 | if config_id: |
||
| 5180 | cmd.set_attribute("config_id", config_id) |
||
| 5181 | |||
| 5182 | return self._send_xml_command(cmd) |
||
| 5183 | |||
| 5184 | View Code Duplication | def get_reports( |
|
| 5185 | self, |
||
| 5186 | *, |
||
| 5187 | filter: Optional[str] = None, |
||
| 5188 | filter_id: Optional[str] = None, |
||
| 5189 | note_details: Optional[bool] = None, |
||
| 5190 | override_details: Optional[bool] = None, |
||
| 5191 | details: Optional[bool] = None, |
||
| 5192 | ) -> Any: |
||
| 5193 | """Request a list of reports |
||
| 5194 | |||
| 5195 | Arguments: |
||
| 5196 | filter: Filter term to use for the query |
||
| 5197 | filter_id: UUID of an existing filter to use for the query |
||
| 5198 | note_details: If notes are included, whether to include note details |
||
| 5199 | override_details: If overrides are included, whether to include |
||
| 5200 | override details |
||
| 5201 | details: Whether to exclude results |
||
| 5202 | |||
| 5203 | Returns: |
||
| 5204 | The response. See :py:meth:`send_command` for details. |
||
| 5205 | """ |
||
| 5206 | cmd = XmlCommand("get_reports") |
||
| 5207 | |||
| 5208 | if filter: |
||
| 5209 | cmd.set_attribute("report_filter", filter) |
||
| 5210 | |||
| 5211 | if filter_id: |
||
| 5212 | cmd.set_attribute("report_filt_id", filter_id) |
||
| 5213 | |||
| 5214 | if note_details is not None: |
||
| 5215 | cmd.set_attribute("note_details", to_bool(note_details)) |
||
| 5216 | |||
| 5217 | if override_details is not None: |
||
| 5218 | cmd.set_attribute("override_details", to_bool(override_details)) |
||
| 5219 | |||
| 5220 | if details is not None: |
||
| 5221 | cmd.set_attribute("details", to_bool(details)) |
||
| 5222 | |||
| 5223 | cmd.set_attribute("ignore_pagination", "1") |
||
| 5224 | |||
| 5225 | return self._send_xml_command(cmd) |
||
| 5226 | |||
| 5227 | def get_report( |
||
| 5228 | self, |
||
| 5229 | report_id: str, |
||
| 5230 | *, |
||
| 5231 | filter: Optional[str] = None, |
||
| 5232 | filter_id: Optional[str] = None, |
||
| 5233 | delta_report_id: Optional[str] = None, |
||
| 5234 | report_format_id: Optional[Union[str, ReportFormatType]] = None, |
||
| 5235 | ignore_pagination: Optional[bool] = None, |
||
| 5236 | details: Optional[bool] = True, |
||
| 5237 | ) -> Any: |
||
| 5238 | """Request a single report |
||
| 5239 | |||
| 5240 | Arguments: |
||
| 5241 | report_id: UUID of an existing report |
||
| 5242 | filter: Filter term to use to filter results in the report |
||
| 5243 | filter_id: UUID of filter to use to filter results in the report |
||
| 5244 | delta_report_id: UUID of an existing report to compare report to. |
||
| 5245 | report_format_id: UUID of report format to use |
||
| 5246 | or ReportFormatType (enum) |
||
| 5247 | ignore_pagination: Whether to ignore the filter terms "first" and |
||
| 5248 | "rows". |
||
| 5249 | details: Request additional report information details |
||
| 5250 | defaults to True |
||
| 5251 | |||
| 5252 | Returns: |
||
| 5253 | The response. See :py:meth:`send_command` for details. |
||
| 5254 | """ |
||
| 5255 | cmd = XmlCommand("get_reports") |
||
| 5256 | |||
| 5257 | if not report_id: |
||
| 5258 | raise RequiredArgument( |
||
| 5259 | function=self.get_report.__name__, argument='report_id' |
||
| 5260 | ) |
||
| 5261 | |||
| 5262 | cmd.set_attribute("report_id", report_id) |
||
| 5263 | |||
| 5264 | add_filter(cmd, filter, filter_id) |
||
| 5265 | |||
| 5266 | if delta_report_id: |
||
| 5267 | cmd.set_attribute("delta_report_id", delta_report_id) |
||
| 5268 | |||
| 5269 | if report_format_id: |
||
| 5270 | if isinstance(report_format_id, ReportFormatType): |
||
| 5271 | report_format_id = report_format_id.value |
||
| 5272 | |||
| 5273 | cmd.set_attribute("format_id", report_format_id) |
||
| 5274 | |||
| 5275 | if ignore_pagination is not None: |
||
| 5276 | cmd.set_attribute("ignore_pagination", to_bool(ignore_pagination)) |
||
| 5277 | |||
| 5278 | cmd.set_attribute("details", to_bool(details)) |
||
| 5279 | |||
| 5280 | return self._send_xml_command(cmd) |
||
| 5281 | |||
| 5282 | def get_report_formats( |
||
| 5283 | self, |
||
| 5284 | *, |
||
| 5285 | filter: Optional[str] = None, |
||
| 5286 | filter_id: Optional[str] = None, |
||
| 5287 | trash: Optional[bool] = None, |
||
| 5288 | alerts: Optional[bool] = None, |
||
| 5289 | params: Optional[bool] = None, |
||
| 5290 | details: Optional[bool] = None, |
||
| 5291 | ) -> Any: |
||
| 5292 | """Request a list of report formats |
||
| 5293 | |||
| 5294 | Arguments: |
||
| 5295 | filter: Filter term to use for the query |
||
| 5296 | filter_id: UUID of an existing filter to use for the query |
||
| 5297 | trash: Whether to get the trashcan report formats instead |
||
| 5298 | alerts: Whether to include alerts that use the report format |
||
| 5299 | params: Whether to include report format parameters |
||
| 5300 | details: Include report format file, signature and parameters |
||
| 5301 | |||
| 5302 | Returns: |
||
| 5303 | The response. See :py:meth:`send_command` for details. |
||
| 5304 | """ |
||
| 5305 | cmd = XmlCommand("get_report_formats") |
||
| 5306 | |||
| 5307 | add_filter(cmd, filter, filter_id) |
||
| 5308 | |||
| 5309 | if details is not None: |
||
| 5310 | cmd.set_attribute("details", to_bool(details)) |
||
| 5311 | |||
| 5312 | if alerts is not None: |
||
| 5313 | cmd.set_attribute("alerts", to_bool(alerts)) |
||
| 5314 | |||
| 5315 | if params is not None: |
||
| 5316 | cmd.set_attribute("params", to_bool(params)) |
||
| 5317 | |||
| 5318 | if trash is not None: |
||
| 5319 | cmd.set_attribute("trash", to_bool(trash)) |
||
| 5320 | |||
| 5321 | return self._send_xml_command(cmd) |
||
| 5322 | |||
| 5323 | View Code Duplication | def get_report_format( |
|
| 5324 | self, report_format_id: Union[str, ReportFormatType] |
||
| 5325 | ) -> Any: |
||
| 5326 | """Request a single report format |
||
| 5327 | |||
| 5328 | Arguments: |
||
| 5329 | report_format_id: UUID of an existing report format |
||
| 5330 | or ReportFormatType (enum) |
||
| 5331 | |||
| 5332 | Returns: |
||
| 5333 | The response. See :py:meth:`send_command` for details. |
||
| 5334 | """ |
||
| 5335 | cmd = XmlCommand("get_report_formats") |
||
| 5336 | |||
| 5337 | if not report_format_id: |
||
| 5338 | raise RequiredArgument( |
||
| 5339 | function=self.get_report_format.__name__, |
||
| 5340 | argument='report_format_id', |
||
| 5341 | ) |
||
| 5342 | |||
| 5343 | if isinstance(report_format_id, ReportFormatType): |
||
| 5344 | report_format_id = report_format_id.value |
||
| 5345 | |||
| 5346 | cmd.set_attribute("report_format_id", report_format_id) |
||
| 5347 | |||
| 5348 | # for single entity always request all details |
||
| 5349 | cmd.set_attribute("details", "1") |
||
| 5350 | return self._send_xml_command(cmd) |
||
| 5351 | |||
| 5352 | View Code Duplication | def get_results( |
|
| 5353 | self, |
||
| 5354 | *, |
||
| 5355 | filter: Optional[str] = None, |
||
| 5356 | filter_id: Optional[str] = None, |
||
| 5357 | task_id: Optional[str] = None, |
||
| 5358 | note_details: Optional[bool] = None, |
||
| 5359 | override_details: Optional[bool] = None, |
||
| 5360 | details: Optional[bool] = None, |
||
| 5361 | ) -> Any: |
||
| 5362 | """Request a list of results |
||
| 5363 | |||
| 5364 | Arguments: |
||
| 5365 | filter: Filter term to use for the query |
||
| 5366 | filter_id: UUID of an existing filter to use for the query |
||
| 5367 | task_id: UUID of task for note and override handling |
||
| 5368 | note_details: If notes are included, whether to include note details |
||
| 5369 | override_details: If overrides are included, whether to include |
||
| 5370 | override details |
||
| 5371 | details: Whether to include additional details of the results |
||
| 5372 | |||
| 5373 | Returns: |
||
| 5374 | The response. See :py:meth:`send_command` for details. |
||
| 5375 | """ |
||
| 5376 | cmd = XmlCommand("get_results") |
||
| 5377 | |||
| 5378 | add_filter(cmd, filter, filter_id) |
||
| 5379 | |||
| 5380 | if task_id: |
||
| 5381 | cmd.set_attribute("task_id", task_id) |
||
| 5382 | |||
| 5383 | if details is not None: |
||
| 5384 | cmd.set_attribute("details", to_bool(details)) |
||
| 5385 | |||
| 5386 | if note_details is not None: |
||
| 5387 | cmd.set_attribute("note_details", to_bool(note_details)) |
||
| 5388 | |||
| 5389 | if override_details is not None: |
||
| 5390 | cmd.set_attribute("override_details", to_bool(override_details)) |
||
| 5391 | |||
| 5392 | return self._send_xml_command(cmd) |
||
| 5393 | |||
| 5394 | def get_result(self, result_id: str) -> Any: |
||
| 5395 | """Request a single result |
||
| 5396 | |||
| 5397 | Arguments: |
||
| 5398 | result_id: UUID of an existing result |
||
| 5399 | |||
| 5400 | Returns: |
||
| 5401 | The response. See :py:meth:`send_command` for details. |
||
| 5402 | """ |
||
| 5403 | cmd = XmlCommand("get_results") |
||
| 5404 | |||
| 5405 | if not result_id: |
||
| 5406 | raise RequiredArgument( |
||
| 5407 | function=self.get_result.__name__, argument='result_id' |
||
| 5408 | ) |
||
| 5409 | |||
| 5410 | cmd.set_attribute("result_id", result_id) |
||
| 5411 | |||
| 5412 | # for single entity always request all details |
||
| 5413 | cmd.set_attribute("details", "1") |
||
| 5414 | return self._send_xml_command(cmd) |
||
| 5415 | |||
| 5416 | View Code Duplication | def get_roles( |
|
| 5417 | self, |
||
| 5418 | *, |
||
| 5419 | filter: Optional[str] = None, |
||
| 5420 | filter_id: Optional[str] = None, |
||
| 5421 | trash: Optional[bool] = None, |
||
| 5422 | ) -> Any: |
||
| 5423 | """Request a list of roles |
||
| 5424 | |||
| 5425 | Arguments: |
||
| 5426 | filter: Filter term to use for the query |
||
| 5427 | filter_id: UUID of an existing filter to use for the query |
||
| 5428 | trash: Whether to get the trashcan roles instead |
||
| 5429 | |||
| 5430 | Returns: |
||
| 5431 | The response. See :py:meth:`send_command` for details. |
||
| 5432 | """ |
||
| 5433 | cmd = XmlCommand("get_roles") |
||
| 5434 | |||
| 5435 | add_filter(cmd, filter, filter_id) |
||
| 5436 | |||
| 5437 | if trash is not None: |
||
| 5438 | cmd.set_attribute("trash", to_bool(trash)) |
||
| 5439 | |||
| 5440 | return self._send_xml_command(cmd) |
||
| 5441 | |||
| 5442 | def get_role(self, role_id: str) -> Any: |
||
| 5443 | """Request a single role |
||
| 5444 | |||
| 5445 | Arguments: |
||
| 5446 | role_id: UUID of an existing role |
||
| 5447 | |||
| 5448 | Returns: |
||
| 5449 | The response. See :py:meth:`send_command` for details. |
||
| 5450 | """ |
||
| 5451 | if not role_id: |
||
| 5452 | raise RequiredArgument( |
||
| 5453 | function=self.get_role.__name__, argument='role_id' |
||
| 5454 | ) |
||
| 5455 | |||
| 5456 | cmd = XmlCommand("get_roles") |
||
| 5457 | cmd.set_attribute("role_id", role_id) |
||
| 5458 | return self._send_xml_command(cmd) |
||
| 5459 | |||
| 5460 | View Code Duplication | def get_scanners( |
|
| 5461 | self, |
||
| 5462 | *, |
||
| 5463 | filter: Optional[str] = None, |
||
| 5464 | filter_id: Optional[str] = None, |
||
| 5465 | trash: Optional[bool] = None, |
||
| 5466 | details: Optional[bool] = None, |
||
| 5467 | ) -> Any: |
||
| 5468 | """Request a list of scanners |
||
| 5469 | |||
| 5470 | Arguments: |
||
| 5471 | filter: Filter term to use for the query |
||
| 5472 | filter_id: UUID of an existing filter to use for the query |
||
| 5473 | trash: Whether to get the trashcan scanners instead |
||
| 5474 | details: Whether to include extra details like tasks using this |
||
| 5475 | scanner |
||
| 5476 | |||
| 5477 | Returns: |
||
| 5478 | The response. See :py:meth:`send_command` for details. |
||
| 5479 | """ |
||
| 5480 | cmd = XmlCommand("get_scanners") |
||
| 5481 | |||
| 5482 | add_filter(cmd, filter, filter_id) |
||
| 5483 | |||
| 5484 | if trash is not None: |
||
| 5485 | cmd.set_attribute("trash", to_bool(trash)) |
||
| 5486 | |||
| 5487 | if details is not None: |
||
| 5488 | cmd.set_attribute("details", to_bool(details)) |
||
| 5489 | |||
| 5490 | return self._send_xml_command(cmd) |
||
| 5491 | |||
| 5492 | def get_scanner(self, scanner_id: str) -> Any: |
||
| 5493 | """Request a single scanner |
||
| 5494 | |||
| 5495 | Arguments: |
||
| 5496 | scanner_id: UUID of an existing scanner |
||
| 5497 | |||
| 5498 | Returns: |
||
| 5499 | The response. See :py:meth:`send_command` for details. |
||
| 5500 | """ |
||
| 5501 | cmd = XmlCommand("get_scanners") |
||
| 5502 | |||
| 5503 | if not scanner_id: |
||
| 5504 | raise RequiredArgument( |
||
| 5505 | function=self.get_scanner.__name__, argument='scanner_id' |
||
| 5506 | ) |
||
| 5507 | |||
| 5508 | cmd.set_attribute("scanner_id", scanner_id) |
||
| 5509 | |||
| 5510 | # for single entity always request all details |
||
| 5511 | cmd.set_attribute("details", "1") |
||
| 5512 | return self._send_xml_command(cmd) |
||
| 5513 | |||
| 5514 | def get_schedules( |
||
| 5515 | self, |
||
| 5516 | *, |
||
| 5517 | filter: Optional[str] = None, |
||
| 5518 | filter_id: Optional[str] = None, |
||
| 5519 | trash: Optional[bool] = None, |
||
| 5520 | tasks: Optional[bool] = None, |
||
| 5521 | ) -> Any: |
||
| 5522 | """Request a list of schedules |
||
| 5523 | |||
| 5524 | Arguments: |
||
| 5525 | filter: Filter term to use for the query |
||
| 5526 | filter_id: UUID of an existing filter to use for the query |
||
| 5527 | trash: Whether to get the trashcan schedules instead |
||
| 5528 | tasks: Whether to include tasks using the schedules |
||
| 5529 | |||
| 5530 | Returns: |
||
| 5531 | The response. See :py:meth:`send_command` for details. |
||
| 5532 | """ |
||
| 5533 | cmd = XmlCommand("get_schedules") |
||
| 5534 | |||
| 5535 | add_filter(cmd, filter, filter_id) |
||
| 5536 | |||
| 5537 | if trash is not None: |
||
| 5538 | cmd.set_attribute("trash", to_bool(trash)) |
||
| 5539 | |||
| 5540 | if tasks is not None: |
||
| 5541 | cmd.set_attribute("tasks", to_bool(tasks)) |
||
| 5542 | |||
| 5543 | return self._send_xml_command(cmd) |
||
| 5544 | |||
| 5545 | def get_schedule( |
||
| 5546 | self, schedule_id: str, *, tasks: Optional[bool] = None |
||
| 5547 | ) -> Any: |
||
| 5548 | """Request a single schedule |
||
| 5549 | |||
| 5550 | Arguments: |
||
| 5551 | schedule_id: UUID of an existing schedule |
||
| 5552 | tasks: Whether to include tasks using the schedules |
||
| 5553 | |||
| 5554 | Returns: |
||
| 5555 | The response. See :py:meth:`send_command` for details. |
||
| 5556 | """ |
||
| 5557 | cmd = XmlCommand("get_schedules") |
||
| 5558 | |||
| 5559 | if not schedule_id: |
||
| 5560 | raise RequiredArgument( |
||
| 5561 | function=self.get_schedule.__name__, argument='schedule_id' |
||
| 5562 | ) |
||
| 5563 | |||
| 5564 | cmd.set_attribute("schedule_id", schedule_id) |
||
| 5565 | |||
| 5566 | if tasks is not None: |
||
| 5567 | cmd.set_attribute("tasks", to_bool(tasks)) |
||
| 5568 | |||
| 5569 | return self._send_xml_command(cmd) |
||
| 5570 | |||
| 5571 | def get_settings(self, *, filter: Optional[str] = None) -> Any: |
||
| 5572 | """Request a list of user settings |
||
| 5573 | |||
| 5574 | Arguments: |
||
| 5575 | filter: Filter term to use for the query |
||
| 5576 | |||
| 5577 | Returns: |
||
| 5578 | The response. See :py:meth:`send_command` for details. |
||
| 5579 | """ |
||
| 5580 | cmd = XmlCommand("get_settings") |
||
| 5581 | |||
| 5582 | if filter: |
||
| 5583 | cmd.set_attribute("filter", filter) |
||
| 5584 | |||
| 5585 | return self._send_xml_command(cmd) |
||
| 5586 | |||
| 5587 | def get_setting(self, setting_id: str) -> Any: |
||
| 5588 | """Request a single setting |
||
| 5589 | |||
| 5590 | Arguments: |
||
| 5591 | setting_id: UUID of an existing setting |
||
| 5592 | |||
| 5593 | Returns: |
||
| 5594 | The response. See :py:meth:`send_command` for details. |
||
| 5595 | """ |
||
| 5596 | cmd = XmlCommand("get_settings") |
||
| 5597 | |||
| 5598 | if not setting_id: |
||
| 5599 | raise RequiredArgument( |
||
| 5600 | function=self.get_setting.__name__, argument='setting_id' |
||
| 5601 | ) |
||
| 5602 | |||
| 5603 | cmd.set_attribute("setting_id", setting_id) |
||
| 5604 | return self._send_xml_command(cmd) |
||
| 5605 | |||
| 5606 | def get_system_reports( |
||
| 5607 | self, |
||
| 5608 | *, |
||
| 5609 | name: Optional[str] = None, |
||
| 5610 | duration: Optional[int] = None, |
||
| 5611 | start_time: Optional[str] = None, |
||
| 5612 | end_time: Optional[str] = None, |
||
| 5613 | brief: Optional[bool] = None, |
||
| 5614 | slave_id: Optional[str] = None, |
||
| 5615 | ) -> Any: |
||
| 5616 | """Request a list of system reports |
||
| 5617 | |||
| 5618 | Arguments: |
||
| 5619 | name: A string describing the required system report |
||
| 5620 | duration: The number of seconds into the past that the system report |
||
| 5621 | should include |
||
| 5622 | start_time: The start of the time interval the system report should |
||
| 5623 | include in ISO time format |
||
| 5624 | end_time: The end of the time interval the system report should |
||
| 5625 | include in ISO time format |
||
| 5626 | brief: Whether to include the actual system reports |
||
| 5627 | slave_id: UUID of GMP scanner from which to get the system reports |
||
| 5628 | |||
| 5629 | Returns: |
||
| 5630 | The response. See :py:meth:`send_command` for details. |
||
| 5631 | """ |
||
| 5632 | cmd = XmlCommand("get_system_reports") |
||
| 5633 | |||
| 5634 | if name: |
||
| 5635 | cmd.set_attribute("name", name) |
||
| 5636 | |||
| 5637 | if duration is not None: |
||
| 5638 | if not isinstance(duration, numbers.Integral): |
||
| 5639 | raise InvalidArgument("duration needs to be an integer number") |
||
| 5640 | |||
| 5641 | cmd.set_attribute("duration", str(duration)) |
||
| 5642 | |||
| 5643 | if start_time: |
||
| 5644 | cmd.set_attribute("start_time", str(start_time)) |
||
| 5645 | |||
| 5646 | if end_time: |
||
| 5647 | cmd.set_attribute("end_time", str(end_time)) |
||
| 5648 | |||
| 5649 | if brief is not None: |
||
| 5650 | cmd.set_attribute("brief", to_bool(brief)) |
||
| 5651 | |||
| 5652 | if slave_id: |
||
| 5653 | cmd.set_attribute("slave_id", slave_id) |
||
| 5654 | |||
| 5655 | return self._send_xml_command(cmd) |
||
| 5656 | |||
| 5657 | def get_tags( |
||
| 5658 | self, |
||
| 5659 | *, |
||
| 5660 | filter: Optional[str] = None, |
||
| 5661 | filter_id: Optional[str] = None, |
||
| 5662 | trash: Optional[bool] = None, |
||
| 5663 | names_only: Optional[bool] = None, |
||
| 5664 | ) -> Any: |
||
| 5665 | """Request a list of tags |
||
| 5666 | |||
| 5667 | Arguments: |
||
| 5668 | filter: Filter term to use for the query |
||
| 5669 | filter_id: UUID of an existing filter to use for the query |
||
| 5670 | trash: Whether to get tags from the trashcan instead |
||
| 5671 | names_only: Whether to get only distinct tag names |
||
| 5672 | |||
| 5673 | Returns: |
||
| 5674 | The response. See :py:meth:`send_command` for details. |
||
| 5675 | """ |
||
| 5676 | cmd = XmlCommand("get_tags") |
||
| 5677 | |||
| 5678 | add_filter(cmd, filter, filter_id) |
||
| 5679 | |||
| 5680 | if trash is not None: |
||
| 5681 | cmd.set_attribute("trash", to_bool(trash)) |
||
| 5682 | |||
| 5683 | if names_only is not None: |
||
| 5684 | cmd.set_attribute("names_only", to_bool(names_only)) |
||
| 5685 | |||
| 5686 | return self._send_xml_command(cmd) |
||
| 5687 | |||
| 5688 | def get_tag(self, tag_id: str) -> Any: |
||
| 5689 | """Request a single tag |
||
| 5690 | |||
| 5691 | Arguments: |
||
| 5692 | tag_id: UUID of an existing tag |
||
| 5693 | |||
| 5694 | Returns: |
||
| 5695 | The response. See :py:meth:`send_command` for details. |
||
| 5696 | """ |
||
| 5697 | cmd = XmlCommand("get_tags") |
||
| 5698 | |||
| 5699 | if not tag_id: |
||
| 5700 | raise RequiredArgument( |
||
| 5701 | function=self.get_tag.__name__, argument='tag_id' |
||
| 5702 | ) |
||
| 5703 | |||
| 5704 | cmd.set_attribute("tag_id", tag_id) |
||
| 5705 | return self._send_xml_command(cmd) |
||
| 5706 | |||
| 5707 | def get_targets( |
||
| 5708 | self, |
||
| 5709 | *, |
||
| 5710 | filter: Optional[str] = None, |
||
| 5711 | filter_id: Optional[str] = None, |
||
| 5712 | trash: Optional[bool] = None, |
||
| 5713 | tasks: Optional[bool] = None, |
||
| 5714 | ) -> Any: |
||
| 5715 | """Request a list of targets |
||
| 5716 | |||
| 5717 | Arguments: |
||
| 5718 | filter: Filter term to use for the query |
||
| 5719 | filter_id: UUID of an existing filter to use for the query |
||
| 5720 | trash: Whether to get the trashcan targets instead |
||
| 5721 | tasks: Whether to include list of tasks that use the target |
||
| 5722 | |||
| 5723 | Returns: |
||
| 5724 | The response. See :py:meth:`send_command` for details. |
||
| 5725 | """ |
||
| 5726 | cmd = XmlCommand("get_targets") |
||
| 5727 | |||
| 5728 | add_filter(cmd, filter, filter_id) |
||
| 5729 | |||
| 5730 | if trash is not None: |
||
| 5731 | cmd.set_attribute("trash", to_bool(trash)) |
||
| 5732 | |||
| 5733 | if tasks is not None: |
||
| 5734 | cmd.set_attribute("tasks", to_bool(tasks)) |
||
| 5735 | |||
| 5736 | return self._send_xml_command(cmd) |
||
| 5737 | |||
| 5738 | def get_target( |
||
| 5739 | self, target_id: str, *, tasks: Optional[bool] = None |
||
| 5740 | ) -> Any: |
||
| 5741 | """Request a single target |
||
| 5742 | |||
| 5743 | Arguments: |
||
| 5744 | target_id: UUID of an existing target |
||
| 5745 | tasks: Whether to include list of tasks that use the target |
||
| 5746 | |||
| 5747 | Returns: |
||
| 5748 | The response. See :py:meth:`send_command` for details. |
||
| 5749 | """ |
||
| 5750 | cmd = XmlCommand("get_targets") |
||
| 5751 | |||
| 5752 | if not target_id: |
||
| 5753 | raise RequiredArgument( |
||
| 5754 | function=self.get_target.__name__, argument='target_id' |
||
| 5755 | ) |
||
| 5756 | |||
| 5757 | cmd.set_attribute("target_id", target_id) |
||
| 5758 | |||
| 5759 | if tasks is not None: |
||
| 5760 | cmd.set_attribute("tasks", to_bool(tasks)) |
||
| 5761 | |||
| 5762 | return self._send_xml_command(cmd) |
||
| 5763 | |||
| 5764 | def get_users( |
||
| 5765 | self, *, filter: Optional[str] = None, filter_id: Optional[str] = None |
||
| 5766 | ) -> Any: |
||
| 5767 | """Request a list of users |
||
| 5768 | |||
| 5769 | Arguments: |
||
| 5770 | filter: Filter term to use for the query |
||
| 5771 | filter_id: UUID of an existing filter to use for the query |
||
| 5772 | |||
| 5773 | Returns: |
||
| 5774 | The response. See :py:meth:`send_command` for details. |
||
| 5775 | """ |
||
| 5776 | cmd = XmlCommand("get_users") |
||
| 5777 | |||
| 5778 | add_filter(cmd, filter, filter_id) |
||
| 5779 | |||
| 5780 | return self._send_xml_command(cmd) |
||
| 5781 | |||
| 5782 | def get_user(self, user_id: str) -> Any: |
||
| 5783 | """Request a single user |
||
| 5784 | |||
| 5785 | Arguments: |
||
| 5786 | user_id: UUID of an existing user |
||
| 5787 | |||
| 5788 | Returns: |
||
| 5789 | The response. See :py:meth:`send_command` for details. |
||
| 5790 | """ |
||
| 5791 | cmd = XmlCommand("get_users") |
||
| 5792 | |||
| 5793 | if not user_id: |
||
| 5794 | raise RequiredArgument( |
||
| 5795 | function=self.get_user.__name__, argument='user_id' |
||
| 5796 | ) |
||
| 5797 | |||
| 5798 | cmd.set_attribute("user_id", user_id) |
||
| 5799 | return self._send_xml_command(cmd) |
||
| 5800 | |||
| 5801 | def get_version(self) -> Any: |
||
| 5802 | """Get the Greenbone Manager Protocol version used by the remote gvmd |
||
| 5803 | |||
| 5804 | Returns: |
||
| 5805 | The response. See :py:meth:`send_command` for details. |
||
| 5806 | """ |
||
| 5807 | return self._send_xml_command(XmlCommand("get_version")) |
||
| 5808 | |||
| 5809 | def help( |
||
| 5810 | self, *, format: Optional[str] = None, help_type: Optional[str] = "" |
||
| 5811 | ) -> Any: |
||
| 5812 | """Get the help text |
||
| 5813 | |||
| 5814 | Arguments: |
||
| 5815 | format: One of "html", "rnc", "text" or "xml |
||
| 5816 | help_type: One of "brief" or "". Default "" |
||
| 5817 | |||
| 5818 | Returns: |
||
| 5819 | The response. See :py:meth:`send_command` for details. |
||
| 5820 | """ |
||
| 5821 | cmd = XmlCommand("help") |
||
| 5822 | |||
| 5823 | if help_type not in ("", "brief"): |
||
| 5824 | raise InvalidArgument( |
||
| 5825 | 'help_type argument must be an empty string or "brief"' |
||
| 5826 | ) |
||
| 5827 | |||
| 5828 | cmd.set_attribute("type", help_type) |
||
| 5829 | |||
| 5830 | if format: |
||
| 5831 | if not format.lower() in ("html", "rnc", "text", "xml"): |
||
| 5832 | raise InvalidArgument( |
||
| 5833 | "help format Argument must be one of html, rnc, text or " |
||
| 5834 | "xml" |
||
| 5835 | ) |
||
| 5836 | |||
| 5837 | cmd.set_attribute("format", format) |
||
| 5838 | |||
| 5839 | return self._send_xml_command(cmd) |
||
| 5840 | |||
| 5841 | def modify_asset(self, asset_id: str, comment: Optional[str] = "") -> Any: |
||
| 5842 | """Modifies an existing asset. |
||
| 5843 | |||
| 5844 | Arguments: |
||
| 5845 | asset_id: UUID of the asset to be modified. |
||
| 5846 | comment: Comment for the asset. |
||
| 5847 | |||
| 5848 | Returns: |
||
| 5849 | The response. See :py:meth:`send_command` for details. |
||
| 5850 | """ |
||
| 5851 | if not asset_id: |
||
| 5852 | raise RequiredArgument( |
||
| 5853 | function=self.modify_asset.__name__, argument='asset_id' |
||
| 5854 | ) |
||
| 5855 | |||
| 5856 | cmd = XmlCommand("modify_asset") |
||
| 5857 | cmd.set_attribute("asset_id", asset_id) |
||
| 5858 | cmd.add_element("comment", comment) |
||
| 5859 | |||
| 5860 | return self._send_xml_command(cmd) |
||
| 5861 | |||
| 5862 | def modify_auth(self, group_name: str, auth_conf_settings: dict) -> Any: |
||
| 5863 | """Modifies an existing auth. |
||
| 5864 | |||
| 5865 | Arguments: |
||
| 5866 | group_name: Name of the group to be modified. |
||
| 5867 | auth_conf_settings: The new auth config. |
||
| 5868 | |||
| 5869 | Returns: |
||
| 5870 | The response. See :py:meth:`send_command` for details. |
||
| 5871 | """ |
||
| 5872 | if not group_name: |
||
| 5873 | raise RequiredArgument( |
||
| 5874 | function=self.modify_auth.__name__, argument='group_name' |
||
| 5875 | ) |
||
| 5876 | if not auth_conf_settings: |
||
| 5877 | raise RequiredArgument( |
||
| 5878 | function=self.modify_auth.__name__, |
||
| 5879 | argument='auth_conf_settings', |
||
| 5880 | ) |
||
| 5881 | cmd = XmlCommand("modify_auth") |
||
| 5882 | _xmlgroup = cmd.add_element("group", attrs={"name": str(group_name)}) |
||
| 5883 | |||
| 5884 | for key, value in auth_conf_settings.items(): |
||
| 5885 | _xmlauthconf = _xmlgroup.add_element("auth_conf_setting") |
||
| 5886 | _xmlauthconf.add_element("key", key) |
||
| 5887 | _xmlauthconf.add_element("value", value) |
||
| 5888 | |||
| 5889 | return self._send_xml_command(cmd) |
||
| 5890 | |||
| 5891 | def modify_config_set_nvt_preference( |
||
| 5892 | self, |
||
| 5893 | config_id: str, |
||
| 5894 | name: str, |
||
| 5895 | nvt_oid: str, |
||
| 5896 | *, |
||
| 5897 | value: Optional[str] = None, |
||
| 5898 | ) -> Any: |
||
| 5899 | """Modifies the nvt preferences of an existing scan config. |
||
| 5900 | |||
| 5901 | Arguments: |
||
| 5902 | config_id: UUID of scan config to modify. |
||
| 5903 | name: Name for nvt preference to change. |
||
| 5904 | nvt_oid: OID of the NVT associated with preference to modify |
||
| 5905 | value: New value for the preference. None to delete the preference |
||
| 5906 | and to use the default instead. |
||
| 5907 | """ |
||
| 5908 | if not config_id: |
||
| 5909 | raise RequiredArgument( |
||
| 5910 | function=self.modify_config_set_nvt_preference.__name__, |
||
| 5911 | argument='config_id', |
||
| 5912 | ) |
||
| 5913 | |||
| 5914 | if not nvt_oid: |
||
| 5915 | raise RequiredArgument( |
||
| 5916 | function=self.modify_config_set_nvt_preference.__name__, |
||
| 5917 | argument='nvt_oid', |
||
| 5918 | ) |
||
| 5919 | |||
| 5920 | if not name: |
||
| 5921 | raise RequiredArgument( |
||
| 5922 | function=self.modify_config_set_nvt_preference.__name__, |
||
| 5923 | argument='name', |
||
| 5924 | ) |
||
| 5925 | |||
| 5926 | cmd = XmlCommand("modify_config") |
||
| 5927 | cmd.set_attribute("config_id", str(config_id)) |
||
| 5928 | |||
| 5929 | _xmlpref = cmd.add_element("preference") |
||
| 5930 | |||
| 5931 | _xmlpref.add_element("nvt", attrs={"oid": nvt_oid}) |
||
| 5932 | _xmlpref.add_element("name", name) |
||
| 5933 | |||
| 5934 | if value: |
||
| 5935 | _xmlpref.add_element("value", to_base64(value)) |
||
| 5936 | |||
| 5937 | return self._send_xml_command(cmd) |
||
| 5938 | |||
| 5939 | def modify_config_set_name(self, config_id: str, name: str) -> Any: |
||
| 5940 | """Modifies the name of an existing scan config |
||
| 5941 | |||
| 5942 | Arguments: |
||
| 5943 | config_id: UUID of scan config to modify. |
||
| 5944 | name: New name for the config. |
||
| 5945 | """ |
||
| 5946 | if not config_id: |
||
| 5947 | raise RequiredArgument( |
||
| 5948 | function=self.modify_config_set_name.__name__, |
||
| 5949 | argument='config_id', |
||
| 5950 | ) |
||
| 5951 | |||
| 5952 | if not name: |
||
| 5953 | raise RequiredArgument( |
||
| 5954 | function=self.modify_config_set_name.__name__, argument='name' |
||
| 5955 | ) |
||
| 5956 | |||
| 5957 | cmd = XmlCommand("modify_config") |
||
| 5958 | cmd.set_attribute("config_id", str(config_id)) |
||
| 5959 | |||
| 5960 | cmd.add_element("name", name) |
||
| 5961 | |||
| 5962 | return self._send_xml_command(cmd) |
||
| 5963 | |||
| 5964 | def modify_config_set_comment( |
||
| 5965 | self, config_id: str, comment: Optional[str] = "" |
||
| 5966 | ) -> Any: |
||
| 5967 | """Modifies the comment of an existing scan config |
||
| 5968 | |||
| 5969 | Arguments: |
||
| 5970 | config_id: UUID of scan config to modify. |
||
| 5971 | comment: Comment to set on a config. Default: '' |
||
| 5972 | """ |
||
| 5973 | if not config_id: |
||
| 5974 | raise RequiredArgument( |
||
| 5975 | function=self.modify_config_set_comment.__name__, |
||
| 5976 | argument='config_id argument', |
||
| 5977 | ) |
||
| 5978 | |||
| 5979 | cmd = XmlCommand("modify_config") |
||
| 5980 | cmd.set_attribute("config_id", str(config_id)) |
||
| 5981 | |||
| 5982 | cmd.add_element("comment", comment) |
||
| 5983 | |||
| 5984 | return self._send_xml_command(cmd) |
||
| 5985 | |||
| 5986 | def modify_config_set_scanner_preference( |
||
| 5987 | self, config_id: str, name: str, *, value: Optional[str] = None |
||
| 5988 | ) -> Any: |
||
| 5989 | """Modifies the scanner preferences of an existing scan config |
||
| 5990 | |||
| 5991 | Arguments: |
||
| 5992 | config_id: UUID of scan config to modify. |
||
| 5993 | name: Name of the scanner preference to change |
||
| 5994 | value: New value for the preference. None to delete the preference |
||
| 5995 | and to use the default instead. |
||
| 5996 | |||
| 5997 | """ |
||
| 5998 | if not config_id: |
||
| 5999 | raise RequiredArgument( |
||
| 6000 | function=self.modify_config_set_scanner_preference.__name__, |
||
| 6001 | argument='config_id', |
||
| 6002 | ) |
||
| 6003 | |||
| 6004 | if not name: |
||
| 6005 | raise RequiredArgument( |
||
| 6006 | function=self.modify_config_set_scanner_preference.__name__, |
||
| 6007 | argument='name argument', |
||
| 6008 | ) |
||
| 6009 | |||
| 6010 | cmd = XmlCommand("modify_config") |
||
| 6011 | cmd.set_attribute("config_id", str(config_id)) |
||
| 6012 | |||
| 6013 | _xmlpref = cmd.add_element("preference") |
||
| 6014 | |||
| 6015 | _xmlpref.add_element("name", name) |
||
| 6016 | |||
| 6017 | if value: |
||
| 6018 | _xmlpref.add_element("value", to_base64(value)) |
||
| 6019 | |||
| 6020 | return self._send_xml_command(cmd) |
||
| 6021 | |||
| 6022 | def modify_config_set_nvt_selection( |
||
| 6023 | self, config_id: str, family: str, nvt_oids: List[str] |
||
| 6024 | ) -> Any: |
||
| 6025 | """Modifies the selected nvts of an existing scan config |
||
| 6026 | |||
| 6027 | The manager updates the given family in the config to include only the |
||
| 6028 | given NVTs. |
||
| 6029 | |||
| 6030 | Arguments: |
||
| 6031 | config_id: UUID of scan config to modify. |
||
| 6032 | family: Name of the NVT family to include NVTs from |
||
| 6033 | nvt_oids: List of NVTs to select for the family. |
||
| 6034 | """ |
||
| 6035 | if not config_id: |
||
| 6036 | raise RequiredArgument( |
||
| 6037 | function=self.modify_config_set_nvt_selection.__name__, |
||
| 6038 | argument='config_id', |
||
| 6039 | ) |
||
| 6040 | |||
| 6041 | if not family: |
||
| 6042 | raise RequiredArgument( |
||
| 6043 | function=self.modify_config_set_nvt_selection.__name__, |
||
| 6044 | argument='family argument', |
||
| 6045 | ) |
||
| 6046 | |||
| 6047 | if not is_list_like(nvt_oids): |
||
| 6048 | raise InvalidArgumentType( |
||
| 6049 | function=self.modify_config_set_nvt_selection.__name__, |
||
| 6050 | argument='nvt_oids', |
||
| 6051 | arg_type='list', |
||
| 6052 | ) |
||
| 6053 | |||
| 6054 | cmd = XmlCommand("modify_config") |
||
| 6055 | cmd.set_attribute("config_id", str(config_id)) |
||
| 6056 | |||
| 6057 | _xmlnvtsel = cmd.add_element("nvt_selection") |
||
| 6058 | _xmlnvtsel.add_element("family", family) |
||
| 6059 | |||
| 6060 | for nvt in nvt_oids: |
||
| 6061 | _xmlnvtsel.add_element("nvt", attrs={"oid": nvt}) |
||
| 6062 | |||
| 6063 | return self._send_xml_command(cmd) |
||
| 6064 | |||
| 6065 | def modify_config_set_family_selection( |
||
| 6066 | self, |
||
| 6067 | config_id: str, |
||
| 6068 | families: List[Tuple[str, bool, bool]], |
||
| 6069 | *, |
||
| 6070 | auto_add_new_families: Optional[bool] = True, |
||
| 6071 | ) -> Any: |
||
| 6072 | """ |
||
| 6073 | Selected the NVTs of a scan config at a family level. |
||
| 6074 | |||
| 6075 | Arguments: |
||
| 6076 | config_id: UUID of scan config to modify. |
||
| 6077 | families: A list of tuples (str, bool, bool): |
||
| 6078 | str: the name of the NVT family selected, |
||
| 6079 | bool: add new NVTs to the family automatically, |
||
| 6080 | bool: include all NVTs from the family |
||
| 6081 | auto_add_new_families: Whether new families should be added to the |
||
| 6082 | scan config automatically. Default: True. |
||
| 6083 | """ |
||
| 6084 | if not config_id: |
||
| 6085 | raise RequiredArgument( |
||
| 6086 | function=self.modify_config_set_family_selection.__name__, |
||
| 6087 | argument='config_id', |
||
| 6088 | ) |
||
| 6089 | |||
| 6090 | if not is_list_like(families): |
||
| 6091 | raise InvalidArgumentType( |
||
| 6092 | function=self.modify_config_set_family_selection.__name__, |
||
| 6093 | argument='families', |
||
| 6094 | arg_type='list', |
||
| 6095 | ) |
||
| 6096 | |||
| 6097 | cmd = XmlCommand("modify_config") |
||
| 6098 | cmd.set_attribute("config_id", str(config_id)) |
||
| 6099 | |||
| 6100 | _xmlfamsel = cmd.add_element("family_selection") |
||
| 6101 | _xmlfamsel.add_element("growing", to_bool(auto_add_new_families)) |
||
| 6102 | |||
| 6103 | for family in families: |
||
| 6104 | _xmlfamily = _xmlfamsel.add_element("family") |
||
| 6105 | _xmlfamily.add_element("name", family[0]) |
||
| 6106 | |||
| 6107 | if len(family) != 3: |
||
| 6108 | raise InvalidArgument( |
||
| 6109 | "Family must be a tuple of 3. (str, bool, bool)" |
||
| 6110 | ) |
||
| 6111 | |||
| 6112 | if not isinstance(family[1], bool) or not isinstance( |
||
| 6113 | family[2], bool |
||
| 6114 | ): |
||
| 6115 | raise InvalidArgumentType( |
||
| 6116 | function=self.modify_config_set_family_selection.__name__, |
||
| 6117 | argument='families', |
||
| 6118 | arg_type='[tuple(str, bool, bool)]', |
||
| 6119 | ) |
||
| 6120 | |||
| 6121 | _xmlfamily.add_element("all", to_bool(family[2])) |
||
| 6122 | _xmlfamily.add_element("growing", to_bool(family[1])) |
||
| 6123 | |||
| 6124 | return self._send_xml_command(cmd) |
||
| 6125 | |||
| 6126 | def modify_config( |
||
| 6127 | self, config_id: str, selection: Optional[str] = None, **kwargs |
||
| 6128 | ) -> Any: |
||
| 6129 | """Modifies an existing scan config. |
||
| 6130 | |||
| 6131 | DEPRECATED. Please use *modify_config_set_* methods instead. |
||
| 6132 | |||
| 6133 | modify_config has four modes to operate depending on the selection. |
||
| 6134 | |||
| 6135 | Arguments: |
||
| 6136 | config_id: UUID of scan config to modify. |
||
| 6137 | selection: one of 'scan_pref', 'nvt_pref', 'nvt_selection' or |
||
| 6138 | 'family_selection' |
||
| 6139 | name: New name for preference. |
||
| 6140 | value: New value for preference. |
||
| 6141 | nvt_oids: List of NVTs associated with preference to modify. |
||
| 6142 | family: Name of family to modify. |
||
| 6143 | |||
| 6144 | Returns: |
||
| 6145 | The response. See :py:meth:`send_command` for details. |
||
| 6146 | """ |
||
| 6147 | if not config_id: |
||
| 6148 | raise RequiredArgument( |
||
| 6149 | function=self.modify_config.__name__, |
||
| 6150 | argument='config_id argument', |
||
| 6151 | ) |
||
| 6152 | |||
| 6153 | if selection is None: |
||
| 6154 | deprecation( |
||
| 6155 | "Using modify_config to update the comment of a scan config is" |
||
| 6156 | "deprecated. Please use modify_config_set_comment instead." |
||
| 6157 | ) |
||
| 6158 | return self.modify_config_set_comment( |
||
| 6159 | config_id, kwargs.get("comment") |
||
| 6160 | ) |
||
| 6161 | |||
| 6162 | if selection not in ( |
||
| 6163 | "nvt_pref", |
||
| 6164 | "scan_pref", |
||
| 6165 | "family_selection", |
||
| 6166 | "nvt_selection", |
||
| 6167 | ): |
||
| 6168 | raise InvalidArgument( |
||
| 6169 | "selection must be one of nvt_pref, " |
||
| 6170 | "scan_pref, family_selection or " |
||
| 6171 | "nvt_selection" |
||
| 6172 | ) |
||
| 6173 | |||
| 6174 | if selection == "nvt_pref": |
||
| 6175 | deprecation( |
||
| 6176 | "Using modify_config to update a nvt preference of a scan " |
||
| 6177 | "config is deprecated. Please use " |
||
| 6178 | "modify_config_set_nvt_preference instead." |
||
| 6179 | ) |
||
| 6180 | return self.modify_config_set_nvt_preference(config_id, **kwargs) |
||
| 6181 | |||
| 6182 | if selection == "scan_pref": |
||
| 6183 | deprecation( |
||
| 6184 | "Using modify_config to update a scanner preference of a " |
||
| 6185 | "scan config is deprecated. Please use " |
||
| 6186 | "modify_config_set_scanner_preference instead." |
||
| 6187 | ) |
||
| 6188 | return self.modify_config_set_scanner_preference( |
||
| 6189 | config_id, **kwargs |
||
| 6190 | ) |
||
| 6191 | |||
| 6192 | if selection == "nvt_selection": |
||
| 6193 | deprecation( |
||
| 6194 | "Using modify_config to update a nvt selection of a " |
||
| 6195 | "scan config is deprecated. Please use " |
||
| 6196 | "modify_config_set_nvt_selection instead." |
||
| 6197 | ) |
||
| 6198 | return self.modify_config_set_nvt_selection(config_id, **kwargs) |
||
| 6199 | |||
| 6200 | deprecation( |
||
| 6201 | "Using modify_config to update a family selection of a " |
||
| 6202 | "scan config is deprecated. Please use " |
||
| 6203 | "modify_config_set_family_selection instead." |
||
| 6204 | ) |
||
| 6205 | return self.modify_config_set_family_selection(config_id, **kwargs) |
||
| 6206 | |||
| 6207 | View Code Duplication | def modify_group( |
|
| 6208 | self, |
||
| 6209 | group_id: str, |
||
| 6210 | *, |
||
| 6211 | comment: Optional[str] = None, |
||
| 6212 | name: Optional[str] = None, |
||
| 6213 | users: Optional[List[str]] = None, |
||
| 6214 | ) -> Any: |
||
| 6215 | """Modifies an existing group. |
||
| 6216 | |||
| 6217 | Arguments: |
||
| 6218 | group_id: UUID of group to modify. |
||
| 6219 | comment: Comment on group. |
||
| 6220 | name: Name of group. |
||
| 6221 | users: List of user names to be in the group |
||
| 6222 | |||
| 6223 | Returns: |
||
| 6224 | The response. See :py:meth:`send_command` for details. |
||
| 6225 | """ |
||
| 6226 | if not group_id: |
||
| 6227 | raise RequiredArgument( |
||
| 6228 | function=self.modify_group.__name__, argument='group_id' |
||
| 6229 | ) |
||
| 6230 | |||
| 6231 | cmd = XmlCommand("modify_group") |
||
| 6232 | cmd.set_attribute("group_id", group_id) |
||
| 6233 | |||
| 6234 | if comment: |
||
| 6235 | cmd.add_element("comment", comment) |
||
| 6236 | |||
| 6237 | if name: |
||
| 6238 | cmd.add_element("name", name) |
||
| 6239 | |||
| 6240 | if users: |
||
| 6241 | cmd.add_element("users", to_comma_list(users)) |
||
| 6242 | |||
| 6243 | return self._send_xml_command(cmd) |
||
| 6244 | |||
| 6245 | View Code Duplication | def modify_note( |
|
| 6246 | self, |
||
| 6247 | note_id: str, |
||
| 6248 | text: str, |
||
| 6249 | *, |
||
| 6250 | days_active: Optional[int] = None, |
||
| 6251 | hosts: Optional[List[str]] = None, |
||
| 6252 | port: Optional[int] = None, |
||
| 6253 | result_id: Optional[str] = None, |
||
| 6254 | severity: Optional[Severity] = None, |
||
| 6255 | task_id: Optional[str] = None, |
||
| 6256 | threat: Optional[SeverityLevel] = None, |
||
| 6257 | ) -> Any: |
||
| 6258 | """Modifies an existing note. |
||
| 6259 | |||
| 6260 | Arguments: |
||
| 6261 | note_id: UUID of note to modify. |
||
| 6262 | text: The text of the note. |
||
| 6263 | days_active: Days note will be active. -1 on always, 0 off. |
||
| 6264 | hosts: A list of hosts addresses |
||
| 6265 | port: Port to which note applies. |
||
| 6266 | result_id: Result to which note applies. |
||
| 6267 | severity: Severity to which note applies. |
||
| 6268 | task_id: Task to which note applies. |
||
| 6269 | threat: Threat level to which note applies. Will be converted to |
||
| 6270 | severity. |
||
| 6271 | |||
| 6272 | Returns: |
||
| 6273 | The response. See :py:meth:`send_command` for details. |
||
| 6274 | """ |
||
| 6275 | if not note_id: |
||
| 6276 | raise RequiredArgument( |
||
| 6277 | function=self.modify_note.__name__, argument='note_id' |
||
| 6278 | ) |
||
| 6279 | |||
| 6280 | if not text: |
||
| 6281 | raise RequiredArgument( |
||
| 6282 | function=self.modify_note.__name__, argument='text' |
||
| 6283 | ) |
||
| 6284 | |||
| 6285 | cmd = XmlCommand("modify_note") |
||
| 6286 | cmd.set_attribute("note_id", note_id) |
||
| 6287 | cmd.add_element("text", text) |
||
| 6288 | |||
| 6289 | if days_active is not None: |
||
| 6290 | cmd.add_element("active", str(days_active)) |
||
| 6291 | |||
| 6292 | if hosts: |
||
| 6293 | cmd.add_element("hosts", to_comma_list(hosts)) |
||
| 6294 | |||
| 6295 | if port: |
||
| 6296 | cmd.add_element("port", str(port)) |
||
| 6297 | |||
| 6298 | if result_id: |
||
| 6299 | cmd.add_element("result", attrs={"id": result_id}) |
||
| 6300 | |||
| 6301 | if severity: |
||
| 6302 | cmd.add_element("severity", str(severity)) |
||
| 6303 | |||
| 6304 | if task_id: |
||
| 6305 | cmd.add_element("task", attrs={"id": task_id}) |
||
| 6306 | |||
| 6307 | if threat is not None: |
||
| 6308 | |||
| 6309 | if not isinstance(threat, SeverityLevel): |
||
| 6310 | raise InvalidArgumentType( |
||
| 6311 | function=self.modify_note.__name__, |
||
| 6312 | argument='threat', |
||
| 6313 | arg_type=SeverityLevel.__name__, |
||
| 6314 | ) |
||
| 6315 | |||
| 6316 | cmd.add_element("threat", threat.value) |
||
| 6317 | |||
| 6318 | return self._send_xml_command(cmd) |
||
| 6319 | |||
| 6320 | View Code Duplication | def modify_override( |
|
| 6321 | self, |
||
| 6322 | override_id: str, |
||
| 6323 | text: str, |
||
| 6324 | *, |
||
| 6325 | days_active: Optional[int] = None, |
||
| 6326 | hosts: Optional[List[str]] = None, |
||
| 6327 | port: Optional[int] = None, |
||
| 6328 | result_id: Optional[str] = None, |
||
| 6329 | severity: Optional[Severity] = None, |
||
| 6330 | new_severity: Optional[Severity] = None, |
||
| 6331 | task_id: Optional[str] = None, |
||
| 6332 | threat: Optional[SeverityLevel] = None, |
||
| 6333 | new_threat: Optional[SeverityLevel] = None, |
||
| 6334 | ) -> Any: |
||
| 6335 | """Modifies an existing override. |
||
| 6336 | |||
| 6337 | Arguments: |
||
| 6338 | override_id: UUID of override to modify. |
||
| 6339 | text: The text of the override. |
||
| 6340 | days_active: Days override will be active. -1 on always, |
||
| 6341 | 0 off. |
||
| 6342 | hosts: A list of host addresses |
||
| 6343 | port: Port to which override applies. |
||
| 6344 | result_id: Result to which override applies. |
||
| 6345 | severity: Severity to which override applies. |
||
| 6346 | new_severity: New severity score for result. |
||
| 6347 | task_id: Task to which override applies. |
||
| 6348 | threat: Threat level to which override applies. |
||
| 6349 | Will be converted to severity. |
||
| 6350 | new_threat: New threat level for results. Will be converted to |
||
| 6351 | new_severity. |
||
| 6352 | |||
| 6353 | Returns: |
||
| 6354 | The response. See :py:meth:`send_command` for details. |
||
| 6355 | """ |
||
| 6356 | if not override_id: |
||
| 6357 | raise RequiredArgument( |
||
| 6358 | function=self.modify_override.__name__, argument='override_id' |
||
| 6359 | ) |
||
| 6360 | if not text: |
||
| 6361 | raise RequiredArgument( |
||
| 6362 | function=self.modify_override.__name__, argument='text' |
||
| 6363 | ) |
||
| 6364 | |||
| 6365 | cmd = XmlCommand("modify_override") |
||
| 6366 | cmd.set_attribute("override_id", override_id) |
||
| 6367 | cmd.add_element("text", text) |
||
| 6368 | |||
| 6369 | if days_active is not None: |
||
| 6370 | cmd.add_element("active", str(days_active)) |
||
| 6371 | |||
| 6372 | if hosts: |
||
| 6373 | cmd.add_element("hosts", to_comma_list(hosts)) |
||
| 6374 | |||
| 6375 | if port: |
||
| 6376 | cmd.add_element("port", str(port)) |
||
| 6377 | |||
| 6378 | if result_id: |
||
| 6379 | cmd.add_element("result", attrs={"id": result_id}) |
||
| 6380 | |||
| 6381 | if severity: |
||
| 6382 | cmd.add_element("severity", str(severity)) |
||
| 6383 | |||
| 6384 | if new_severity: |
||
| 6385 | cmd.add_element("new_severity", str(new_severity)) |
||
| 6386 | |||
| 6387 | if task_id: |
||
| 6388 | cmd.add_element("task", attrs={"id": task_id}) |
||
| 6389 | |||
| 6390 | if threat is not None: |
||
| 6391 | if not isinstance(threat, SeverityLevel): |
||
| 6392 | raise InvalidArgumentType( |
||
| 6393 | function=self.modify_override.__name__, |
||
| 6394 | argument='threat', |
||
| 6395 | arg_type=SeverityLevel.__name__, |
||
| 6396 | ) |
||
| 6397 | cmd.add_element("threat", threat.value) |
||
| 6398 | |||
| 6399 | if new_threat is not None: |
||
| 6400 | if not isinstance(new_threat, SeverityLevel): |
||
| 6401 | raise InvalidArgumentType( |
||
| 6402 | function=self.modify_override.__name__, |
||
| 6403 | argument='new_threat', |
||
| 6404 | arg_type=SeverityLevel.__name__, |
||
| 6405 | ) |
||
| 6406 | |||
| 6407 | cmd.add_element("new_threat", new_threat.value) |
||
| 6408 | |||
| 6409 | return self._send_xml_command(cmd) |
||
| 6410 | |||
| 6411 | def modify_port_list( |
||
| 6412 | self, |
||
| 6413 | port_list_id: str, |
||
| 6414 | *, |
||
| 6415 | comment: Optional[str] = None, |
||
| 6416 | name: Optional[str] = None, |
||
| 6417 | ) -> Any: |
||
| 6418 | """Modifies an existing port list. |
||
| 6419 | |||
| 6420 | Arguments: |
||
| 6421 | port_list_id: UUID of port list to modify. |
||
| 6422 | name: Name of port list. |
||
| 6423 | comment: Comment on port list. |
||
| 6424 | |||
| 6425 | Returns: |
||
| 6426 | The response. See :py:meth:`send_command` for details. |
||
| 6427 | """ |
||
| 6428 | if not port_list_id: |
||
| 6429 | raise RequiredArgument( |
||
| 6430 | function=self.modify_port_list.__name__, argument='port_list_id' |
||
| 6431 | ) |
||
| 6432 | cmd = XmlCommand("modify_port_list") |
||
| 6433 | cmd.set_attribute("port_list_id", port_list_id) |
||
| 6434 | |||
| 6435 | if comment: |
||
| 6436 | cmd.add_element("comment", comment) |
||
| 6437 | |||
| 6438 | if name: |
||
| 6439 | cmd.add_element("name", name) |
||
| 6440 | |||
| 6441 | return self._send_xml_command(cmd) |
||
| 6442 | |||
| 6443 | def modify_report_format( |
||
| 6444 | self, |
||
| 6445 | report_format_id: Optional[Union[str, ReportFormatType]] = None, |
||
| 6446 | *, |
||
| 6447 | active: Optional[bool] = None, |
||
| 6448 | name: Optional[str] = None, |
||
| 6449 | summary: Optional[str] = None, |
||
| 6450 | param_name: Optional[str] = None, |
||
| 6451 | param_value: Optional[str] = None, |
||
| 6452 | ) -> Any: |
||
| 6453 | """Modifies an existing report format. |
||
| 6454 | |||
| 6455 | Arguments: |
||
| 6456 | report_format_id: UUID of report format to modify |
||
| 6457 | or ReportFormatType (enum) |
||
| 6458 | active: Whether the report format is active. |
||
| 6459 | name: The name of the report format. |
||
| 6460 | summary: A summary of the report format. |
||
| 6461 | param_name: The name of the param. |
||
| 6462 | param_value: The value of the param. |
||
| 6463 | |||
| 6464 | Returns: |
||
| 6465 | The response. See :py:meth:`send_command` for details. |
||
| 6466 | """ |
||
| 6467 | if not report_format_id: |
||
| 6468 | raise RequiredArgument( |
||
| 6469 | function=self.modify_report_format.__name__, |
||
| 6470 | argument='report_format_id ', |
||
| 6471 | ) |
||
| 6472 | |||
| 6473 | cmd = XmlCommand("modify_report_format") |
||
| 6474 | |||
| 6475 | if isinstance(report_format_id, ReportFormatType): |
||
| 6476 | report_format_id = report_format_id.value |
||
| 6477 | |||
| 6478 | cmd.set_attribute("report_format_id", report_format_id) |
||
| 6479 | |||
| 6480 | if active is not None: |
||
| 6481 | cmd.add_element("active", to_bool(active)) |
||
| 6482 | |||
| 6483 | if name: |
||
| 6484 | cmd.add_element("name", name) |
||
| 6485 | |||
| 6486 | if summary: |
||
| 6487 | cmd.add_element("summary", summary) |
||
| 6488 | |||
| 6489 | if param_name: |
||
| 6490 | _xmlparam = cmd.add_element("param") |
||
| 6491 | _xmlparam.add_element("name", param_name) |
||
| 6492 | |||
| 6493 | if param_value is not None: |
||
| 6494 | _xmlparam.add_element("value", param_value) |
||
| 6495 | |||
| 6496 | return self._send_xml_command(cmd) |
||
| 6497 | |||
| 6498 | View Code Duplication | def modify_role( |
|
| 6499 | self, |
||
| 6500 | role_id: str, |
||
| 6501 | *, |
||
| 6502 | comment: Optional[str] = None, |
||
| 6503 | name: Optional[str] = None, |
||
| 6504 | users: Optional[List[str]] = None, |
||
| 6505 | ) -> Any: |
||
| 6506 | """Modifies an existing role. |
||
| 6507 | |||
| 6508 | Arguments: |
||
| 6509 | role_id: UUID of role to modify. |
||
| 6510 | comment: Name of role. |
||
| 6511 | name: Comment on role. |
||
| 6512 | users: List of user names. |
||
| 6513 | |||
| 6514 | Returns: |
||
| 6515 | The response. See :py:meth:`send_command` for details. |
||
| 6516 | """ |
||
| 6517 | if not role_id: |
||
| 6518 | raise RequiredArgument( |
||
| 6519 | function=self.modify_role.__name__, argument='role_id argument' |
||
| 6520 | ) |
||
| 6521 | |||
| 6522 | cmd = XmlCommand("modify_role") |
||
| 6523 | cmd.set_attribute("role_id", role_id) |
||
| 6524 | |||
| 6525 | if comment: |
||
| 6526 | cmd.add_element("comment", comment) |
||
| 6527 | |||
| 6528 | if name: |
||
| 6529 | cmd.add_element("name", name) |
||
| 6530 | |||
| 6531 | if users: |
||
| 6532 | cmd.add_element("users", to_comma_list(users)) |
||
| 6533 | |||
| 6534 | return self._send_xml_command(cmd) |
||
| 6535 | |||
| 6536 | def modify_scanner( |
||
| 6537 | self, |
||
| 6538 | scanner_id: str, |
||
| 6539 | *, |
||
| 6540 | scanner_type: Optional[ScannerType] = None, |
||
| 6541 | host: Optional[str] = None, |
||
| 6542 | port: Optional[int] = None, |
||
| 6543 | comment: Optional[str] = None, |
||
| 6544 | name: Optional[str] = None, |
||
| 6545 | ca_pub: Optional[str] = None, |
||
| 6546 | credential_id: Optional[str] = None, |
||
| 6547 | ) -> Any: |
||
| 6548 | """Modifies an existing scanner. |
||
| 6549 | |||
| 6550 | Arguments: |
||
| 6551 | scanner_id: UUID of scanner to modify. |
||
| 6552 | scanner_type: New type of the Scanner. |
||
| 6553 | host: Host of the scanner. |
||
| 6554 | port: Port of the scanner. |
||
| 6555 | comment: Comment on scanner. |
||
| 6556 | name: Name of scanner. |
||
| 6557 | ca_pub: Certificate of CA to verify scanner's certificate. |
||
| 6558 | credential_id: UUID of the client certificate credential for the |
||
| 6559 | Scanner. |
||
| 6560 | |||
| 6561 | Returns: |
||
| 6562 | The response. See :py:meth:`send_command` for details. |
||
| 6563 | """ |
||
| 6564 | if not scanner_id: |
||
| 6565 | raise RequiredArgument( |
||
| 6566 | function=self.modify_scanner.__name__, |
||
| 6567 | argument='scanner_id argument', |
||
| 6568 | ) |
||
| 6569 | |||
| 6570 | cmd = XmlCommand("modify_scanner") |
||
| 6571 | cmd.set_attribute("scanner_id", scanner_id) |
||
| 6572 | |||
| 6573 | if scanner_type is not None: |
||
| 6574 | if not isinstance(scanner_type, self.types.ScannerType): |
||
| 6575 | raise InvalidArgumentType( |
||
| 6576 | function=self.modify_scanner.__name__, |
||
| 6577 | argument='scanner_type', |
||
| 6578 | arg_type=self.types.ScannerType.__name__, |
||
| 6579 | ) |
||
| 6580 | |||
| 6581 | cmd.add_element("type", scanner_type.value) |
||
| 6582 | |||
| 6583 | if host: |
||
| 6584 | cmd.add_element("host", host) |
||
| 6585 | |||
| 6586 | if port: |
||
| 6587 | cmd.add_element("port", str(port)) |
||
| 6588 | |||
| 6589 | if comment: |
||
| 6590 | cmd.add_element("comment", comment) |
||
| 6591 | |||
| 6592 | if name: |
||
| 6593 | cmd.add_element("name", name) |
||
| 6594 | |||
| 6595 | if ca_pub: |
||
| 6596 | cmd.add_element("ca_pub", ca_pub) |
||
| 6597 | |||
| 6598 | if credential_id: |
||
| 6599 | cmd.add_element("credential", attrs={"id": str(credential_id)}) |
||
| 6600 | |||
| 6601 | return self._send_xml_command(cmd) |
||
| 6602 | |||
| 6603 | def modify_setting( |
||
| 6604 | self, |
||
| 6605 | setting_id: Optional[str] = None, |
||
| 6606 | name: Optional[str] = None, |
||
| 6607 | value: Optional[str] = None, |
||
| 6608 | ) -> Any: |
||
| 6609 | """Modifies an existing setting. |
||
| 6610 | |||
| 6611 | Arguments: |
||
| 6612 | setting_id: UUID of the setting to be changed. |
||
| 6613 | name: The name of the setting. Either setting_id or name must be |
||
| 6614 | passed. |
||
| 6615 | value: The value of the setting. |
||
| 6616 | |||
| 6617 | Returns: |
||
| 6618 | The response. See :py:meth:`send_command` for details. |
||
| 6619 | """ |
||
| 6620 | if not setting_id and not name: |
||
| 6621 | raise RequiredArgument( |
||
| 6622 | function=self.modify_setting.__name__, |
||
| 6623 | argument='setting_id or name argument', |
||
| 6624 | ) |
||
| 6625 | |||
| 6626 | if value is None: |
||
| 6627 | raise RequiredArgument( |
||
| 6628 | function=self.modify_setting.__name__, argument='value argument' |
||
| 6629 | ) |
||
| 6630 | |||
| 6631 | cmd = XmlCommand("modify_setting") |
||
| 6632 | |||
| 6633 | if setting_id: |
||
| 6634 | cmd.set_attribute("setting_id", setting_id) |
||
| 6635 | else: |
||
| 6636 | cmd.add_element("name", name) |
||
| 6637 | |||
| 6638 | cmd.add_element("value", to_base64(value)) |
||
| 6639 | |||
| 6640 | return self._send_xml_command(cmd) |
||
| 6641 | |||
| 6642 | def modify_target( |
||
| 6643 | self, |
||
| 6644 | target_id: str, |
||
| 6645 | *, |
||
| 6646 | name: Optional[str] = None, |
||
| 6647 | comment: Optional[str] = None, |
||
| 6648 | hosts: Optional[List[str]] = None, |
||
| 6649 | exclude_hosts: Optional[List[str]] = None, |
||
| 6650 | ssh_credential_id: Optional[str] = None, |
||
| 6651 | ssh_credential_port: Optional[bool] = None, |
||
| 6652 | smb_credential_id: Optional[str] = None, |
||
| 6653 | esxi_credential_id: Optional[str] = None, |
||
| 6654 | snmp_credential_id: Optional[str] = None, |
||
| 6655 | alive_test: Optional[AliveTest] = None, |
||
| 6656 | reverse_lookup_only: Optional[bool] = None, |
||
| 6657 | reverse_lookup_unify: Optional[bool] = None, |
||
| 6658 | port_list_id: Optional[str] = None, |
||
| 6659 | ) -> Any: |
||
| 6660 | """Modifies an existing target. |
||
| 6661 | |||
| 6662 | Arguments: |
||
| 6663 | target_id: ID of target to modify. |
||
| 6664 | comment: Comment on target. |
||
| 6665 | name: Name of target. |
||
| 6666 | hosts: List of target hosts. |
||
| 6667 | exclude_hosts: A list of hosts to exclude. |
||
| 6668 | ssh_credential_id: UUID of SSH credential to use on target. |
||
| 6669 | ssh_credential_port: The port to use for ssh credential |
||
| 6670 | smb_credential_id: UUID of SMB credential to use on target. |
||
| 6671 | esxi_credential_id: UUID of ESXi credential to use on target. |
||
| 6672 | snmp_credential_id: UUID of SNMP credential to use on target. |
||
| 6673 | port_list_id: UUID of port list describing ports to scan. |
||
| 6674 | alive_test: Which alive tests to use. |
||
| 6675 | reverse_lookup_only: Whether to scan only hosts that have names. |
||
| 6676 | reverse_lookup_unify: Whether to scan only one IP when multiple IPs |
||
| 6677 | have the same name. |
||
| 6678 | |||
| 6679 | Returns: |
||
| 6680 | The response. See :py:meth:`send_command` for details. |
||
| 6681 | """ |
||
| 6682 | if not target_id: |
||
| 6683 | raise RequiredArgument( |
||
| 6684 | function=self.modify_target.__name__, argument='target_id' |
||
| 6685 | ) |
||
| 6686 | |||
| 6687 | cmd = XmlCommand("modify_target") |
||
| 6688 | cmd.set_attribute("target_id", target_id) |
||
| 6689 | |||
| 6690 | if comment: |
||
| 6691 | cmd.add_element("comment", comment) |
||
| 6692 | |||
| 6693 | if name: |
||
| 6694 | cmd.add_element("name", name) |
||
| 6695 | |||
| 6696 | if hosts: |
||
| 6697 | cmd.add_element("hosts", to_comma_list(hosts)) |
||
| 6698 | if exclude_hosts is None: |
||
| 6699 | exclude_hosts = [''] |
||
| 6700 | |||
| 6701 | if exclude_hosts: |
||
| 6702 | cmd.add_element("exclude_hosts", to_comma_list(exclude_hosts)) |
||
| 6703 | |||
| 6704 | if alive_test: |
||
| 6705 | if not isinstance(alive_test, AliveTest): |
||
| 6706 | raise InvalidArgumentType( |
||
| 6707 | function=self.modify_target.__name__, |
||
| 6708 | argument='alive_test', |
||
| 6709 | arg_type=AliveTest.__name__, |
||
| 6710 | ) |
||
| 6711 | cmd.add_element("alive_tests", alive_test.value) |
||
| 6712 | |||
| 6713 | if ssh_credential_id: |
||
| 6714 | _xmlssh = cmd.add_element( |
||
| 6715 | "ssh_credential", attrs={"id": ssh_credential_id} |
||
| 6716 | ) |
||
| 6717 | |||
| 6718 | if ssh_credential_port: |
||
| 6719 | _xmlssh.add_element("port", str(ssh_credential_port)) |
||
| 6720 | |||
| 6721 | if smb_credential_id: |
||
| 6722 | cmd.add_element("smb_credential", attrs={"id": smb_credential_id}) |
||
| 6723 | |||
| 6724 | if esxi_credential_id: |
||
| 6725 | cmd.add_element("esxi_credential", attrs={"id": esxi_credential_id}) |
||
| 6726 | |||
| 6727 | if snmp_credential_id: |
||
| 6728 | cmd.add_element("snmp_credential", attrs={"id": snmp_credential_id}) |
||
| 6729 | |||
| 6730 | if reverse_lookup_only is not None: |
||
| 6731 | cmd.add_element("reverse_lookup_only", to_bool(reverse_lookup_only)) |
||
| 6732 | |||
| 6733 | if reverse_lookup_unify is not None: |
||
| 6734 | cmd.add_element( |
||
| 6735 | "reverse_lookup_unify", to_bool(reverse_lookup_unify) |
||
| 6736 | ) |
||
| 6737 | |||
| 6738 | if port_list_id: |
||
| 6739 | cmd.add_element("port_list", attrs={"id": port_list_id}) |
||
| 6740 | |||
| 6741 | return self._send_xml_command(cmd) |
||
| 6742 | |||
| 6743 | def modify_task( |
||
| 6744 | self, |
||
| 6745 | task_id: str, |
||
| 6746 | *, |
||
| 6747 | name: Optional[str] = None, |
||
| 6748 | config_id: Optional[str] = None, |
||
| 6749 | target_id: Optional[str] = None, |
||
| 6750 | scanner_id: Optional[str] = None, |
||
| 6751 | alterable: Optional[bool] = None, |
||
| 6752 | hosts_ordering: Optional[HostsOrdering] = None, |
||
| 6753 | schedule_id: Optional[str] = None, |
||
| 6754 | schedule_periods: Optional[int] = None, |
||
| 6755 | comment: Optional[str] = None, |
||
| 6756 | alert_ids: Optional[List[str]] = None, |
||
| 6757 | observers: Optional[List[str]] = None, |
||
| 6758 | preferences: Optional[dict] = None, |
||
| 6759 | ) -> Any: |
||
| 6760 | """Modifies an existing task. |
||
| 6761 | |||
| 6762 | Arguments: |
||
| 6763 | task_id: UUID of task to modify. |
||
| 6764 | name: The name of the task. |
||
| 6765 | config_id: UUID of scan config to use by the task |
||
| 6766 | target_id: UUID of target to be scanned |
||
| 6767 | scanner_id: UUID of scanner to use for scanning the target |
||
| 6768 | comment: The comment on the task. |
||
| 6769 | alert_ids: List of UUIDs for alerts to be applied to the task |
||
| 6770 | hosts_ordering: The order hosts are scanned in |
||
| 6771 | schedule_id: UUID of a schedule when the task should be run. |
||
| 6772 | schedule_periods: A limit to the number of times the task will be |
||
| 6773 | scheduled, or 0 for no limit. |
||
| 6774 | observers: List of names or ids of users which should be allowed to |
||
| 6775 | observe this task |
||
| 6776 | preferences: Name/Value pairs of scanner preferences. |
||
| 6777 | |||
| 6778 | Returns: |
||
| 6779 | The response. See :py:meth:`send_command` for details. |
||
| 6780 | """ |
||
| 6781 | if not task_id: |
||
| 6782 | raise RequiredArgument( |
||
| 6783 | function=self.modify_task.__name__, argument='task_id argument' |
||
| 6784 | ) |
||
| 6785 | |||
| 6786 | cmd = XmlCommand("modify_task") |
||
| 6787 | cmd.set_attribute("task_id", task_id) |
||
| 6788 | |||
| 6789 | if name: |
||
| 6790 | cmd.add_element("name", name) |
||
| 6791 | |||
| 6792 | if comment: |
||
| 6793 | cmd.add_element("comment", comment) |
||
| 6794 | |||
| 6795 | if config_id: |
||
| 6796 | cmd.add_element("config", attrs={"id": config_id}) |
||
| 6797 | |||
| 6798 | if target_id: |
||
| 6799 | cmd.add_element("target", attrs={"id": target_id}) |
||
| 6800 | |||
| 6801 | if alterable is not None: |
||
| 6802 | cmd.add_element("alterable", to_bool(alterable)) |
||
| 6803 | |||
| 6804 | if hosts_ordering: |
||
| 6805 | if not isinstance(hosts_ordering, HostsOrdering): |
||
| 6806 | raise InvalidArgumentType( |
||
| 6807 | function=self.modify_task.__name__, |
||
| 6808 | argument='hosts_ordering', |
||
| 6809 | arg_type=HostsOrdering.__name__, |
||
| 6810 | ) |
||
| 6811 | cmd.add_element("hosts_ordering", hosts_ordering.value) |
||
| 6812 | |||
| 6813 | if scanner_id: |
||
| 6814 | cmd.add_element("scanner", attrs={"id": scanner_id}) |
||
| 6815 | |||
| 6816 | if schedule_id: |
||
| 6817 | cmd.add_element("schedule", attrs={"id": schedule_id}) |
||
| 6818 | |||
| 6819 | View Code Duplication | if schedule_periods is not None: |
|
| 6820 | if ( |
||
| 6821 | not isinstance(schedule_periods, numbers.Integral) |
||
| 6822 | or schedule_periods < 0 |
||
| 6823 | ): |
||
| 6824 | raise InvalidArgument( |
||
| 6825 | "schedule_periods must be an integer greater or equal " |
||
| 6826 | "than 0" |
||
| 6827 | ) |
||
| 6828 | cmd.add_element("schedule_periods", str(schedule_periods)) |
||
| 6829 | |||
| 6830 | if alert_ids is not None: |
||
| 6831 | if not is_list_like(alert_ids): |
||
| 6832 | raise InvalidArgumentType( |
||
| 6833 | function=self.modify_task.__name__, |
||
| 6834 | argument='alert_ids', |
||
| 6835 | arg_type='list', |
||
| 6836 | ) |
||
| 6837 | |||
| 6838 | if len(alert_ids) == 0: |
||
| 6839 | cmd.add_element("alert", attrs={"id": "0"}) |
||
| 6840 | else: |
||
| 6841 | for alert in alert_ids: |
||
| 6842 | cmd.add_element("alert", attrs={"id": str(alert)}) |
||
| 6843 | |||
| 6844 | if observers is not None: |
||
| 6845 | if not is_list_like(observers): |
||
| 6846 | raise InvalidArgumentType( |
||
| 6847 | function=self.modify_task.__name__, |
||
| 6848 | argument='observers', |
||
| 6849 | arg_type='list', |
||
| 6850 | ) |
||
| 6851 | |||
| 6852 | cmd.add_element("observers", to_comma_list(observers)) |
||
| 6853 | |||
| 6854 | View Code Duplication | if preferences is not None: |
|
| 6855 | if not isinstance(preferences, collections.abc.Mapping): |
||
| 6856 | raise InvalidArgumentType( |
||
| 6857 | function=self.modify_task.__name__, |
||
| 6858 | argument='preferences', |
||
| 6859 | arg_type=collections.abc.Mapping.__name__, |
||
| 6860 | ) |
||
| 6861 | |||
| 6862 | _xmlprefs = cmd.add_element("preferences") |
||
| 6863 | for pref_name, pref_value in preferences.items(): |
||
| 6864 | _xmlpref = _xmlprefs.add_element("preference") |
||
| 6865 | _xmlpref.add_element("scanner_name", pref_name) |
||
| 6866 | _xmlpref.add_element("value", str(pref_value)) |
||
| 6867 | |||
| 6868 | return self._send_xml_command(cmd) |
||
| 6869 | |||
| 6870 | View Code Duplication | def modify_user( |
|
| 6871 | self, |
||
| 6872 | user_id: str = None, |
||
| 6873 | name: str = None, |
||
| 6874 | *, |
||
| 6875 | new_name: Optional[str] = None, |
||
| 6876 | comment: Optional[str] = None, |
||
| 6877 | password: Optional[str] = None, |
||
| 6878 | auth_source: Optional[UserAuthType] = None, |
||
| 6879 | role_ids: Optional[List[str]] = None, |
||
| 6880 | hosts: Optional[List[str]] = None, |
||
| 6881 | hosts_allow: Optional[bool] = False, |
||
| 6882 | ifaces: Optional[List[str]] = None, |
||
| 6883 | ifaces_allow: Optional[bool] = False, |
||
| 6884 | group_ids: Optional[List[str]] = None, |
||
| 6885 | ) -> Any: |
||
| 6886 | """Modifies an existing user. Most of the fields need to be supplied |
||
| 6887 | for changing a single field even if no change is wanted for those. |
||
| 6888 | Else empty values are inserted for the missing fields instead. |
||
| 6889 | |||
| 6890 | Arguments: |
||
| 6891 | user_id: UUID of the user to be modified. Overrides name element |
||
| 6892 | argument. |
||
| 6893 | name: The name of the user to be modified. Either user_id or name |
||
| 6894 | must be passed. |
||
| 6895 | new_name: The new name for the user. |
||
| 6896 | comment: Comment on the user. |
||
| 6897 | password: The password for the user. |
||
| 6898 | auth_source: Source allowed for authentication for this user. |
||
| 6899 | roles_id: List of roles UUIDs for the user. |
||
| 6900 | hosts: User access rules: List of hosts. |
||
| 6901 | hosts_allow: Defines how the hosts list is to be interpreted. |
||
| 6902 | If False (default) the list is treated as a deny list. |
||
| 6903 | All hosts are allowed by default except those provided by |
||
| 6904 | the hosts parameter. If True the list is treated as a |
||
| 6905 | allow list. All hosts are denied by default except those |
||
| 6906 | provided by the hosts parameter. |
||
| 6907 | ifaces: User access rules: List of ifaces. |
||
| 6908 | ifaces_allow: Defines how the ifaces list is to be interpreted. |
||
| 6909 | If False (default) the list is treated as a deny list. |
||
| 6910 | All ifaces are allowed by default except those provided by |
||
| 6911 | the ifaces parameter. If True the list is treated as a |
||
| 6912 | allow list. All ifaces are denied by default except those |
||
| 6913 | provided by the ifaces parameter. |
||
| 6914 | group_ids: List of group UUIDs for the user. |
||
| 6915 | |||
| 6916 | Returns: |
||
| 6917 | The response. See :py:meth:`send_command` for details. |
||
| 6918 | """ |
||
| 6919 | if not user_id and not name: |
||
| 6920 | raise RequiredArgument( |
||
| 6921 | function=self.modify_user.__name__, argument='user_id or name' |
||
| 6922 | ) |
||
| 6923 | |||
| 6924 | cmd = XmlCommand("modify_user") |
||
| 6925 | |||
| 6926 | if user_id: |
||
| 6927 | cmd.set_attribute("user_id", user_id) |
||
| 6928 | else: |
||
| 6929 | cmd.add_element("name", name) |
||
| 6930 | |||
| 6931 | if new_name: |
||
| 6932 | cmd.add_element("new_name", new_name) |
||
| 6933 | |||
| 6934 | if role_ids: |
||
| 6935 | for role in role_ids: |
||
| 6936 | cmd.add_element("role", attrs={"id": role}) |
||
| 6937 | |||
| 6938 | if hosts: |
||
| 6939 | cmd.add_element( |
||
| 6940 | "hosts", |
||
| 6941 | to_comma_list(hosts), |
||
| 6942 | attrs={"allow": to_bool(hosts_allow)}, |
||
| 6943 | ) |
||
| 6944 | |||
| 6945 | if ifaces: |
||
| 6946 | cmd.add_element( |
||
| 6947 | "ifaces", |
||
| 6948 | to_comma_list(ifaces), |
||
| 6949 | attrs={"allow": to_bool(ifaces_allow)}, |
||
| 6950 | ) |
||
| 6951 | |||
| 6952 | if comment: |
||
| 6953 | cmd.add_element("comment", comment) |
||
| 6954 | |||
| 6955 | if password: |
||
| 6956 | cmd.add_element("password", password) |
||
| 6957 | |||
| 6958 | if auth_source: |
||
| 6959 | _xmlauthsrc = cmd.add_element("sources") |
||
| 6960 | _xmlauthsrc.add_element("source", auth_source.value) |
||
| 6961 | |||
| 6962 | if group_ids: |
||
| 6963 | _xmlgroups = cmd.add_element("groups") |
||
| 6964 | for group_id in group_ids: |
||
| 6965 | _xmlgroups.add_element("group", attrs={"id": group_id}) |
||
| 6966 | |||
| 6967 | return self._send_xml_command(cmd) |
||
| 6968 | |||
| 6969 | def move_task(self, task_id: str, *, slave_id: Optional[str] = None) -> Any: |
||
| 6970 | """Move an existing task to another GMP slave scanner or the master |
||
| 6971 | |||
| 6972 | Arguments: |
||
| 6973 | task_id: UUID of the task to be moved |
||
| 6974 | slave_id: UUID of slave to reassign the task to, empty for master. |
||
| 6975 | |||
| 6976 | Returns: |
||
| 6977 | The response. See :py:meth:`send_command` for details. |
||
| 6978 | """ |
||
| 6979 | if not task_id: |
||
| 6980 | raise RequiredArgument( |
||
| 6981 | function=self.move_task.__name__, argument='task_id' |
||
| 6982 | ) |
||
| 6983 | |||
| 6984 | cmd = XmlCommand("move_task") |
||
| 6985 | cmd.set_attribute("task_id", task_id) |
||
| 6986 | |||
| 6987 | if slave_id is not None: |
||
| 6988 | cmd.set_attribute("slave_id", slave_id) |
||
| 6989 | |||
| 6990 | return self._send_xml_command(cmd) |
||
| 6991 | |||
| 6992 | def restore(self, entity_id: str) -> Any: |
||
| 6993 | """Restore an entity from the trashcan |
||
| 6994 | |||
| 6995 | Arguments: |
||
| 6996 | entity_id: ID of the entity to be restored from the trashcan |
||
| 6997 | |||
| 6998 | Returns: |
||
| 6999 | The response. See :py:meth:`send_command` for details. |
||
| 7000 | """ |
||
| 7001 | if not entity_id: |
||
| 7002 | raise RequiredArgument( |
||
| 7003 | function=self.restore.__name__, argument='entity_id' |
||
| 7004 | ) |
||
| 7005 | |||
| 7006 | cmd = XmlCommand("restore") |
||
| 7007 | cmd.set_attribute("id", entity_id) |
||
| 7008 | |||
| 7009 | return self._send_xml_command(cmd) |
||
| 7010 | |||
| 7011 | def resume_task(self, task_id: str) -> Any: |
||
| 7012 | """Resume an existing stopped task |
||
| 7013 | |||
| 7014 | Arguments: |
||
| 7015 | task_id: UUID of the task to be resumed |
||
| 7016 | |||
| 7017 | Returns: |
||
| 7018 | The response. See :py:meth:`send_command` for details. |
||
| 7019 | """ |
||
| 7020 | if not task_id: |
||
| 7021 | raise RequiredArgument( |
||
| 7022 | function=self.resume_task.__name__, argument='task_id' |
||
| 7023 | ) |
||
| 7024 | |||
| 7025 | cmd = XmlCommand("resume_task") |
||
| 7026 | cmd.set_attribute("task_id", task_id) |
||
| 7027 | |||
| 7028 | return self._send_xml_command(cmd) |
||
| 7029 | |||
| 7030 | def start_task(self, task_id: str) -> Any: |
||
| 7031 | """Start an existing task |
||
| 7032 | |||
| 7033 | Arguments: |
||
| 7034 | task_id: UUID of the task to be started |
||
| 7035 | |||
| 7036 | Returns: |
||
| 7037 | The response. See :py:meth:`send_command` for details. |
||
| 7038 | """ |
||
| 7039 | if not task_id: |
||
| 7040 | raise RequiredArgument( |
||
| 7041 | function=self.start_task.__name__, argument='task_id' |
||
| 7042 | ) |
||
| 7043 | |||
| 7044 | cmd = XmlCommand("start_task") |
||
| 7045 | cmd.set_attribute("task_id", task_id) |
||
| 7046 | |||
| 7047 | return self._send_xml_command(cmd) |
||
| 7048 | |||
| 7049 | def stop_task(self, task_id: str) -> Any: |
||
| 7050 | """Stop an existing running task |
||
| 7051 | |||
| 7052 | Arguments: |
||
| 7053 | task_id: UUID of the task to be stopped |
||
| 7054 | |||
| 7055 | Returns: |
||
| 7056 | The response. See :py:meth:`send_command` for details. |
||
| 7057 | """ |
||
| 7058 | if not task_id: |
||
| 7059 | raise RequiredArgument( |
||
| 7060 | function=self.stop_task.__name__, argument='task_id' |
||
| 7061 | ) |
||
| 7062 | |||
| 7063 | cmd = XmlCommand("stop_task") |
||
| 7064 | cmd.set_attribute("task_id", task_id) |
||
| 7065 | |||
| 7066 | return self._send_xml_command(cmd) |
||
| 7067 | |||
| 7068 | def sync_cert(self) -> Any: |
||
| 7069 | """Request a synchronization with the CERT feed service |
||
| 7070 | |||
| 7071 | Returns: |
||
| 7072 | The response. See :py:meth:`send_command` for details. |
||
| 7073 | """ |
||
| 7074 | return self._send_xml_command(XmlCommand("sync_cert")) |
||
| 7075 | |||
| 7076 | def sync_config(self) -> Any: |
||
| 7077 | """Request an OSP config synchronization with scanner |
||
| 7078 | |||
| 7079 | Returns: |
||
| 7080 | The response. See :py:meth:`send_command` for details. |
||
| 7081 | """ |
||
| 7082 | return self._send_xml_command(XmlCommand("sync_config")) |
||
| 7083 | |||
| 7084 | def sync_feed(self) -> Any: |
||
| 7085 | """Request a synchronization with the NVT feed service |
||
| 7086 | |||
| 7087 | Returns: |
||
| 7088 | The response. See :py:meth:`send_command` for details. |
||
| 7089 | """ |
||
| 7090 | return self._send_xml_command(XmlCommand("sync_feed")) |
||
| 7091 | |||
| 7092 | def sync_scap(self) -> Any: |
||
| 7093 | """Request a synchronization with the SCAP feed service |
||
| 7094 | |||
| 7095 | Returns: |
||
| 7096 | The response. See :py:meth:`send_command` for details. |
||
| 7097 | """ |
||
| 7098 | return self._send_xml_command(XmlCommand("sync_scap")) |
||
| 7099 | |||
| 7100 | def test_alert(self, alert_id: str) -> Any: |
||
| 7101 | """Run an alert |
||
| 7102 | |||
| 7103 | Invoke a test run of an alert |
||
| 7104 | |||
| 7105 | Arguments: |
||
| 7106 | alert_id: UUID of the alert to be tested |
||
| 7107 | |||
| 7108 | Returns: |
||
| 7109 | The response. See :py:meth:`send_command` for details. |
||
| 7110 | """ |
||
| 7111 | if not alert_id: |
||
| 7112 | raise InvalidArgument("test_alert requires an alert_id argument") |
||
| 7113 | |||
| 7114 | cmd = XmlCommand("test_alert") |
||
| 7115 | cmd.set_attribute("alert_id", alert_id) |
||
| 7116 | |||
| 7117 | return self._send_xml_command(cmd) |
||
| 7118 | |||
| 7119 | def trigger_alert( |
||
| 7120 | self, |
||
| 7121 | alert_id: str, |
||
| 7122 | report_id: str, |
||
| 7123 | *, |
||
| 7124 | filter: Optional[str] = None, |
||
| 7125 | filter_id: Optional[str] = None, |
||
| 7126 | report_format_id: Optional[Union[str, ReportFormatType]] = None, |
||
| 7127 | delta_report_id: Optional[str] = None, |
||
| 7128 | ) -> Any: |
||
| 7129 | """Run an alert by ignoring its event and conditions |
||
| 7130 | |||
| 7131 | The alert is triggered to run immediately with the provided filtered |
||
| 7132 | report by ignoring the even and condition settings. |
||
| 7133 | |||
| 7134 | Arguments: |
||
| 7135 | alert_id: UUID of the alert to be run |
||
| 7136 | report_id: UUID of the report to be provided to the alert |
||
| 7137 | filter: Filter term to use to filter results in the report |
||
| 7138 | filter_id: UUID of filter to use to filter results in the report |
||
| 7139 | report_format_id: UUID of report format to use |
||
| 7140 | or ReportFormatType (enum) |
||
| 7141 | delta_report_id: UUID of an existing report to compare report to. |
||
| 7142 | |||
| 7143 | Returns: |
||
| 7144 | The response. See :py:meth:`send_command` for details. |
||
| 7145 | """ |
||
| 7146 | if not alert_id: |
||
| 7147 | raise RequiredArgument( |
||
| 7148 | function=self.trigger_alert.__name__, |
||
| 7149 | argument='alert_id argument', |
||
| 7150 | ) |
||
| 7151 | |||
| 7152 | if not report_id: |
||
| 7153 | raise RequiredArgument( |
||
| 7154 | function=self.trigger_alert.__name__, |
||
| 7155 | argument='report_id argument', |
||
| 7156 | ) |
||
| 7157 | |||
| 7158 | cmd = XmlCommand("get_reports") |
||
| 7159 | cmd.set_attribute("report_id", report_id) |
||
| 7160 | cmd.set_attribute("alert_id", alert_id) |
||
| 7161 | |||
| 7162 | if filter: |
||
| 7163 | cmd.set_attribute("filter", filter) |
||
| 7164 | |||
| 7165 | if filter_id: |
||
| 7166 | cmd.set_attribute("filt_id", filter_id) |
||
| 7167 | |||
| 7168 | if report_format_id: |
||
| 7169 | if isinstance(report_format_id, ReportFormatType): |
||
| 7170 | report_format_id = report_format_id.value |
||
| 7171 | |||
| 7172 | cmd.set_attribute("format_id", report_format_id) |
||
| 7173 | |||
| 7174 | if delta_report_id: |
||
| 7175 | cmd.set_attribute("delta_report_id", delta_report_id) |
||
| 7176 | |||
| 7177 | return self._send_xml_command(cmd) |
||
| 7178 | |||
| 7179 | View Code Duplication | def verify_report_format( |
|
| 7180 | self, report_format_id: Union[str, ReportFormatType] |
||
| 7181 | ) -> Any: |
||
| 7182 | """Verify an existing report format |
||
| 7183 | |||
| 7184 | Verifies the trust level of an existing report format. It will be |
||
| 7185 | checked whether the signature of the report format currently matches the |
||
| 7186 | report format. This includes the script and files used to generate |
||
| 7187 | reports of this format. It is *not* verified if the report format works |
||
| 7188 | as expected by the user. |
||
| 7189 | |||
| 7190 | Arguments: |
||
| 7191 | report_format_id: UUID of the report format to be verified |
||
| 7192 | or ReportFormatType (enum) |
||
| 7193 | |||
| 7194 | Returns: |
||
| 7195 | The response. See :py:meth:`send_command` for details. |
||
| 7196 | """ |
||
| 7197 | if not report_format_id: |
||
| 7198 | raise RequiredArgument( |
||
| 7199 | function=self.verify_report_format.__name__, |
||
| 7200 | argument='report_format_id', |
||
| 7201 | ) |
||
| 7202 | |||
| 7203 | cmd = XmlCommand("verify_report_format") |
||
| 7204 | |||
| 7205 | if isinstance(report_format_id, ReportFormatType): |
||
| 7206 | report_format_id = report_format_id.value |
||
| 7207 | |||
| 7208 | cmd.set_attribute("report_format_id", report_format_id) |
||
| 7209 | |||
| 7210 | return self._send_xml_command(cmd) |
||
| 7211 | |||
| 7212 | def verify_scanner(self, scanner_id: str) -> Any: |
||
| 7213 | """Verify an existing scanner |
||
| 7214 | |||
| 7215 | Verifies if it is possible to connect to an existing scanner. It is |
||
| 7216 | *not* verified if the scanner works as expected by the user. |
||
| 7217 | |||
| 7218 | Arguments: |
||
| 7219 | scanner_id: UUID of the scanner to be verified |
||
| 7220 | |||
| 7221 | Returns: |
||
| 7222 | The response. See :py:meth:`send_command` for details. |
||
| 7223 | """ |
||
| 7224 | if not scanner_id: |
||
| 7225 | raise RequiredArgument( |
||
| 7226 | function=self.verify_scanner.__name__, argument='scanner_id' |
||
| 7227 | ) |
||
| 7228 | |||
| 7229 | cmd = XmlCommand("verify_scanner") |
||
| 7230 | cmd.set_attribute("scanner_id", scanner_id) |
||
| 7231 | |||
| 7232 | return self._send_xml_command(cmd) |
||
| 7233 |