| Total Complexity | 577 |
| Total Lines | 4936 |
| Duplicated Lines | 14.71 % |
| 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 | from numbers import Integral |
||
| 31 | |||
| 32 | from typing import Any, List, Optional, Callable, Union, Tuple |
||
| 33 | from lxml import etree |
||
| 34 | |||
| 35 | from gvm.connections import GvmConnection |
||
| 36 | from gvm.errors import InvalidArgument, InvalidArgumentType, RequiredArgument |
||
| 37 | from gvm.protocols.base import GvmProtocol |
||
| 38 | from gvm.protocols.gmpv208.entities.report_formats import ( |
||
| 39 | ReportFormatType, |
||
| 40 | ) |
||
| 41 | from gvm.utils import ( |
||
| 42 | deprecation, |
||
| 43 | check_command_status, |
||
| 44 | is_list_like, |
||
| 45 | to_base64, |
||
| 46 | to_bool, |
||
| 47 | to_comma_list, |
||
| 48 | add_filter, |
||
| 49 | ) |
||
| 50 | from gvm.xml import XmlCommand |
||
| 51 | |||
| 52 | from . import types |
||
| 53 | from .types import * # pylint: disable=unused-wildcard-import, wildcard-import |
||
| 54 | from .types import _UsageType as UsageType |
||
| 55 | |||
| 56 | _EMPTY_POLICY_ID = '085569ce-73ed-11df-83c3-002264764cea' |
||
| 57 | |||
| 58 | PROTOCOL_VERSION = (20, 8) |
||
| 59 | |||
| 60 | |||
| 61 | logger = logging.getLogger(__name__) |
||
| 62 | |||
| 63 | |||
| 64 | class GmpV208Mixin(GvmProtocol): |
||
| 65 | """Python interface for Greenbone Management Protocol |
||
| 66 | |||
| 67 | This class implements the `Greenbone Management Protocol version 20.08`_ |
||
| 68 | |||
| 69 | Arguments: |
||
| 70 | connection: Connection to use to talk with the gvmd daemon. See |
||
| 71 | :mod:`gvm.connections` for possible connection types. |
||
| 72 | transform: Optional transform `callable`_ to convert response data. |
||
| 73 | After each request the callable gets passed the plain response data |
||
| 74 | which can be used to check the data and/or conversion into different |
||
| 75 | representations like a xml dom. |
||
| 76 | |||
| 77 | See :mod:`gvm.transforms` for existing transforms. |
||
| 78 | |||
| 79 | .. _Greenbone Management Protocol version 20.08: |
||
| 80 | https://docs.greenbone.net/API/GMP/gmp-20.08.html |
||
| 81 | .. _callable: |
||
| 82 | https://docs.python.org/3/library/functions.html#callable |
||
| 83 | """ |
||
| 84 | |||
| 85 | types = types |
||
|
|
|||
| 86 | |||
| 87 | def __init__( |
||
| 88 | self, |
||
| 89 | connection: GvmConnection, |
||
| 90 | *, |
||
| 91 | transform: Optional[Callable[[str], Any]] = None, |
||
| 92 | ): |
||
| 93 | super().__init__(connection, transform=transform) |
||
| 94 | |||
| 95 | # Is authenticated on gvmd |
||
| 96 | self._authenticated = False |
||
| 97 | |||
| 98 | def is_authenticated(self) -> bool: |
||
| 99 | """Checks if the user is authenticated |
||
| 100 | |||
| 101 | If the user is authenticated privileged GMP commands like get_tasks |
||
| 102 | may be send to gvmd. |
||
| 103 | |||
| 104 | Returns: |
||
| 105 | bool: True if an authenticated connection to gvmd has been |
||
| 106 | established. |
||
| 107 | """ |
||
| 108 | return self._authenticated |
||
| 109 | |||
| 110 | def authenticate(self, username: str, password: str) -> Any: |
||
| 111 | """Authenticate to gvmd. |
||
| 112 | |||
| 113 | The generated authenticate command will be send to server. |
||
| 114 | Afterwards the response is read, transformed and returned. |
||
| 115 | |||
| 116 | Arguments: |
||
| 117 | username: Username |
||
| 118 | password: Password |
||
| 119 | |||
| 120 | Returns: |
||
| 121 | Transformed response from server. |
||
| 122 | """ |
||
| 123 | cmd = XmlCommand("authenticate") |
||
| 124 | |||
| 125 | if not username: |
||
| 126 | raise RequiredArgument( |
||
| 127 | function=self.authenticate.__name__, argument='username' |
||
| 128 | ) |
||
| 129 | |||
| 130 | if not password: |
||
| 131 | raise RequiredArgument( |
||
| 132 | function=self.authenticate.__name__, argument='password' |
||
| 133 | ) |
||
| 134 | |||
| 135 | credentials = cmd.add_element("credentials") |
||
| 136 | credentials.add_element("username", username) |
||
| 137 | credentials.add_element("password", password) |
||
| 138 | |||
| 139 | self._send(cmd.to_string()) |
||
| 140 | response = self._read() |
||
| 141 | |||
| 142 | if check_command_status(response): |
||
| 143 | self._authenticated = True |
||
| 144 | |||
| 145 | return self._transform(response) |
||
| 146 | |||
| 147 | def create_audit( |
||
| 148 | self, |
||
| 149 | name: str, |
||
| 150 | policy_id: str, |
||
| 151 | target_id: str, |
||
| 152 | scanner_id: str, |
||
| 153 | *, |
||
| 154 | alterable: Optional[bool] = None, |
||
| 155 | hosts_ordering: Optional[HostsOrdering] = None, |
||
| 156 | schedule_id: Optional[str] = None, |
||
| 157 | alert_ids: Optional[List[str]] = None, |
||
| 158 | comment: Optional[str] = None, |
||
| 159 | schedule_periods: Optional[int] = None, |
||
| 160 | observers: Optional[List[str]] = None, |
||
| 161 | preferences: Optional[dict] = None, |
||
| 162 | ) -> Any: |
||
| 163 | """Create a new audit task |
||
| 164 | |||
| 165 | Arguments: |
||
| 166 | name: Name of the new audit |
||
| 167 | policy_id: UUID of policy to use by the audit |
||
| 168 | target_id: UUID of target to be scanned |
||
| 169 | scanner_id: UUID of scanner to use for scanning the target |
||
| 170 | comment: Comment for the audit |
||
| 171 | alterable: Whether the task should be alterable |
||
| 172 | alert_ids: List of UUIDs for alerts to be applied to the audit |
||
| 173 | hosts_ordering: The order hosts are scanned in |
||
| 174 | schedule_id: UUID of a schedule when the audit should be run. |
||
| 175 | schedule_periods: A limit to the number of times the audit will be |
||
| 176 | scheduled, or 0 for no limit |
||
| 177 | observers: List of names or ids of users which should be allowed to |
||
| 178 | observe this audit |
||
| 179 | preferences: Name/Value pairs of scanner preferences. |
||
| 180 | |||
| 181 | Returns: |
||
| 182 | The response. See :py:meth:`send_command` for details. |
||
| 183 | """ |
||
| 184 | |||
| 185 | return self.__create_task( |
||
| 186 | name=name, |
||
| 187 | config_id=policy_id, |
||
| 188 | target_id=target_id, |
||
| 189 | scanner_id=scanner_id, |
||
| 190 | usage_type=UsageType.AUDIT, |
||
| 191 | function=self.create_audit.__name__, |
||
| 192 | alterable=alterable, |
||
| 193 | hosts_ordering=hosts_ordering, |
||
| 194 | schedule_id=schedule_id, |
||
| 195 | alert_ids=alert_ids, |
||
| 196 | comment=comment, |
||
| 197 | schedule_periods=schedule_periods, |
||
| 198 | observers=observers, |
||
| 199 | preferences=preferences, |
||
| 200 | ) |
||
| 201 | |||
| 202 | def create_config( |
||
| 203 | self, config_id: str, name: str, *, comment: Optional[str] = None |
||
| 204 | ) -> Any: |
||
| 205 | """Create a new scan config |
||
| 206 | |||
| 207 | Arguments: |
||
| 208 | config_id: UUID of the existing scan config |
||
| 209 | name: Name of the new scan config |
||
| 210 | comment: A comment on the config |
||
| 211 | |||
| 212 | Returns: |
||
| 213 | The response. See :py:meth:`send_command` for details. |
||
| 214 | """ |
||
| 215 | return self.__create_config( |
||
| 216 | config_id=config_id, |
||
| 217 | name=name, |
||
| 218 | comment=comment, |
||
| 219 | usage_type=UsageType.SCAN, |
||
| 220 | function=self.create_config.__name__, |
||
| 221 | ) |
||
| 222 | |||
| 223 | def create_config_from_osp_scanner( |
||
| 224 | self, scanner_id: str, name: str, *, comment: Optional[str] = None |
||
| 225 | ) -> Any: |
||
| 226 | """Create a new scan config from an ospd scanner. |
||
| 227 | |||
| 228 | Create config by retrieving the expected preferences from the given |
||
| 229 | scanner via OSP. |
||
| 230 | |||
| 231 | Arguments: |
||
| 232 | scanner_id: UUID of an OSP scanner to get config data from |
||
| 233 | name: Name of the new scan config |
||
| 234 | comment: A comment on the config |
||
| 235 | |||
| 236 | Returns: |
||
| 237 | The response. See :py:meth:`send_command` for details. |
||
| 238 | """ |
||
| 239 | return self.__create_config_from_osp_scanner( |
||
| 240 | scanner_id=scanner_id, |
||
| 241 | name=name, |
||
| 242 | comment=comment, |
||
| 243 | usage_type=UsageType.SCAN, |
||
| 244 | function=self.create_config.__name__, |
||
| 245 | ) |
||
| 246 | |||
| 247 | def create_permission( |
||
| 248 | self, |
||
| 249 | name: str, |
||
| 250 | subject_id: str, |
||
| 251 | subject_type: PermissionSubjectType, |
||
| 252 | *, |
||
| 253 | resource_id: Optional[str] = None, |
||
| 254 | resource_type: Optional[EntityType] = None, |
||
| 255 | comment: Optional[str] = None, |
||
| 256 | ) -> Any: |
||
| 257 | """Create a new permission |
||
| 258 | |||
| 259 | Arguments: |
||
| 260 | name: Name of the new permission |
||
| 261 | subject_id: UUID of subject to whom the permission is granted |
||
| 262 | subject_type: Type of the subject user, group or role |
||
| 263 | comment: Comment for the permission |
||
| 264 | resource_id: UUID of entity to which the permission applies |
||
| 265 | resource_type: Type of the resource. For Super permissions user, |
||
| 266 | group or role |
||
| 267 | |||
| 268 | Returns: |
||
| 269 | The response. See :py:meth:`send_command` for details. |
||
| 270 | """ |
||
| 271 | if not name: |
||
| 272 | raise RequiredArgument( |
||
| 273 | function=self.create_permission.__name__, argument='name' |
||
| 274 | ) |
||
| 275 | |||
| 276 | if not subject_id: |
||
| 277 | raise RequiredArgument( |
||
| 278 | function=self.create_permission.__name__, argument='subject_id' |
||
| 279 | ) |
||
| 280 | |||
| 281 | if not isinstance(subject_type, PermissionSubjectType): |
||
| 282 | raise InvalidArgumentType( |
||
| 283 | function=self.create_permission.__name__, |
||
| 284 | argument='subject_type', |
||
| 285 | arg_type=PermissionSubjectType.__name__, |
||
| 286 | ) |
||
| 287 | |||
| 288 | cmd = XmlCommand("create_permission") |
||
| 289 | cmd.add_element("name", name) |
||
| 290 | |||
| 291 | _xmlsubject = cmd.add_element("subject", attrs={"id": subject_id}) |
||
| 292 | _xmlsubject.add_element("type", subject_type.value) |
||
| 293 | |||
| 294 | if comment: |
||
| 295 | cmd.add_element("comment", comment) |
||
| 296 | |||
| 297 | View Code Duplication | if resource_id or resource_type: |
|
| 298 | if not resource_id: |
||
| 299 | raise RequiredArgument( |
||
| 300 | function=self.create_permission.__name__, |
||
| 301 | argument='resource_id', |
||
| 302 | ) |
||
| 303 | |||
| 304 | if not resource_type: |
||
| 305 | raise RequiredArgument( |
||
| 306 | function=self.create_permission.__name__, |
||
| 307 | argument='resource_type', |
||
| 308 | ) |
||
| 309 | |||
| 310 | if not isinstance(resource_type, self.types.EntityType): |
||
| 311 | raise InvalidArgumentType( |
||
| 312 | function=self.create_permission.__name__, |
||
| 313 | argument='resource_type', |
||
| 314 | arg_type=self.types.EntityType.__name__, |
||
| 315 | ) |
||
| 316 | |||
| 317 | _xmlresource = cmd.add_element( |
||
| 318 | "resource", attrs={"id": resource_id} |
||
| 319 | ) |
||
| 320 | |||
| 321 | _actual_resource_type = resource_type |
||
| 322 | if resource_type.value == EntityType.AUDIT.value: |
||
| 323 | _actual_resource_type = EntityType.TASK |
||
| 324 | elif resource_type.value == EntityType.POLICY.value: |
||
| 325 | _actual_resource_type = EntityType.SCAN_CONFIG |
||
| 326 | |||
| 327 | _xmlresource.add_element("type", _actual_resource_type.value) |
||
| 328 | |||
| 329 | return self._send_xml_command(cmd) |
||
| 330 | |||
| 331 | def create_policy( |
||
| 332 | self, name: str, *, policy_id: str = None, comment: Optional[str] = None |
||
| 333 | ) -> Any: |
||
| 334 | """Create a new policy config |
||
| 335 | |||
| 336 | Arguments: |
||
| 337 | name: Name of the new policy |
||
| 338 | policy_id: UUID of an existing policy as base. By default the empty |
||
| 339 | policy is used. |
||
| 340 | comment: A comment on the policy |
||
| 341 | |||
| 342 | Returns: |
||
| 343 | The response. See :py:meth:`send_command` for details. |
||
| 344 | """ |
||
| 345 | if policy_id is None: |
||
| 346 | policy_id = _EMPTY_POLICY_ID |
||
| 347 | return self.__create_config( |
||
| 348 | config_id=policy_id, |
||
| 349 | name=name, |
||
| 350 | comment=comment, |
||
| 351 | usage_type=UsageType.POLICY, |
||
| 352 | function=self.create_policy.__name__, |
||
| 353 | ) |
||
| 354 | |||
| 355 | def create_tag( |
||
| 356 | self, |
||
| 357 | name: str, |
||
| 358 | resource_type: EntityType, |
||
| 359 | *, |
||
| 360 | resource_filter: Optional[str] = None, |
||
| 361 | resource_ids: Optional[List[str]] = None, |
||
| 362 | value: Optional[str] = None, |
||
| 363 | comment: Optional[str] = None, |
||
| 364 | active: Optional[bool] = None, |
||
| 365 | ) -> Any: |
||
| 366 | """Create a tag. |
||
| 367 | |||
| 368 | Arguments: |
||
| 369 | name: Name of the tag. A full tag name consisting of namespace and |
||
| 370 | predicate e.g. `foo:bar`. |
||
| 371 | resource_type: Entity type the tag is to be attached to. |
||
| 372 | resource_filter: Filter term to select resources the tag is to be |
||
| 373 | attached to. Only one of resource_filter or resource_ids can be |
||
| 374 | provided. |
||
| 375 | resource_ids: IDs of the resources the tag is to be attached to. |
||
| 376 | Only one of resource_filter or resource_ids can be provided. |
||
| 377 | value: Value associated with the tag. |
||
| 378 | comment: Comment for the tag. |
||
| 379 | active: Whether the tag should be active. |
||
| 380 | |||
| 381 | Returns: |
||
| 382 | The response. See :py:meth:`send_command` for details. |
||
| 383 | """ |
||
| 384 | if not name: |
||
| 385 | raise RequiredArgument( |
||
| 386 | function=self.create_tag.__name__, argument='name' |
||
| 387 | ) |
||
| 388 | |||
| 389 | if resource_filter and resource_ids: |
||
| 390 | raise InvalidArgument( |
||
| 391 | "create_tag accepts either resource_filter or resource_ids " |
||
| 392 | "argument", |
||
| 393 | function=self.create_tag.__name__, |
||
| 394 | ) |
||
| 395 | |||
| 396 | if not resource_type: |
||
| 397 | raise RequiredArgument( |
||
| 398 | function=self.create_tag.__name__, argument='resource_type' |
||
| 399 | ) |
||
| 400 | |||
| 401 | if not isinstance(resource_type, self.types.EntityType): |
||
| 402 | raise InvalidArgumentType( |
||
| 403 | function=self.create_tag.__name__, |
||
| 404 | argument='resource_type', |
||
| 405 | arg_type=EntityType.__name__, |
||
| 406 | ) |
||
| 407 | |||
| 408 | cmd = XmlCommand('create_tag') |
||
| 409 | cmd.add_element('name', name) |
||
| 410 | |||
| 411 | _xmlresources = cmd.add_element("resources") |
||
| 412 | if resource_filter is not None: |
||
| 413 | _xmlresources.set_attribute("filter", resource_filter) |
||
| 414 | |||
| 415 | for resource_id in resource_ids or []: |
||
| 416 | _xmlresources.add_element( |
||
| 417 | "resource", attrs={"id": str(resource_id)} |
||
| 418 | ) |
||
| 419 | |||
| 420 | _actual_resource_type = resource_type |
||
| 421 | if resource_type.value == EntityType.AUDIT.value: |
||
| 422 | _actual_resource_type = EntityType.TASK |
||
| 423 | elif resource_type.value == EntityType.POLICY.value: |
||
| 424 | _actual_resource_type = EntityType.SCAN_CONFIG |
||
| 425 | _xmlresources.add_element("type", _actual_resource_type.value) |
||
| 426 | |||
| 427 | if comment: |
||
| 428 | cmd.add_element("comment", comment) |
||
| 429 | |||
| 430 | if value: |
||
| 431 | cmd.add_element("value", value) |
||
| 432 | |||
| 433 | if active is not None: |
||
| 434 | if active: |
||
| 435 | cmd.add_element("active", "1") |
||
| 436 | else: |
||
| 437 | cmd.add_element("active", "0") |
||
| 438 | |||
| 439 | return self._send_xml_command(cmd) |
||
| 440 | |||
| 441 | View Code Duplication | def create_tls_certificate( |
|
| 442 | self, |
||
| 443 | name: str, |
||
| 444 | certificate: str, |
||
| 445 | *, |
||
| 446 | comment: Optional[str] = None, |
||
| 447 | trust: Optional[bool] = None, |
||
| 448 | ) -> Any: |
||
| 449 | """Create a new TLS certificate |
||
| 450 | |||
| 451 | Arguments: |
||
| 452 | name: Name of the TLS certificate, defaulting to the MD5 |
||
| 453 | fingerprint. |
||
| 454 | certificate: The Base64 encoded certificate data (x.509 DER or PEM). |
||
| 455 | comment: Comment for the TLS certificate. |
||
| 456 | trust: Whether the certificate is trusted. |
||
| 457 | |||
| 458 | Returns: |
||
| 459 | The response. See :py:meth:`send_command` for details. |
||
| 460 | """ |
||
| 461 | if not name: |
||
| 462 | raise RequiredArgument( |
||
| 463 | function=self.create_tls_certificate.__name__, argument='name' |
||
| 464 | ) |
||
| 465 | if not certificate: |
||
| 466 | raise RequiredArgument( |
||
| 467 | function=self.create_tls_certificate.__name__, |
||
| 468 | argument='certificate', |
||
| 469 | ) |
||
| 470 | |||
| 471 | cmd = XmlCommand("create_tls_certificate") |
||
| 472 | |||
| 473 | if comment: |
||
| 474 | cmd.add_element("comment", comment) |
||
| 475 | |||
| 476 | cmd.add_element("name", name) |
||
| 477 | cmd.add_element("certificate", certificate) |
||
| 478 | |||
| 479 | if trust: |
||
| 480 | cmd.add_element("trust", to_bool(trust)) |
||
| 481 | |||
| 482 | return self._send_xml_command(cmd) |
||
| 483 | |||
| 484 | def get_aggregates( |
||
| 485 | self, |
||
| 486 | resource_type: EntityType, |
||
| 487 | *, |
||
| 488 | filter: Optional[str] = None, |
||
| 489 | filter_id: Optional[str] = None, |
||
| 490 | sort_criteria: Optional[list] = None, |
||
| 491 | data_columns: Optional[list] = None, |
||
| 492 | group_column: Optional[str] = None, |
||
| 493 | subgroup_column: Optional[str] = None, |
||
| 494 | text_columns: Optional[list] = None, |
||
| 495 | first_group: Optional[int] = None, |
||
| 496 | max_groups: Optional[int] = None, |
||
| 497 | mode: Optional[int] = None, |
||
| 498 | **kwargs, |
||
| 499 | ) -> Any: |
||
| 500 | """Request aggregated information on a resource / entity type |
||
| 501 | |||
| 502 | Additional arguments can be set via the kwargs parameter for backward |
||
| 503 | compatibility with older versions of python-gvm, but are not validated. |
||
| 504 | |||
| 505 | Arguments: |
||
| 506 | resource_type: The entity type to gather data from |
||
| 507 | filter: Filter term to use for the query |
||
| 508 | filter_id: UUID of an existing filter to use for the query |
||
| 509 | sort_criteria: List of sort criteria (dicts that can contain |
||
| 510 | a field, stat and order) |
||
| 511 | data_columns: List of fields to aggregate data from |
||
| 512 | group_column: The field to group the entities by |
||
| 513 | subgroup_column: The field to further group the entities |
||
| 514 | inside groups by |
||
| 515 | text_columns: List of simple text columns which no statistics |
||
| 516 | are calculated for |
||
| 517 | first_group: The index of the first aggregate group to return |
||
| 518 | max_groups: The maximum number of aggregate groups to return, |
||
| 519 | -1 for all |
||
| 520 | mode: Special mode for aggregation |
||
| 521 | |||
| 522 | Returns: |
||
| 523 | The response. See :py:meth:`send_command` for details. |
||
| 524 | """ |
||
| 525 | if not resource_type: |
||
| 526 | raise RequiredArgument( |
||
| 527 | function=self.get_aggregates.__name__, argument='resource_type' |
||
| 528 | ) |
||
| 529 | |||
| 530 | if not isinstance(resource_type, self.types.EntityType): |
||
| 531 | raise InvalidArgumentType( |
||
| 532 | function=self.get_aggregates.__name__, |
||
| 533 | argument='resource_type', |
||
| 534 | arg_type=self.types.EntityType.__name__, |
||
| 535 | ) |
||
| 536 | |||
| 537 | cmd = XmlCommand('get_aggregates') |
||
| 538 | |||
| 539 | _actual_resource_type = resource_type |
||
| 540 | if resource_type.value == EntityType.AUDIT.value: |
||
| 541 | _actual_resource_type = EntityType.TASK |
||
| 542 | cmd.set_attribute('usage_type', 'audit') |
||
| 543 | elif resource_type.value == EntityType.POLICY.value: |
||
| 544 | _actual_resource_type = EntityType.SCAN_CONFIG |
||
| 545 | cmd.set_attribute('usage_type', 'policy') |
||
| 546 | elif resource_type.value == EntityType.SCAN_CONFIG.value: |
||
| 547 | cmd.set_attribute('usage_type', 'scan') |
||
| 548 | elif resource_type.value == EntityType.TASK.value: |
||
| 549 | cmd.set_attribute('usage_type', 'scan') |
||
| 550 | cmd.set_attribute('type', _actual_resource_type.value) |
||
| 551 | |||
| 552 | add_filter(cmd, filter, filter_id) |
||
| 553 | |||
| 554 | if first_group is not None: |
||
| 555 | if not isinstance(first_group, int): |
||
| 556 | raise InvalidArgumentType( |
||
| 557 | function=self.get_aggregates.__name__, |
||
| 558 | argument='first_group', |
||
| 559 | arg_type=int.__name__, |
||
| 560 | ) |
||
| 561 | cmd.set_attribute('first_group', str(first_group)) |
||
| 562 | |||
| 563 | if max_groups is not None: |
||
| 564 | if not isinstance(max_groups, int): |
||
| 565 | raise InvalidArgumentType( |
||
| 566 | function=self.get_aggregates.__name__, |
||
| 567 | argument='max_groups', |
||
| 568 | arg_type=int.__name__, |
||
| 569 | ) |
||
| 570 | cmd.set_attribute('max_groups', str(max_groups)) |
||
| 571 | |||
| 572 | if sort_criteria is not None: |
||
| 573 | if not isinstance(sort_criteria, list): |
||
| 574 | raise InvalidArgumentType( |
||
| 575 | function=self.get_aggregates.__name__, |
||
| 576 | argument='sort_criteria', |
||
| 577 | arg_type=list.__name__, |
||
| 578 | ) |
||
| 579 | for sort in sort_criteria: |
||
| 580 | if not isinstance(sort, dict): |
||
| 581 | raise InvalidArgumentType( |
||
| 582 | function=self.get_aggregates.__name__, |
||
| 583 | argument='sort_criteria', |
||
| 584 | ) |
||
| 585 | |||
| 586 | sort_elem = cmd.add_element('sort') |
||
| 587 | if sort.get('field'): |
||
| 588 | sort_elem.set_attribute('field', sort.get('field')) |
||
| 589 | |||
| 590 | if sort.get('stat'): |
||
| 591 | if isinstance(sort['stat'], AggregateStatistic): |
||
| 592 | sort_elem.set_attribute('stat', sort['stat'].value) |
||
| 593 | else: |
||
| 594 | stat = get_aggregate_statistic_from_string(sort['stat']) |
||
| 595 | sort_elem.set_attribute('stat', stat.value) |
||
| 596 | |||
| 597 | if sort.get('order'): |
||
| 598 | if isinstance(sort['order'], SortOrder): |
||
| 599 | sort_elem.set_attribute('order', sort['order'].value) |
||
| 600 | else: |
||
| 601 | so = get_sort_order_from_string(sort['order']) |
||
| 602 | sort_elem.set_attribute('order', so.value) |
||
| 603 | |||
| 604 | if data_columns is not None: |
||
| 605 | if not isinstance(data_columns, list): |
||
| 606 | raise InvalidArgumentType( |
||
| 607 | function=self.get_aggregates.__name__, |
||
| 608 | argument='data_columns', |
||
| 609 | arg_type=list.__name__, |
||
| 610 | ) |
||
| 611 | for column in data_columns: |
||
| 612 | cmd.add_element('data_column', column) |
||
| 613 | |||
| 614 | if group_column is not None: |
||
| 615 | cmd.set_attribute('group_column', group_column) |
||
| 616 | |||
| 617 | if subgroup_column is not None: |
||
| 618 | if not group_column: |
||
| 619 | raise RequiredArgument( |
||
| 620 | '{} requires a group_column argument' |
||
| 621 | ' if subgroup_column is given'.format( |
||
| 622 | self.get_aggregates.__name__ |
||
| 623 | ), |
||
| 624 | function=self.get_aggregates.__name__, |
||
| 625 | argument='subgroup_column', |
||
| 626 | ) |
||
| 627 | cmd.set_attribute('subgroup_column', subgroup_column) |
||
| 628 | |||
| 629 | if text_columns is not None: |
||
| 630 | if not isinstance(text_columns, list): |
||
| 631 | raise InvalidArgumentType( |
||
| 632 | function=self.get_aggregates.__name__, |
||
| 633 | argument='text_columns', |
||
| 634 | arg_type=list.__name__, |
||
| 635 | ) |
||
| 636 | for column in text_columns: |
||
| 637 | cmd.add_element('text_column', column) |
||
| 638 | |||
| 639 | if mode is not None: |
||
| 640 | cmd.set_attribute('mode', mode) |
||
| 641 | |||
| 642 | # Add additional keyword args as attributes for backward compatibility. |
||
| 643 | cmd.set_attributes(kwargs) |
||
| 644 | |||
| 645 | return self._send_xml_command(cmd) |
||
| 646 | |||
| 647 | View Code Duplication | def get_tls_certificates( |
|
| 648 | self, |
||
| 649 | *, |
||
| 650 | filter: Optional[str] = None, |
||
| 651 | filter_id: Optional[str] = None, |
||
| 652 | include_certificate_data: Optional[bool] = None, |
||
| 653 | details: Optional[bool] = None, |
||
| 654 | ) -> Any: |
||
| 655 | """Request a list of TLS certificates |
||
| 656 | |||
| 657 | Arguments: |
||
| 658 | filter: Filter term to use for the query |
||
| 659 | filter_id: UUID of an existing filter to use for the query |
||
| 660 | include_certificate_data: Whether to include the certificate data in |
||
| 661 | the response |
||
| 662 | |||
| 663 | Returns: |
||
| 664 | The response. See :py:meth:`send_command` for details. |
||
| 665 | """ |
||
| 666 | |||
| 667 | cmd = XmlCommand("get_tls_certificates") |
||
| 668 | |||
| 669 | add_filter(cmd, filter, filter_id) |
||
| 670 | |||
| 671 | if details is not None: |
||
| 672 | cmd.set_attribute("details", to_bool(details)) |
||
| 673 | |||
| 674 | if include_certificate_data is not None: |
||
| 675 | cmd.set_attribute( |
||
| 676 | "include_certificate_data", to_bool(include_certificate_data) |
||
| 677 | ) |
||
| 678 | |||
| 679 | return self._send_xml_command(cmd) |
||
| 680 | |||
| 681 | def get_tls_certificate(self, tls_certificate_id: str) -> Any: |
||
| 682 | """Request a single TLS certificate |
||
| 683 | |||
| 684 | Arguments: |
||
| 685 | tls_certificate_id: UUID of an existing TLS certificate |
||
| 686 | |||
| 687 | Returns: |
||
| 688 | The response. See :py:meth:`send_command` for details. |
||
| 689 | """ |
||
| 690 | cmd = XmlCommand("get_tls_certificates") |
||
| 691 | |||
| 692 | if not tls_certificate_id: |
||
| 693 | raise RequiredArgument( |
||
| 694 | function=self.get_tls_certificate.__name__, |
||
| 695 | argument='tls_certificate_id', |
||
| 696 | ) |
||
| 697 | |||
| 698 | cmd.set_attribute("tls_certificate_id", tls_certificate_id) |
||
| 699 | |||
| 700 | # for single tls certificate always request cert data |
||
| 701 | cmd.set_attribute("include_certificate_data", "1") |
||
| 702 | |||
| 703 | # for single entity always request all details |
||
| 704 | cmd.set_attribute("details", "1") |
||
| 705 | |||
| 706 | return self._send_xml_command(cmd) |
||
| 707 | |||
| 708 | def modify_audit( |
||
| 709 | self, |
||
| 710 | audit_id: str, |
||
| 711 | *, |
||
| 712 | name: Optional[str] = None, |
||
| 713 | policy_id: Optional[str] = None, |
||
| 714 | target_id: Optional[str] = None, |
||
| 715 | scanner_id: Optional[str] = None, |
||
| 716 | alterable: Optional[bool] = None, |
||
| 717 | hosts_ordering: Optional[HostsOrdering] = None, |
||
| 718 | schedule_id: Optional[str] = None, |
||
| 719 | schedule_periods: Optional[int] = None, |
||
| 720 | comment: Optional[str] = None, |
||
| 721 | alert_ids: Optional[List[str]] = None, |
||
| 722 | observers: Optional[List[str]] = None, |
||
| 723 | preferences: Optional[dict] = None, |
||
| 724 | ) -> Any: |
||
| 725 | """Modifies an existing task. |
||
| 726 | |||
| 727 | Arguments: |
||
| 728 | audit_id: UUID of audit to modify. |
||
| 729 | name: The name of the audit. |
||
| 730 | policy_id: UUID of policy to use by the audit |
||
| 731 | target_id: UUID of target to be scanned |
||
| 732 | scanner_id: UUID of scanner to use for scanning the target |
||
| 733 | comment: The comment on the audit. |
||
| 734 | alert_ids: List of UUIDs for alerts to be applied to the audit |
||
| 735 | hosts_ordering: The order hosts are scanned in |
||
| 736 | schedule_id: UUID of a schedule when the audit should be run. |
||
| 737 | schedule_periods: A limit to the number of times the audit will be |
||
| 738 | scheduled, or 0 for no limit. |
||
| 739 | observers: List of names or ids of users which should be allowed to |
||
| 740 | observe this audit |
||
| 741 | preferences: Name/Value pairs of scanner preferences. |
||
| 742 | |||
| 743 | Returns: |
||
| 744 | The response. See :py:meth:`send_command` for details. |
||
| 745 | """ |
||
| 746 | self.modify_task( |
||
| 747 | task_id=audit_id, |
||
| 748 | name=name, |
||
| 749 | config_id=policy_id, |
||
| 750 | target_id=target_id, |
||
| 751 | scanner_id=scanner_id, |
||
| 752 | alterable=alterable, |
||
| 753 | hosts_ordering=hosts_ordering, |
||
| 754 | schedule_id=schedule_id, |
||
| 755 | schedule_periods=schedule_periods, |
||
| 756 | comment=comment, |
||
| 757 | alert_ids=alert_ids, |
||
| 758 | observers=observers, |
||
| 759 | preferences=preferences, |
||
| 760 | ) |
||
| 761 | |||
| 762 | def modify_permission( |
||
| 763 | self, |
||
| 764 | permission_id: str, |
||
| 765 | *, |
||
| 766 | comment: Optional[str] = None, |
||
| 767 | name: Optional[str] = None, |
||
| 768 | resource_id: Optional[str] = None, |
||
| 769 | resource_type: Optional[EntityType] = None, |
||
| 770 | subject_id: Optional[str] = None, |
||
| 771 | subject_type: Optional[PermissionSubjectType] = None, |
||
| 772 | ) -> Any: |
||
| 773 | """Modifies an existing permission. |
||
| 774 | |||
| 775 | Arguments: |
||
| 776 | permission_id: UUID of permission to be modified. |
||
| 777 | comment: The comment on the permission. |
||
| 778 | name: Permission name, currently the name of a command. |
||
| 779 | subject_id: UUID of subject to whom the permission is granted |
||
| 780 | subject_type: Type of the subject user, group or role |
||
| 781 | resource_id: UUID of entity to which the permission applies |
||
| 782 | resource_type: Type of the resource. For Super permissions user, |
||
| 783 | group or role |
||
| 784 | |||
| 785 | Returns: |
||
| 786 | The response. See :py:meth:`send_command` for details. |
||
| 787 | """ |
||
| 788 | if not permission_id: |
||
| 789 | raise RequiredArgument( |
||
| 790 | function=self.modify_permission.__name__, |
||
| 791 | argument='permission_id', |
||
| 792 | ) |
||
| 793 | |||
| 794 | cmd = XmlCommand("modify_permission") |
||
| 795 | cmd.set_attribute("permission_id", permission_id) |
||
| 796 | |||
| 797 | if comment: |
||
| 798 | cmd.add_element("comment", comment) |
||
| 799 | |||
| 800 | if name: |
||
| 801 | cmd.add_element("name", name) |
||
| 802 | |||
| 803 | View Code Duplication | if resource_id or resource_type: |
|
| 804 | if not resource_id: |
||
| 805 | raise RequiredArgument( |
||
| 806 | function=self.modify_permission.__name__, |
||
| 807 | argument='resource_id', |
||
| 808 | ) |
||
| 809 | |||
| 810 | if not resource_type: |
||
| 811 | raise RequiredArgument( |
||
| 812 | function=self.modify_permission.__name__, |
||
| 813 | argument='resource_type', |
||
| 814 | ) |
||
| 815 | |||
| 816 | if not isinstance(resource_type, self.types.EntityType): |
||
| 817 | raise InvalidArgumentType( |
||
| 818 | function=self.modify_permission.__name__, |
||
| 819 | argument='resource_type', |
||
| 820 | arg_type=self.types.EntityType.__name__, |
||
| 821 | ) |
||
| 822 | |||
| 823 | _xmlresource = cmd.add_element( |
||
| 824 | "resource", attrs={"id": resource_id} |
||
| 825 | ) |
||
| 826 | _actual_resource_type = resource_type |
||
| 827 | if resource_type.value == EntityType.AUDIT.value: |
||
| 828 | _actual_resource_type = EntityType.TASK |
||
| 829 | elif resource_type.value == EntityType.POLICY.value: |
||
| 830 | _actual_resource_type = EntityType.SCAN_CONFIG |
||
| 831 | _xmlresource.add_element("type", _actual_resource_type.value) |
||
| 832 | |||
| 833 | if subject_id or subject_type: |
||
| 834 | if not subject_id: |
||
| 835 | raise RequiredArgument( |
||
| 836 | function=self.modify_permission.__name__, |
||
| 837 | argument='subject_id', |
||
| 838 | ) |
||
| 839 | |||
| 840 | if not isinstance(subject_type, PermissionSubjectType): |
||
| 841 | raise InvalidArgumentType( |
||
| 842 | function=self.modify_permission.__name__, |
||
| 843 | argument='subject_type', |
||
| 844 | arg_type=PermissionSubjectType.__name__, |
||
| 845 | ) |
||
| 846 | |||
| 847 | _xmlsubject = cmd.add_element("subject", attrs={"id": subject_id}) |
||
| 848 | _xmlsubject.add_element("type", subject_type.value) |
||
| 849 | |||
| 850 | return self._send_xml_command(cmd) |
||
| 851 | |||
| 852 | def modify_policy_set_nvt_preference( |
||
| 853 | self, |
||
| 854 | policy_id: str, |
||
| 855 | name: str, |
||
| 856 | nvt_oid: str, |
||
| 857 | *, |
||
| 858 | value: Optional[str] = None, |
||
| 859 | ) -> Any: |
||
| 860 | """Modifies the nvt preferences of an existing policy. |
||
| 861 | |||
| 862 | Arguments: |
||
| 863 | policy_id: UUID of policy to modify. |
||
| 864 | name: Name for preference to change. |
||
| 865 | nvt_oid: OID of the NVT associated with preference to modify |
||
| 866 | value: New value for the preference. None to delete the preference |
||
| 867 | and to use the default instead. |
||
| 868 | """ |
||
| 869 | self.modify_config_set_nvt_preference( |
||
| 870 | config_id=policy_id, name=name, nvt_oid=nvt_oid, value=value |
||
| 871 | ) |
||
| 872 | |||
| 873 | def modify_policy_set_name(self, policy_id: str, name: str) -> Any: |
||
| 874 | """Modifies the name of an existing policy |
||
| 875 | |||
| 876 | Arguments: |
||
| 877 | config_id: UUID of policy to modify. |
||
| 878 | name: New name for the config. |
||
| 879 | """ |
||
| 880 | self.modify_config_set_name(config_id=policy_id, name=name) |
||
| 881 | |||
| 882 | def modify_policy_set_comment( |
||
| 883 | self, policy_id: str, comment: Optional[str] = "" |
||
| 884 | ) -> Any: |
||
| 885 | """Modifies the comment of an existing policy |
||
| 886 | |||
| 887 | Arguments: |
||
| 888 | policy_id: UUID of policy to modify. |
||
| 889 | comment: Comment to set on a config. Default: '' |
||
| 890 | """ |
||
| 891 | self.modify_config_set_comment(config_id=policy_id, comment=comment) |
||
| 892 | |||
| 893 | def modify_policy_set_scanner_preference( |
||
| 894 | self, policy_id: str, name: str, *, value: Optional[str] = None |
||
| 895 | ) -> Any: |
||
| 896 | """Modifies the scanner preferences of an existing policy |
||
| 897 | |||
| 898 | Arguments: |
||
| 899 | policy_id: UUID of policy to modify. |
||
| 900 | name: Name of the scanner preference to change |
||
| 901 | value: New value for the preference. None to delete the preference |
||
| 902 | and to use the default instead. |
||
| 903 | |||
| 904 | """ |
||
| 905 | self.modify_config_set_scanner_preference( |
||
| 906 | config_id=policy_id, name=name, value=value |
||
| 907 | ) |
||
| 908 | |||
| 909 | def modify_policy_set_nvt_selection( |
||
| 910 | self, policy_id: str, family: str, nvt_oids: List[str] |
||
| 911 | ) -> Any: |
||
| 912 | """Modifies the selected nvts of an existing policy |
||
| 913 | |||
| 914 | The manager updates the given family in the config to include only the |
||
| 915 | given NVTs. |
||
| 916 | |||
| 917 | Arguments: |
||
| 918 | policy_id: UUID of policy to modify. |
||
| 919 | family: Name of the NVT family to include NVTs from |
||
| 920 | nvt_oids: List of NVTs to select for the family. |
||
| 921 | """ |
||
| 922 | self.modify_config_set_nvt_selection( |
||
| 923 | config_id=policy_id, family=family, nvt_oids=nvt_oids |
||
| 924 | ) |
||
| 925 | |||
| 926 | def modify_policy_set_family_selection( |
||
| 927 | self, |
||
| 928 | policy_id: str, |
||
| 929 | families: List[Tuple[str, bool, bool]], |
||
| 930 | *, |
||
| 931 | auto_add_new_families: Optional[bool] = True, |
||
| 932 | ) -> Any: |
||
| 933 | """ |
||
| 934 | Selected the NVTs of a policy at a family level. |
||
| 935 | |||
| 936 | Arguments: |
||
| 937 | policy_id: UUID of policy to modify. |
||
| 938 | families: A list of tuples with the first entry being the name |
||
| 939 | of the NVT family selected, second entry a boolean indicating |
||
| 940 | whether new NVTs should be added to the family automatically, |
||
| 941 | and third entry a boolean indicating whether all nvts from |
||
| 942 | the family should be included. |
||
| 943 | auto_add_new_families: Whether new families should be added to the |
||
| 944 | policy automatically. Default: True. |
||
| 945 | """ |
||
| 946 | self.modify_config_set_family_selection( |
||
| 947 | config_id=policy_id, |
||
| 948 | families=families, |
||
| 949 | auto_add_new_families=auto_add_new_families, |
||
| 950 | ) |
||
| 951 | |||
| 952 | def modify_tag( |
||
| 953 | self, |
||
| 954 | tag_id: str, |
||
| 955 | *, |
||
| 956 | comment: Optional[str] = None, |
||
| 957 | name: Optional[str] = None, |
||
| 958 | value=None, |
||
| 959 | active=None, |
||
| 960 | resource_action: Optional[str] = None, |
||
| 961 | resource_type: Optional[EntityType] = None, |
||
| 962 | resource_filter: Optional[str] = None, |
||
| 963 | resource_ids: Optional[List[str]] = None, |
||
| 964 | ) -> Any: |
||
| 965 | """Modifies an existing tag. |
||
| 966 | |||
| 967 | Arguments: |
||
| 968 | tag_id: UUID of the tag. |
||
| 969 | comment: Comment to add to the tag. |
||
| 970 | name: Name of the tag. |
||
| 971 | value: Value of the tag. |
||
| 972 | active: Whether the tag is active. |
||
| 973 | resource_action: Whether to add or remove resources instead of |
||
| 974 | overwriting. One of '', 'add', 'set' or 'remove'. |
||
| 975 | resource_type: Type of the resources to which to attach the tag. |
||
| 976 | Required if resource_filter is set. |
||
| 977 | resource_filter: Filter term to select resources the tag is to be |
||
| 978 | attached to. |
||
| 979 | resource_ids: IDs of the resources to which to attach the tag. |
||
| 980 | |||
| 981 | Returns: |
||
| 982 | The response. See :py:meth:`send_command` for details. |
||
| 983 | """ |
||
| 984 | if not tag_id: |
||
| 985 | raise RequiredArgument( |
||
| 986 | function=self.modify_tag.__name__, argument='tag_id' |
||
| 987 | ) |
||
| 988 | |||
| 989 | cmd = XmlCommand("modify_tag") |
||
| 990 | cmd.set_attribute("tag_id", str(tag_id)) |
||
| 991 | |||
| 992 | if comment: |
||
| 993 | cmd.add_element("comment", comment) |
||
| 994 | |||
| 995 | if name: |
||
| 996 | cmd.add_element("name", name) |
||
| 997 | |||
| 998 | if value: |
||
| 999 | cmd.add_element("value", value) |
||
| 1000 | |||
| 1001 | if active is not None: |
||
| 1002 | cmd.add_element("active", to_bool(active)) |
||
| 1003 | |||
| 1004 | if resource_action or resource_filter or resource_ids or resource_type: |
||
| 1005 | if resource_filter and not resource_type: |
||
| 1006 | raise RequiredArgument( |
||
| 1007 | function=self.modify_tag.__name__, argument='resource_type' |
||
| 1008 | ) |
||
| 1009 | |||
| 1010 | _xmlresources = cmd.add_element("resources") |
||
| 1011 | if resource_action is not None: |
||
| 1012 | _xmlresources.set_attribute("action", resource_action) |
||
| 1013 | |||
| 1014 | if resource_filter is not None: |
||
| 1015 | _xmlresources.set_attribute("filter", resource_filter) |
||
| 1016 | |||
| 1017 | for resource_id in resource_ids or []: |
||
| 1018 | _xmlresources.add_element( |
||
| 1019 | "resource", attrs={"id": str(resource_id)} |
||
| 1020 | ) |
||
| 1021 | |||
| 1022 | if resource_type is not None: |
||
| 1023 | if not isinstance(resource_type, self.types.EntityType): |
||
| 1024 | raise InvalidArgumentType( |
||
| 1025 | function=self.modify_tag.__name__, |
||
| 1026 | argument="resource_type", |
||
| 1027 | arg_type=EntityType.__name__, |
||
| 1028 | ) |
||
| 1029 | _actual_resource_type = resource_type |
||
| 1030 | if resource_type.value == EntityType.AUDIT.value: |
||
| 1031 | _actual_resource_type = EntityType.TASK |
||
| 1032 | elif resource_type.value == EntityType.POLICY.value: |
||
| 1033 | _actual_resource_type = EntityType.SCAN_CONFIG |
||
| 1034 | _xmlresources.add_element("type", _actual_resource_type.value) |
||
| 1035 | |||
| 1036 | return self._send_xml_command(cmd) |
||
| 1037 | |||
| 1038 | View Code Duplication | def modify_tls_certificate( |
|
| 1039 | self, |
||
| 1040 | tls_certificate_id: str, |
||
| 1041 | *, |
||
| 1042 | name: Optional[str] = None, |
||
| 1043 | comment: Optional[str] = None, |
||
| 1044 | trust: Optional[bool] = None, |
||
| 1045 | ) -> Any: |
||
| 1046 | """Modifies an existing TLS certificate. |
||
| 1047 | |||
| 1048 | Arguments: |
||
| 1049 | tls_certificate_id: UUID of the TLS certificate to be modified. |
||
| 1050 | name: Name of the TLS certificate, defaulting to the MD5 fingerprint |
||
| 1051 | comment: Comment for the TLS certificate. |
||
| 1052 | trust: Whether the certificate is trusted. |
||
| 1053 | |||
| 1054 | Returns: |
||
| 1055 | The response. See :py:meth:`send_command` for details. |
||
| 1056 | """ |
||
| 1057 | if not tls_certificate_id: |
||
| 1058 | raise RequiredArgument( |
||
| 1059 | function=self.modify_tls_certificate.__name__, |
||
| 1060 | argument='tls_certificate_id', |
||
| 1061 | ) |
||
| 1062 | |||
| 1063 | cmd = XmlCommand("modify_tls_certificate") |
||
| 1064 | cmd.set_attribute("tls_certificate_id", str(tls_certificate_id)) |
||
| 1065 | |||
| 1066 | if comment: |
||
| 1067 | cmd.add_element("comment", comment) |
||
| 1068 | |||
| 1069 | if name: |
||
| 1070 | cmd.add_element("name", name) |
||
| 1071 | |||
| 1072 | if trust: |
||
| 1073 | cmd.add_element("trust", to_bool(trust)) |
||
| 1074 | |||
| 1075 | return self._send_xml_command(cmd) |
||
| 1076 | |||
| 1077 | def clone_ticket(self, ticket_id: str) -> Any: |
||
| 1078 | """Clone an existing ticket |
||
| 1079 | |||
| 1080 | Arguments: |
||
| 1081 | ticket_id: UUID of an existing ticket to clone from |
||
| 1082 | |||
| 1083 | Returns: |
||
| 1084 | The response. See :py:meth:`send_command` for details. |
||
| 1085 | """ |
||
| 1086 | if not ticket_id: |
||
| 1087 | raise RequiredArgument( |
||
| 1088 | function=self.clone_ticket.__name__, argument='ticket_id' |
||
| 1089 | ) |
||
| 1090 | |||
| 1091 | cmd = XmlCommand("create_ticket") |
||
| 1092 | |||
| 1093 | _copy = cmd.add_element("copy", ticket_id) |
||
| 1094 | |||
| 1095 | return self._send_xml_command(cmd) |
||
| 1096 | |||
| 1097 | def clone_tls_certificate(self, tls_certificate_id: str) -> Any: |
||
| 1098 | """Modifies an existing TLS certificate. |
||
| 1099 | |||
| 1100 | Arguments: |
||
| 1101 | tls_certificate_id: The UUID of an existing TLS certificate |
||
| 1102 | |||
| 1103 | Returns: |
||
| 1104 | The response. See :py:meth:`send_command` for details. |
||
| 1105 | """ |
||
| 1106 | if not tls_certificate_id: |
||
| 1107 | raise RequiredArgument( |
||
| 1108 | function=self.clone_tls_certificate.__name__, |
||
| 1109 | argument='tls_certificate_id', |
||
| 1110 | ) |
||
| 1111 | |||
| 1112 | cmd = XmlCommand("create_tls_certificate") |
||
| 1113 | |||
| 1114 | cmd.add_element("copy", tls_certificate_id) |
||
| 1115 | |||
| 1116 | return self._send_xml_command(cmd) |
||
| 1117 | |||
| 1118 | def get_configs( |
||
| 1119 | self, |
||
| 1120 | *, |
||
| 1121 | filter: Optional[str] = None, |
||
| 1122 | filter_id: Optional[str] = None, |
||
| 1123 | trash: Optional[bool] = None, |
||
| 1124 | details: Optional[bool] = None, |
||
| 1125 | families: Optional[bool] = None, |
||
| 1126 | preferences: Optional[bool] = None, |
||
| 1127 | tasks: Optional[bool] = None, |
||
| 1128 | ) -> Any: |
||
| 1129 | """Request a list of scan configs |
||
| 1130 | |||
| 1131 | Arguments: |
||
| 1132 | filter: Filter term to use for the query |
||
| 1133 | filter_id: UUID of an existing filter to use for the query |
||
| 1134 | trash: Whether to get the trashcan scan configs instead |
||
| 1135 | details: Whether to get config families, preferences, nvt selectors |
||
| 1136 | and tasks. |
||
| 1137 | families: Whether to include the families if no details are |
||
| 1138 | requested |
||
| 1139 | preferences: Whether to include the preferences if no details are |
||
| 1140 | requested |
||
| 1141 | tasks: Whether to get tasks using this config |
||
| 1142 | |||
| 1143 | Returns: |
||
| 1144 | The response. See :py:meth:`send_command` for details. |
||
| 1145 | """ |
||
| 1146 | return self.__get_configs( |
||
| 1147 | UsageType.SCAN, |
||
| 1148 | filter=filter, |
||
| 1149 | filter_id=filter_id, |
||
| 1150 | trash=trash, |
||
| 1151 | details=details, |
||
| 1152 | families=families, |
||
| 1153 | preferences=preferences, |
||
| 1154 | tasks=tasks, |
||
| 1155 | ) |
||
| 1156 | |||
| 1157 | def get_policies( |
||
| 1158 | self, |
||
| 1159 | *, |
||
| 1160 | audits: Optional[bool] = None, |
||
| 1161 | filter: Optional[str] = None, |
||
| 1162 | filter_id: Optional[str] = None, |
||
| 1163 | details: Optional[bool] = None, |
||
| 1164 | families: Optional[bool] = None, |
||
| 1165 | preferences: Optional[bool] = None, |
||
| 1166 | trash: Optional[bool] = None, |
||
| 1167 | ) -> Any: |
||
| 1168 | """Request a list of policies |
||
| 1169 | |||
| 1170 | Arguments: |
||
| 1171 | audits: Whether to get audits using the policy |
||
| 1172 | filter: Filter term to use for the query |
||
| 1173 | filter_id: UUID of an existing filter to use for the query |
||
| 1174 | details: Whether to get families, preferences, nvt selectors |
||
| 1175 | and tasks. |
||
| 1176 | families: Whether to include the families if no details are |
||
| 1177 | requested |
||
| 1178 | preferences: Whether to include the preferences if no details are |
||
| 1179 | requested |
||
| 1180 | trash: Whether to get the trashcan audits instead |
||
| 1181 | |||
| 1182 | Returns: |
||
| 1183 | The response. See :py:meth:`send_command` for details. |
||
| 1184 | """ |
||
| 1185 | return self.__get_configs( |
||
| 1186 | UsageType.POLICY, |
||
| 1187 | filter=filter, |
||
| 1188 | filter_id=filter_id, |
||
| 1189 | details=details, |
||
| 1190 | families=families, |
||
| 1191 | preferences=preferences, |
||
| 1192 | tasks=audits, |
||
| 1193 | trash=trash, |
||
| 1194 | ) |
||
| 1195 | |||
| 1196 | def get_config( |
||
| 1197 | self, config_id: str, *, tasks: Optional[bool] = None |
||
| 1198 | ) -> Any: |
||
| 1199 | """Request a single scan config |
||
| 1200 | |||
| 1201 | Arguments: |
||
| 1202 | config_id: UUID of an existing scan config |
||
| 1203 | tasks: Whether to get tasks using this config |
||
| 1204 | |||
| 1205 | Returns: |
||
| 1206 | The response. See :py:meth:`send_command` for details. |
||
| 1207 | """ |
||
| 1208 | return self.__get_config( |
||
| 1209 | config_id=config_id, usage_type=UsageType.SCAN, tasks=tasks |
||
| 1210 | ) |
||
| 1211 | |||
| 1212 | def get_policy( |
||
| 1213 | self, policy_id: str, *, audits: Optional[bool] = None |
||
| 1214 | ) -> Any: |
||
| 1215 | """Request a single policy |
||
| 1216 | |||
| 1217 | Arguments: |
||
| 1218 | policy_id: UUID of an existing policy |
||
| 1219 | audits: Whether to get audits using this config |
||
| 1220 | |||
| 1221 | Returns: |
||
| 1222 | The response. See :py:meth:`send_command` for details. |
||
| 1223 | """ |
||
| 1224 | return self.__get_config(policy_id, UsageType.POLICY, tasks=audits) |
||
| 1225 | |||
| 1226 | def get_tasks( |
||
| 1227 | self, |
||
| 1228 | *, |
||
| 1229 | filter: Optional[str] = None, |
||
| 1230 | filter_id: Optional[str] = None, |
||
| 1231 | trash: Optional[bool] = None, |
||
| 1232 | details: Optional[bool] = None, |
||
| 1233 | schedules_only: Optional[bool] = None, |
||
| 1234 | ) -> Any: |
||
| 1235 | """Request a list of tasks |
||
| 1236 | |||
| 1237 | Arguments: |
||
| 1238 | filter: Filter term to use for the query |
||
| 1239 | filter_id: UUID of an existing filter to use for the query |
||
| 1240 | trash: Whether to get the trashcan tasks instead |
||
| 1241 | details: Whether to include full task details |
||
| 1242 | schedules_only: Whether to only include id, name and schedule |
||
| 1243 | details |
||
| 1244 | |||
| 1245 | Returns: |
||
| 1246 | The response. See :py:meth:`send_command` for details. |
||
| 1247 | """ |
||
| 1248 | return self.__get_tasks( |
||
| 1249 | UsageType.SCAN, |
||
| 1250 | filter=filter, |
||
| 1251 | filter_id=filter_id, |
||
| 1252 | trash=trash, |
||
| 1253 | details=details, |
||
| 1254 | schedules_only=schedules_only, |
||
| 1255 | ) |
||
| 1256 | |||
| 1257 | def get_audits( |
||
| 1258 | self, |
||
| 1259 | *, |
||
| 1260 | filter: Optional[str] = None, |
||
| 1261 | filter_id: Optional[str] = None, |
||
| 1262 | trash: Optional[bool] = None, |
||
| 1263 | details: Optional[bool] = None, |
||
| 1264 | schedules_only: Optional[bool] = None, |
||
| 1265 | ) -> Any: |
||
| 1266 | """Request a list of audits |
||
| 1267 | |||
| 1268 | Arguments: |
||
| 1269 | filter: Filter term to use for the query |
||
| 1270 | filter_id: UUID of an existing filter to use for the query |
||
| 1271 | trash: Whether to get the trashcan audits instead |
||
| 1272 | details: Whether to include full audit details |
||
| 1273 | schedules_only: Whether to only include id, name and schedule |
||
| 1274 | details |
||
| 1275 | |||
| 1276 | Returns: |
||
| 1277 | The response. See :py:meth:`send_command` for details. |
||
| 1278 | """ |
||
| 1279 | return self.__get_tasks( |
||
| 1280 | UsageType.AUDIT, |
||
| 1281 | filter=filter, |
||
| 1282 | filter_id=filter_id, |
||
| 1283 | trash=trash, |
||
| 1284 | details=details, |
||
| 1285 | schedules_only=schedules_only, |
||
| 1286 | ) |
||
| 1287 | |||
| 1288 | def get_task(self, task_id: str) -> Any: |
||
| 1289 | """Request a single task |
||
| 1290 | |||
| 1291 | Arguments: |
||
| 1292 | task_id: UUID of an existing task |
||
| 1293 | |||
| 1294 | Returns: |
||
| 1295 | The response. See :py:meth:`send_command` for details. |
||
| 1296 | """ |
||
| 1297 | return self.__get_task(task_id, UsageType.SCAN) |
||
| 1298 | |||
| 1299 | def get_audit(self, audit_id: str) -> Any: |
||
| 1300 | """Request a single audit |
||
| 1301 | |||
| 1302 | Arguments: |
||
| 1303 | audit_id: UUID of an existing audit |
||
| 1304 | |||
| 1305 | Returns: |
||
| 1306 | The response. See :py:meth:`send_command` for details. |
||
| 1307 | """ |
||
| 1308 | return self.__get_task(audit_id, UsageType.AUDIT) |
||
| 1309 | |||
| 1310 | def clone_audit(self, audit_id: str) -> Any: |
||
| 1311 | """Clone an existing audit |
||
| 1312 | |||
| 1313 | Arguments: |
||
| 1314 | audit_id: UUID of existing audit to clone from |
||
| 1315 | |||
| 1316 | Returns: |
||
| 1317 | The response. See :py:meth:`send_command` for details. |
||
| 1318 | """ |
||
| 1319 | if not audit_id: |
||
| 1320 | raise RequiredArgument( |
||
| 1321 | function=self.clone_audit.__name__, argument='audit_id' |
||
| 1322 | ) |
||
| 1323 | |||
| 1324 | cmd = XmlCommand("create_task") |
||
| 1325 | cmd.add_element("copy", audit_id) |
||
| 1326 | return self._send_xml_command(cmd) |
||
| 1327 | |||
| 1328 | def clone_policy(self, policy_id: str) -> Any: |
||
| 1329 | """Clone a policy from an existing one |
||
| 1330 | |||
| 1331 | Arguments: |
||
| 1332 | policy_id: UUID of the existing policy |
||
| 1333 | |||
| 1334 | Returns: |
||
| 1335 | The response. See :py:meth:`send_command` for details. |
||
| 1336 | """ |
||
| 1337 | if not policy_id: |
||
| 1338 | raise RequiredArgument( |
||
| 1339 | function=self.clone_policy.__name__, argument='policy_id' |
||
| 1340 | ) |
||
| 1341 | |||
| 1342 | cmd = XmlCommand("create_config") |
||
| 1343 | cmd.add_element("copy", policy_id) |
||
| 1344 | return self._send_xml_command(cmd) |
||
| 1345 | |||
| 1346 | def delete_audit( |
||
| 1347 | self, audit_id: str, *, ultimate: Optional[bool] = False |
||
| 1348 | ) -> Any: |
||
| 1349 | """Deletes an existing audit |
||
| 1350 | |||
| 1351 | Arguments: |
||
| 1352 | audit_id: UUID of the audit to be deleted. |
||
| 1353 | ultimate: Whether to remove entirely, or to the trashcan. |
||
| 1354 | """ |
||
| 1355 | if not audit_id: |
||
| 1356 | raise RequiredArgument( |
||
| 1357 | function=self.delete_audit.__name__, argument='audit_id' |
||
| 1358 | ) |
||
| 1359 | |||
| 1360 | cmd = XmlCommand("delete_task") |
||
| 1361 | cmd.set_attribute("task_id", audit_id) |
||
| 1362 | cmd.set_attribute("ultimate", to_bool(ultimate)) |
||
| 1363 | |||
| 1364 | return self._send_xml_command(cmd) |
||
| 1365 | |||
| 1366 | def delete_policy( |
||
| 1367 | self, policy_id: str, *, ultimate: Optional[bool] = False |
||
| 1368 | ) -> Any: |
||
| 1369 | """Deletes an existing policy |
||
| 1370 | |||
| 1371 | Arguments: |
||
| 1372 | policy_id: UUID of the policy to be deleted. |
||
| 1373 | ultimate: Whether to remove entirely, or to the trashcan. |
||
| 1374 | """ |
||
| 1375 | if not policy_id: |
||
| 1376 | raise RequiredArgument( |
||
| 1377 | function=self.delete_policy.__name__, argument='policy_id' |
||
| 1378 | ) |
||
| 1379 | |||
| 1380 | cmd = XmlCommand("delete_config") |
||
| 1381 | cmd.set_attribute("config_id", policy_id) |
||
| 1382 | cmd.set_attribute("ultimate", to_bool(ultimate)) |
||
| 1383 | |||
| 1384 | return self._send_xml_command(cmd) |
||
| 1385 | |||
| 1386 | def delete_tls_certificate(self, tls_certificate_id: str) -> Any: |
||
| 1387 | """Deletes an existing tls certificate |
||
| 1388 | |||
| 1389 | Arguments: |
||
| 1390 | tls_certificate_id: UUID of the tls certificate to be deleted. |
||
| 1391 | """ |
||
| 1392 | if not tls_certificate_id: |
||
| 1393 | raise RequiredArgument( |
||
| 1394 | function=self.delete_tls_certificate.__name__, |
||
| 1395 | argument='tls_certificate_id', |
||
| 1396 | ) |
||
| 1397 | |||
| 1398 | cmd = XmlCommand("delete_tls_certificate") |
||
| 1399 | cmd.set_attribute("tls_certificate_id", tls_certificate_id) |
||
| 1400 | |||
| 1401 | return self._send_xml_command(cmd) |
||
| 1402 | |||
| 1403 | def __create_task( |
||
| 1404 | self, |
||
| 1405 | name: str, |
||
| 1406 | config_id: str, |
||
| 1407 | target_id: str, |
||
| 1408 | scanner_id: str, |
||
| 1409 | usage_type: UsageType, |
||
| 1410 | function: str, |
||
| 1411 | *, |
||
| 1412 | alterable: Optional[bool] = None, |
||
| 1413 | hosts_ordering: Optional[HostsOrdering] = None, |
||
| 1414 | schedule_id: Optional[str] = None, |
||
| 1415 | alert_ids: Optional[List[str]] = None, |
||
| 1416 | comment: Optional[str] = None, |
||
| 1417 | schedule_periods: Optional[int] = None, |
||
| 1418 | observers: Optional[List[str]] = None, |
||
| 1419 | preferences: Optional[dict] = None, |
||
| 1420 | ) -> Any: |
||
| 1421 | if not name: |
||
| 1422 | raise RequiredArgument(function=function, argument='name') |
||
| 1423 | |||
| 1424 | if not config_id: |
||
| 1425 | raise RequiredArgument(function=function, argument='config_id') |
||
| 1426 | |||
| 1427 | if not target_id: |
||
| 1428 | raise RequiredArgument(function=function, argument='target_id') |
||
| 1429 | |||
| 1430 | if not scanner_id: |
||
| 1431 | raise RequiredArgument(function=function, argument='scanner_id') |
||
| 1432 | |||
| 1433 | # don't allow to create a container task with create_task |
||
| 1434 | if target_id == '0': |
||
| 1435 | raise InvalidArgument(function=function, argument='target_id') |
||
| 1436 | |||
| 1437 | cmd = XmlCommand("create_task") |
||
| 1438 | cmd.add_element("name", name) |
||
| 1439 | cmd.add_element("usage_type", usage_type.value) |
||
| 1440 | cmd.add_element("config", attrs={"id": config_id}) |
||
| 1441 | cmd.add_element("target", attrs={"id": target_id}) |
||
| 1442 | cmd.add_element("scanner", attrs={"id": scanner_id}) |
||
| 1443 | |||
| 1444 | if comment: |
||
| 1445 | cmd.add_element("comment", comment) |
||
| 1446 | |||
| 1447 | if alterable is not None: |
||
| 1448 | cmd.add_element("alterable", to_bool(alterable)) |
||
| 1449 | |||
| 1450 | if hosts_ordering: |
||
| 1451 | if not isinstance(hosts_ordering, self.types.HostsOrdering): |
||
| 1452 | raise InvalidArgumentType( |
||
| 1453 | function=function, |
||
| 1454 | argument='hosts_ordering', |
||
| 1455 | arg_type=HostsOrdering.__name__, |
||
| 1456 | ) |
||
| 1457 | cmd.add_element("hosts_ordering", hosts_ordering.value) |
||
| 1458 | |||
| 1459 | if alert_ids: |
||
| 1460 | if isinstance(alert_ids, str): |
||
| 1461 | deprecation( |
||
| 1462 | "Please pass a list as alert_ids parameter to {}. " |
||
| 1463 | "Passing a string is deprecated and will be removed in " |
||
| 1464 | "future.".format(function) |
||
| 1465 | ) |
||
| 1466 | |||
| 1467 | # if a single id is given as a string wrap it into a list |
||
| 1468 | alert_ids = [alert_ids] |
||
| 1469 | if is_list_like(alert_ids): |
||
| 1470 | # parse all given alert id's |
||
| 1471 | for alert in alert_ids: |
||
| 1472 | cmd.add_element("alert", attrs={"id": str(alert)}) |
||
| 1473 | |||
| 1474 | View Code Duplication | if schedule_id: |
|
| 1475 | cmd.add_element("schedule", attrs={"id": schedule_id}) |
||
| 1476 | |||
| 1477 | if schedule_periods is not None: |
||
| 1478 | if ( |
||
| 1479 | not isinstance(schedule_periods, Integral) |
||
| 1480 | or schedule_periods < 0 |
||
| 1481 | ): |
||
| 1482 | raise InvalidArgument( |
||
| 1483 | "schedule_periods must be an integer greater or equal " |
||
| 1484 | "than 0" |
||
| 1485 | ) |
||
| 1486 | cmd.add_element("schedule_periods", str(schedule_periods)) |
||
| 1487 | |||
| 1488 | if observers is not None: |
||
| 1489 | if not is_list_like(observers): |
||
| 1490 | raise InvalidArgumentType( |
||
| 1491 | function=function, argument='observers', arg_type='list' |
||
| 1492 | ) |
||
| 1493 | |||
| 1494 | # gvmd splits by comma and space |
||
| 1495 | # gvmd tries to lookup each value as user name and afterwards as |
||
| 1496 | # user id. So both user name and user id are possible |
||
| 1497 | cmd.add_element("observers", to_comma_list(observers)) |
||
| 1498 | |||
| 1499 | View Code Duplication | if preferences is not None: |
|
| 1500 | if not isinstance(preferences, collections.abc.Mapping): |
||
| 1501 | raise InvalidArgumentType( |
||
| 1502 | function=function, |
||
| 1503 | argument='preferences', |
||
| 1504 | arg_type=collections.abc.Mapping.__name__, |
||
| 1505 | ) |
||
| 1506 | |||
| 1507 | _xmlprefs = cmd.add_element("preferences") |
||
| 1508 | for pref_name, pref_value in preferences.items(): |
||
| 1509 | _xmlpref = _xmlprefs.add_element("preference") |
||
| 1510 | _xmlpref.add_element("scanner_name", pref_name) |
||
| 1511 | _xmlpref.add_element("value", str(pref_value)) |
||
| 1512 | |||
| 1513 | return self._send_xml_command(cmd) |
||
| 1514 | |||
| 1515 | def __create_config( |
||
| 1516 | self, |
||
| 1517 | config_id: str, |
||
| 1518 | name: str, |
||
| 1519 | usage_type: UsageType, |
||
| 1520 | function: str, |
||
| 1521 | *, |
||
| 1522 | comment: Optional[str] = None, |
||
| 1523 | ) -> Any: |
||
| 1524 | if not name: |
||
| 1525 | raise RequiredArgument(function=function, argument='name') |
||
| 1526 | |||
| 1527 | if not config_id: |
||
| 1528 | raise RequiredArgument(function=function, argument='config_id') |
||
| 1529 | |||
| 1530 | cmd = XmlCommand("create_config") |
||
| 1531 | if comment is not None: |
||
| 1532 | cmd.add_element("comment", comment) |
||
| 1533 | cmd.add_element("copy", config_id) |
||
| 1534 | cmd.add_element("name", name) |
||
| 1535 | cmd.add_element("usage_type", usage_type.value) |
||
| 1536 | return self._send_xml_command(cmd) |
||
| 1537 | |||
| 1538 | def __create_config_from_osp_scanner( |
||
| 1539 | self, |
||
| 1540 | scanner_id: str, |
||
| 1541 | name: str, |
||
| 1542 | usage_type: UsageType, |
||
| 1543 | function: str, |
||
| 1544 | *, |
||
| 1545 | comment: Optional[str] = None, |
||
| 1546 | ) -> Any: |
||
| 1547 | if not name: |
||
| 1548 | raise RequiredArgument(function=function, argument='name') |
||
| 1549 | |||
| 1550 | if not scanner_id: |
||
| 1551 | raise RequiredArgument(function=function, argument='scanner_id') |
||
| 1552 | |||
| 1553 | cmd = XmlCommand("create_config") |
||
| 1554 | if comment is not None: |
||
| 1555 | cmd.add_element("comment", comment) |
||
| 1556 | cmd.add_element("scanner", scanner_id) |
||
| 1557 | cmd.add_element("name", name) |
||
| 1558 | cmd.add_element("usage_type", usage_type.value) |
||
| 1559 | return self._send_xml_command(cmd) |
||
| 1560 | |||
| 1561 | def __get_configs( |
||
| 1562 | self, |
||
| 1563 | usage_type: UsageType, |
||
| 1564 | *, |
||
| 1565 | filter: Optional[str] = None, |
||
| 1566 | filter_id: Optional[str] = None, |
||
| 1567 | trash: Optional[bool] = None, |
||
| 1568 | details: Optional[bool] = None, |
||
| 1569 | families: Optional[bool] = None, |
||
| 1570 | preferences: Optional[bool] = None, |
||
| 1571 | tasks: Optional[bool] = None, |
||
| 1572 | ) -> Any: |
||
| 1573 | cmd = XmlCommand("get_configs") |
||
| 1574 | cmd.set_attribute("usage_type", usage_type.value) |
||
| 1575 | |||
| 1576 | add_filter(cmd, filter, filter_id) |
||
| 1577 | |||
| 1578 | if trash is not None: |
||
| 1579 | cmd.set_attribute("trash", to_bool(trash)) |
||
| 1580 | |||
| 1581 | if details is not None: |
||
| 1582 | cmd.set_attribute("details", to_bool(details)) |
||
| 1583 | |||
| 1584 | if families is not None: |
||
| 1585 | cmd.set_attribute("families", to_bool(families)) |
||
| 1586 | |||
| 1587 | if preferences is not None: |
||
| 1588 | cmd.set_attribute("preferences", to_bool(preferences)) |
||
| 1589 | |||
| 1590 | if tasks is not None: |
||
| 1591 | cmd.set_attribute("tasks", to_bool(tasks)) |
||
| 1592 | |||
| 1593 | return self._send_xml_command(cmd) |
||
| 1594 | |||
| 1595 | def __get_config( |
||
| 1596 | self, |
||
| 1597 | config_id: str, |
||
| 1598 | usage_type: UsageType, |
||
| 1599 | *, |
||
| 1600 | tasks: Optional[bool] = None, |
||
| 1601 | ) -> Any: |
||
| 1602 | if not config_id: |
||
| 1603 | raise RequiredArgument( |
||
| 1604 | function=self.get_config.__name__, argument='config_id' |
||
| 1605 | ) |
||
| 1606 | |||
| 1607 | cmd = XmlCommand("get_configs") |
||
| 1608 | cmd.set_attribute("config_id", config_id) |
||
| 1609 | |||
| 1610 | cmd.set_attribute("usage_type", usage_type.value) |
||
| 1611 | |||
| 1612 | if tasks is not None: |
||
| 1613 | cmd.set_attribute("tasks", to_bool(tasks)) |
||
| 1614 | |||
| 1615 | # for single entity always request all details |
||
| 1616 | cmd.set_attribute("details", "1") |
||
| 1617 | |||
| 1618 | return self._send_xml_command(cmd) |
||
| 1619 | |||
| 1620 | def __get_tasks( |
||
| 1621 | self, |
||
| 1622 | usage_type: UsageType, |
||
| 1623 | *, |
||
| 1624 | filter: Optional[str] = None, |
||
| 1625 | filter_id: Optional[str] = None, |
||
| 1626 | trash: Optional[bool] = None, |
||
| 1627 | details: Optional[bool] = None, |
||
| 1628 | schedules_only: Optional[bool] = None, |
||
| 1629 | ) -> Any: |
||
| 1630 | cmd = XmlCommand("get_tasks") |
||
| 1631 | cmd.set_attribute("usage_type", usage_type.value) |
||
| 1632 | |||
| 1633 | add_filter(cmd, filter, filter_id) |
||
| 1634 | |||
| 1635 | if trash is not None: |
||
| 1636 | cmd.set_attribute("trash", to_bool(trash)) |
||
| 1637 | |||
| 1638 | if details is not None: |
||
| 1639 | cmd.set_attribute("details", to_bool(details)) |
||
| 1640 | |||
| 1641 | if schedules_only is not None: |
||
| 1642 | cmd.set_attribute("schedules_only", to_bool(schedules_only)) |
||
| 1643 | |||
| 1644 | return self._send_xml_command(cmd) |
||
| 1645 | |||
| 1646 | def __get_task(self, task_id: str, usage_type: UsageType) -> Any: |
||
| 1647 | if not task_id: |
||
| 1648 | raise RequiredArgument( |
||
| 1649 | function=self.get_task.__name__, argument='task_id' |
||
| 1650 | ) |
||
| 1651 | |||
| 1652 | cmd = XmlCommand("get_tasks") |
||
| 1653 | cmd.set_attribute("task_id", task_id) |
||
| 1654 | cmd.set_attribute("usage_type", usage_type.value) |
||
| 1655 | |||
| 1656 | # for single entity always request all details |
||
| 1657 | cmd.set_attribute("details", "1") |
||
| 1658 | return self._send_xml_command(cmd) |
||
| 1659 | |||
| 1660 | def resume_audit(self, audit_id: str) -> Any: |
||
| 1661 | """Resume an existing stopped audit |
||
| 1662 | |||
| 1663 | Arguments: |
||
| 1664 | audit_id: UUID of the audit to be resumed |
||
| 1665 | |||
| 1666 | Returns: |
||
| 1667 | The response. See :py:meth:`send_command` for details. |
||
| 1668 | """ |
||
| 1669 | if not audit_id: |
||
| 1670 | raise RequiredArgument( |
||
| 1671 | function=self.resume_audit.__name__, argument='audit_id' |
||
| 1672 | ) |
||
| 1673 | |||
| 1674 | cmd = XmlCommand("resume_task") |
||
| 1675 | cmd.set_attribute("task_id", audit_id) |
||
| 1676 | |||
| 1677 | return self._send_xml_command(cmd) |
||
| 1678 | |||
| 1679 | def start_audit(self, audit_id: str) -> Any: |
||
| 1680 | """Start an existing audit |
||
| 1681 | |||
| 1682 | Arguments: |
||
| 1683 | audit_id: UUID of the audit to be started |
||
| 1684 | |||
| 1685 | Returns: |
||
| 1686 | The response. See :py:meth:`send_command` for details. |
||
| 1687 | """ |
||
| 1688 | if not audit_id: |
||
| 1689 | raise RequiredArgument( |
||
| 1690 | function=self.start_audit.__name__, argument='audit_id' |
||
| 1691 | ) |
||
| 1692 | |||
| 1693 | cmd = XmlCommand("start_task") |
||
| 1694 | cmd.set_attribute("task_id", audit_id) |
||
| 1695 | |||
| 1696 | return self._send_xml_command(cmd) |
||
| 1697 | |||
| 1698 | def stop_audit(self, audit_id: str) -> Any: |
||
| 1699 | """Stop an existing running audit |
||
| 1700 | |||
| 1701 | Arguments: |
||
| 1702 | audit_id: UUID of the audit to be stopped |
||
| 1703 | |||
| 1704 | Returns: |
||
| 1705 | The response. See :py:meth:`send_command` for details. |
||
| 1706 | """ |
||
| 1707 | if not audit_id: |
||
| 1708 | raise RequiredArgument( |
||
| 1709 | function=self.stop_audit.__name__, argument='audit_id' |
||
| 1710 | ) |
||
| 1711 | |||
| 1712 | cmd = XmlCommand("stop_task") |
||
| 1713 | cmd.set_attribute("task_id", audit_id) |
||
| 1714 | |||
| 1715 | return self._send_xml_command(cmd) |
||
| 1716 | |||
| 1717 | def get_feed(self, feed_type: Optional[FeedType]) -> Any: |
||
| 1718 | """Request a single feed |
||
| 1719 | |||
| 1720 | Arguments: |
||
| 1721 | feed_type: Type of single feed to get: NVT, CERT or SCAP |
||
| 1722 | |||
| 1723 | Returns: |
||
| 1724 | The response. See :py:meth:`send_command` for details. |
||
| 1725 | """ |
||
| 1726 | if not feed_type: |
||
| 1727 | raise RequiredArgument( |
||
| 1728 | function=self.get_feed.__name__, argument='feed_type' |
||
| 1729 | ) |
||
| 1730 | |||
| 1731 | if not isinstance(feed_type, FeedType): |
||
| 1732 | raise InvalidArgumentType( |
||
| 1733 | function=self.get_feed.__name__, |
||
| 1734 | argument='feed_type', |
||
| 1735 | arg_type=FeedType.__name__, |
||
| 1736 | ) |
||
| 1737 | |||
| 1738 | cmd = XmlCommand("get_feeds") |
||
| 1739 | cmd.set_attribute("type", feed_type.value) |
||
| 1740 | |||
| 1741 | return self._send_xml_command(cmd) |
||
| 1742 | |||
| 1743 | def create_credential( |
||
| 1744 | self, |
||
| 1745 | name: str, |
||
| 1746 | credential_type: CredentialType, |
||
| 1747 | *, |
||
| 1748 | comment: Optional[str] = None, |
||
| 1749 | allow_insecure: Optional[bool] = None, |
||
| 1750 | certificate: Optional[str] = None, |
||
| 1751 | key_phrase: Optional[str] = None, |
||
| 1752 | private_key: Optional[str] = None, |
||
| 1753 | login: Optional[str] = None, |
||
| 1754 | password: Optional[str] = None, |
||
| 1755 | auth_algorithm: Optional[SnmpAuthAlgorithm] = None, |
||
| 1756 | community: Optional[str] = None, |
||
| 1757 | privacy_algorithm: Optional[SnmpPrivacyAlgorithm] = None, |
||
| 1758 | privacy_password: Optional[str] = None, |
||
| 1759 | public_key: Optional[str] = None, |
||
| 1760 | ) -> Any: |
||
| 1761 | """Create a new credential |
||
| 1762 | |||
| 1763 | Create a new credential e.g. to be used in the method of an alert. |
||
| 1764 | |||
| 1765 | Currently the following credential types are supported: |
||
| 1766 | |||
| 1767 | - Username + Password |
||
| 1768 | - Username + SSH-Key |
||
| 1769 | - Client Certificates |
||
| 1770 | - SNMPv1 or SNMPv2c protocol |
||
| 1771 | - S/MIME Certificate |
||
| 1772 | - OpenPGP Key |
||
| 1773 | - Password only |
||
| 1774 | |||
| 1775 | Arguments: |
||
| 1776 | name: Name of the new credential |
||
| 1777 | credential_type: The credential type. |
||
| 1778 | comment: Comment for the credential |
||
| 1779 | allow_insecure: Whether to allow insecure use of the credential |
||
| 1780 | certificate: Certificate for the credential. |
||
| 1781 | Required for client-certificate and smime credential types. |
||
| 1782 | key_phrase: Key passphrase for the private key. |
||
| 1783 | Used for the username+ssh-key credential type. |
||
| 1784 | private_key: Private key to use for login. Required |
||
| 1785 | for usk credential type. Also used for the cc credential type. |
||
| 1786 | The supported key types (dsa, rsa, ecdsa, ...) and formats (PEM, |
||
| 1787 | PKC#12, OpenSSL, ...) depend on your installed GnuTLS version. |
||
| 1788 | login: Username for the credential. Required for username+password, |
||
| 1789 | username+ssh-key and snmp credential type. |
||
| 1790 | password: Password for the credential. Used for username+password |
||
| 1791 | and snmp credential types. |
||
| 1792 | community: The SNMP community |
||
| 1793 | auth_algorithm: The SNMP authentication algorithm. Required for snmp |
||
| 1794 | credential type. |
||
| 1795 | privacy_algorithm: The SNMP privacy algorithm |
||
| 1796 | privacy_password: The SNMP privacy password |
||
| 1797 | public_key: PGP public key in *armor* plain text format. Required |
||
| 1798 | for pgp credential type. |
||
| 1799 | |||
| 1800 | Examples: |
||
| 1801 | Creating a Username + Password credential |
||
| 1802 | |||
| 1803 | .. code-block:: python |
||
| 1804 | |||
| 1805 | gmp.create_credential( |
||
| 1806 | name='UP Credential', |
||
| 1807 | credential_type=CredentialType.USERNAME_PASSWORD, |
||
| 1808 | login='foo', |
||
| 1809 | password='bar', |
||
| 1810 | ) |
||
| 1811 | |||
| 1812 | Creating a Username + SSH Key credential |
||
| 1813 | |||
| 1814 | .. code-block:: python |
||
| 1815 | |||
| 1816 | with open('path/to/private-ssh-key') as f: |
||
| 1817 | key = f.read() |
||
| 1818 | |||
| 1819 | gmp.create_credential( |
||
| 1820 | name='USK Credential', |
||
| 1821 | credential_type=CredentialType.USERNAME_SSH_KEY, |
||
| 1822 | login='foo', |
||
| 1823 | key_phrase='foobar', |
||
| 1824 | private_key=key, |
||
| 1825 | ) |
||
| 1826 | |||
| 1827 | Creating a PGP credential |
||
| 1828 | |||
| 1829 | .. note:: |
||
| 1830 | |||
| 1831 | A compatible public pgp key file can be exported with GnuPG via |
||
| 1832 | :: |
||
| 1833 | |||
| 1834 | $ gpg --armor --export [email protected] > alice.asc |
||
| 1835 | |||
| 1836 | .. code-block:: python |
||
| 1837 | |||
| 1838 | with open('path/to/pgp.key.asc') as f: |
||
| 1839 | key = f.read() |
||
| 1840 | |||
| 1841 | gmp.create_credential( |
||
| 1842 | name='PGP Credential', |
||
| 1843 | credential_type=CredentialType.PGP_ENCRYPTION_KEY, |
||
| 1844 | public_key=key, |
||
| 1845 | ) |
||
| 1846 | |||
| 1847 | Creating a S/MIME credential |
||
| 1848 | |||
| 1849 | .. code-block:: python |
||
| 1850 | |||
| 1851 | with open('path/to/smime-cert') as f: |
||
| 1852 | cert = f.read() |
||
| 1853 | |||
| 1854 | gmp.create_credential( |
||
| 1855 | name='SMIME Credential', |
||
| 1856 | credential_type=CredentialType.SMIME_CERTIFICATE, |
||
| 1857 | certificate=cert, |
||
| 1858 | ) |
||
| 1859 | |||
| 1860 | Creating a Password-Only credential |
||
| 1861 | |||
| 1862 | .. code-block:: python |
||
| 1863 | |||
| 1864 | gmp.create_credential( |
||
| 1865 | name='Password-Only Credential', |
||
| 1866 | credential_type=CredentialType.PASSWORD_ONLY, |
||
| 1867 | password='foo', |
||
| 1868 | ) |
||
| 1869 | Returns: |
||
| 1870 | The response. See :py:meth:`send_command` for details. |
||
| 1871 | """ |
||
| 1872 | if not name: |
||
| 1873 | raise RequiredArgument( |
||
| 1874 | function=self.create_credential.__name__, argument='name' |
||
| 1875 | ) |
||
| 1876 | |||
| 1877 | if not isinstance(credential_type, self.types.CredentialType): |
||
| 1878 | raise InvalidArgumentType( |
||
| 1879 | function=self.create_credential.__name__, |
||
| 1880 | argument='credential_type', |
||
| 1881 | arg_type=CredentialType.__name__, |
||
| 1882 | ) |
||
| 1883 | |||
| 1884 | cmd = XmlCommand("create_credential") |
||
| 1885 | cmd.add_element("name", name) |
||
| 1886 | |||
| 1887 | cmd.add_element("type", credential_type.value) |
||
| 1888 | |||
| 1889 | if comment: |
||
| 1890 | cmd.add_element("comment", comment) |
||
| 1891 | |||
| 1892 | if allow_insecure is not None: |
||
| 1893 | cmd.add_element("allow_insecure", to_bool(allow_insecure)) |
||
| 1894 | |||
| 1895 | if ( |
||
| 1896 | credential_type == CredentialType.CLIENT_CERTIFICATE |
||
| 1897 | or credential_type == CredentialType.SMIME_CERTIFICATE |
||
| 1898 | ): |
||
| 1899 | if not certificate: |
||
| 1900 | raise RequiredArgument( |
||
| 1901 | function=self.create_credential.__name__, |
||
| 1902 | argument='certificate', |
||
| 1903 | ) |
||
| 1904 | |||
| 1905 | cmd.add_element("certificate", certificate) |
||
| 1906 | |||
| 1907 | if ( |
||
| 1908 | credential_type == CredentialType.USERNAME_PASSWORD |
||
| 1909 | or credential_type == CredentialType.USERNAME_SSH_KEY |
||
| 1910 | or credential_type == CredentialType.SNMP |
||
| 1911 | ): |
||
| 1912 | if not login: |
||
| 1913 | raise RequiredArgument( |
||
| 1914 | function=self.create_credential.__name__, argument='login' |
||
| 1915 | ) |
||
| 1916 | |||
| 1917 | cmd.add_element("login", login) |
||
| 1918 | |||
| 1919 | if credential_type == CredentialType.PASSWORD_ONLY and not password: |
||
| 1920 | raise RequiredArgument( |
||
| 1921 | function=self.create_credential.__name__, argument='password' |
||
| 1922 | ) |
||
| 1923 | |||
| 1924 | if ( |
||
| 1925 | credential_type == CredentialType.USERNAME_PASSWORD |
||
| 1926 | or credential_type == CredentialType.SNMP |
||
| 1927 | or credential_type == CredentialType.PASSWORD_ONLY |
||
| 1928 | ) and password: |
||
| 1929 | cmd.add_element("password", password) |
||
| 1930 | |||
| 1931 | if credential_type == CredentialType.USERNAME_SSH_KEY: |
||
| 1932 | if not private_key: |
||
| 1933 | raise RequiredArgument( |
||
| 1934 | function=self.create_credential.__name__, |
||
| 1935 | argument='private_key', |
||
| 1936 | ) |
||
| 1937 | |||
| 1938 | _xmlkey = cmd.add_element("key") |
||
| 1939 | _xmlkey.add_element("private", private_key) |
||
| 1940 | |||
| 1941 | if key_phrase: |
||
| 1942 | _xmlkey.add_element("phrase", key_phrase) |
||
| 1943 | |||
| 1944 | if credential_type == CredentialType.CLIENT_CERTIFICATE and private_key: |
||
| 1945 | _xmlkey = cmd.add_element("key") |
||
| 1946 | _xmlkey.add_element("private", private_key) |
||
| 1947 | |||
| 1948 | if credential_type == CredentialType.SNMP: |
||
| 1949 | if not isinstance(auth_algorithm, self.types.SnmpAuthAlgorithm): |
||
| 1950 | raise InvalidArgumentType( |
||
| 1951 | function=self.create_credential.__name__, |
||
| 1952 | argument='auth_algorithm', |
||
| 1953 | arg_type=SnmpAuthAlgorithm.__name__, |
||
| 1954 | ) |
||
| 1955 | |||
| 1956 | cmd.add_element("auth_algorithm", auth_algorithm.value) |
||
| 1957 | |||
| 1958 | if community: |
||
| 1959 | cmd.add_element("community", community) |
||
| 1960 | |||
| 1961 | View Code Duplication | if privacy_algorithm is not None or privacy_password: |
|
| 1962 | _xmlprivacy = cmd.add_element("privacy") |
||
| 1963 | |||
| 1964 | if privacy_algorithm is not None: |
||
| 1965 | if not isinstance( |
||
| 1966 | privacy_algorithm, self.types.SnmpPrivacyAlgorithm |
||
| 1967 | ): |
||
| 1968 | raise InvalidArgumentType( |
||
| 1969 | function=self.create_credential.__name__, |
||
| 1970 | argument='privacy_algorithm', |
||
| 1971 | arg_type=SnmpPrivacyAlgorithm.__name__, |
||
| 1972 | ) |
||
| 1973 | |||
| 1974 | _xmlprivacy.add_element( |
||
| 1975 | "algorithm", privacy_algorithm.value |
||
| 1976 | ) |
||
| 1977 | |||
| 1978 | if privacy_password: |
||
| 1979 | _xmlprivacy.add_element("password", privacy_password) |
||
| 1980 | |||
| 1981 | if credential_type == CredentialType.PGP_ENCRYPTION_KEY: |
||
| 1982 | if not public_key: |
||
| 1983 | raise RequiredArgument( |
||
| 1984 | function=self.create_credential.__name__, |
||
| 1985 | argument='public_key', |
||
| 1986 | ) |
||
| 1987 | |||
| 1988 | _xmlkey = cmd.add_element("key") |
||
| 1989 | _xmlkey.add_element("public", public_key) |
||
| 1990 | |||
| 1991 | return self._send_xml_command(cmd) |
||
| 1992 | |||
| 1993 | def modify_credential( |
||
| 1994 | self, |
||
| 1995 | credential_id: str, |
||
| 1996 | *, |
||
| 1997 | name: Optional[str] = None, |
||
| 1998 | comment: Optional[str] = None, |
||
| 1999 | allow_insecure: Optional[bool] = None, |
||
| 2000 | certificate: Optional[str] = None, |
||
| 2001 | key_phrase: Optional[str] = None, |
||
| 2002 | private_key: Optional[str] = None, |
||
| 2003 | login: Optional[str] = None, |
||
| 2004 | password: Optional[str] = None, |
||
| 2005 | auth_algorithm: Optional[SnmpAuthAlgorithm] = None, |
||
| 2006 | community: Optional[str] = None, |
||
| 2007 | privacy_algorithm: Optional[SnmpPrivacyAlgorithm] = None, |
||
| 2008 | privacy_password: Optional[str] = None, |
||
| 2009 | public_key: Optional[str] = None, |
||
| 2010 | ) -> Any: |
||
| 2011 | """Modifies an existing credential. |
||
| 2012 | |||
| 2013 | Arguments: |
||
| 2014 | credential_id: UUID of the credential |
||
| 2015 | name: Name of the credential |
||
| 2016 | comment: Comment for the credential |
||
| 2017 | allow_insecure: Whether to allow insecure use of the credential |
||
| 2018 | certificate: Certificate for the credential |
||
| 2019 | key_phrase: Key passphrase for the private key |
||
| 2020 | private_key: Private key to use for login |
||
| 2021 | login: Username for the credential |
||
| 2022 | password: Password for the credential |
||
| 2023 | auth_algorithm: The authentication algorithm for SNMP |
||
| 2024 | community: The SNMP community |
||
| 2025 | privacy_algorithm: The privacy algorithm for SNMP |
||
| 2026 | privacy_password: The SNMP privacy password |
||
| 2027 | public_key: PGP public key in *armor* plain text format |
||
| 2028 | |||
| 2029 | Returns: |
||
| 2030 | The response. See :py:meth:`send_command` for details. |
||
| 2031 | """ |
||
| 2032 | if not credential_id: |
||
| 2033 | raise RequiredArgument( |
||
| 2034 | function=self.modify_credential.__name__, |
||
| 2035 | argument='credential_id', |
||
| 2036 | ) |
||
| 2037 | |||
| 2038 | cmd = XmlCommand("modify_credential") |
||
| 2039 | cmd.set_attribute("credential_id", credential_id) |
||
| 2040 | |||
| 2041 | if comment: |
||
| 2042 | cmd.add_element("comment", comment) |
||
| 2043 | |||
| 2044 | if name: |
||
| 2045 | cmd.add_element("name", name) |
||
| 2046 | |||
| 2047 | if allow_insecure is not None: |
||
| 2048 | cmd.add_element("allow_insecure", to_bool(allow_insecure)) |
||
| 2049 | |||
| 2050 | if certificate: |
||
| 2051 | cmd.add_element("certificate", certificate) |
||
| 2052 | |||
| 2053 | if key_phrase and private_key: |
||
| 2054 | _xmlkey = cmd.add_element("key") |
||
| 2055 | _xmlkey.add_element("phrase", key_phrase) |
||
| 2056 | _xmlkey.add_element("private", private_key) |
||
| 2057 | elif (not key_phrase and private_key) or ( |
||
| 2058 | key_phrase and not private_key |
||
| 2059 | ): |
||
| 2060 | raise RequiredArgument( |
||
| 2061 | function=self.modify_credential.__name__, |
||
| 2062 | argument='key_phrase and private_key', |
||
| 2063 | ) |
||
| 2064 | |||
| 2065 | if login: |
||
| 2066 | cmd.add_element("login", login) |
||
| 2067 | |||
| 2068 | if password: |
||
| 2069 | cmd.add_element("password", password) |
||
| 2070 | |||
| 2071 | if auth_algorithm: |
||
| 2072 | if not isinstance(auth_algorithm, self.types.SnmpAuthAlgorithm): |
||
| 2073 | raise InvalidArgumentType( |
||
| 2074 | function=self.modify_credential.__name__, |
||
| 2075 | argument='auth_algorithm', |
||
| 2076 | arg_type=SnmpAuthAlgorithm.__name__, |
||
| 2077 | ) |
||
| 2078 | cmd.add_element("auth_algorithm", auth_algorithm.value) |
||
| 2079 | |||
| 2080 | if community: |
||
| 2081 | cmd.add_element("community", community) |
||
| 2082 | |||
| 2083 | View Code Duplication | if privacy_algorithm is not None or privacy_password is not None: |
|
| 2084 | _xmlprivacy = cmd.add_element("privacy") |
||
| 2085 | |||
| 2086 | if privacy_algorithm is not None: |
||
| 2087 | if not isinstance( |
||
| 2088 | privacy_algorithm, self.types.SnmpPrivacyAlgorithm |
||
| 2089 | ): |
||
| 2090 | raise InvalidArgumentType( |
||
| 2091 | function=self.modify_credential.__name__, |
||
| 2092 | argument='privacy_algorithm', |
||
| 2093 | arg_type=SnmpPrivacyAlgorithm.__name__, |
||
| 2094 | ) |
||
| 2095 | |||
| 2096 | _xmlprivacy.add_element("algorithm", privacy_algorithm.value) |
||
| 2097 | |||
| 2098 | if privacy_password is not None: |
||
| 2099 | _xmlprivacy.add_element("password", privacy_password) |
||
| 2100 | |||
| 2101 | if public_key: |
||
| 2102 | _xmlkey = cmd.add_element("key") |
||
| 2103 | _xmlkey.add_element("public", public_key) |
||
| 2104 | |||
| 2105 | return self._send_xml_command(cmd) |
||
| 2106 | |||
| 2107 | def create_ticket( |
||
| 2108 | self, |
||
| 2109 | *, |
||
| 2110 | result_id: str, |
||
| 2111 | assigned_to_user_id: str, |
||
| 2112 | note: str, |
||
| 2113 | comment: Optional[str] = None, |
||
| 2114 | ) -> Any: |
||
| 2115 | """Create a new ticket |
||
| 2116 | |||
| 2117 | Arguments: |
||
| 2118 | result_id: UUID of the result the ticket applies to |
||
| 2119 | assigned_to_user_id: UUID of a user the ticket should be assigned to |
||
| 2120 | note: A note about opening the ticket |
||
| 2121 | comment: Comment for the ticket |
||
| 2122 | |||
| 2123 | Returns: |
||
| 2124 | The response. See :py:meth:`send_command` for details. |
||
| 2125 | """ |
||
| 2126 | if not result_id: |
||
| 2127 | raise RequiredArgument( |
||
| 2128 | function=self.create_ticket.__name__, argument='result_id' |
||
| 2129 | ) |
||
| 2130 | |||
| 2131 | if not assigned_to_user_id: |
||
| 2132 | raise RequiredArgument( |
||
| 2133 | function=self.create_ticket.__name__, |
||
| 2134 | argument='assigned_to_user_id', |
||
| 2135 | ) |
||
| 2136 | |||
| 2137 | if not note: |
||
| 2138 | raise RequiredArgument( |
||
| 2139 | function=self.create_ticket.__name__, argument='note' |
||
| 2140 | ) |
||
| 2141 | |||
| 2142 | cmd = XmlCommand("create_ticket") |
||
| 2143 | |||
| 2144 | _result = cmd.add_element("result") |
||
| 2145 | _result.set_attribute("id", result_id) |
||
| 2146 | |||
| 2147 | _assigned = cmd.add_element("assigned_to") |
||
| 2148 | _user = _assigned.add_element("user") |
||
| 2149 | _user.set_attribute("id", assigned_to_user_id) |
||
| 2150 | |||
| 2151 | _note = cmd.add_element("open_note", note) |
||
| 2152 | |||
| 2153 | if comment: |
||
| 2154 | cmd.add_element("comment", comment) |
||
| 2155 | |||
| 2156 | return self._send_xml_command(cmd) |
||
| 2157 | |||
| 2158 | def delete_ticket( |
||
| 2159 | self, ticket_id: str, *, ultimate: Optional[bool] = False |
||
| 2160 | ): |
||
| 2161 | """Deletes an existing ticket |
||
| 2162 | |||
| 2163 | Arguments: |
||
| 2164 | ticket_id: UUID of the ticket to be deleted. |
||
| 2165 | ultimate: Whether to remove entirely, or to the trashcan. |
||
| 2166 | """ |
||
| 2167 | if not ticket_id: |
||
| 2168 | raise RequiredArgument( |
||
| 2169 | function=self.delete_ticket.__name__, argument='ticket_id' |
||
| 2170 | ) |
||
| 2171 | |||
| 2172 | cmd = XmlCommand("delete_ticket") |
||
| 2173 | cmd.set_attribute("ticket_id", ticket_id) |
||
| 2174 | cmd.set_attribute("ultimate", to_bool(ultimate)) |
||
| 2175 | |||
| 2176 | return self._send_xml_command(cmd) |
||
| 2177 | |||
| 2178 | View Code Duplication | def get_tickets( |
|
| 2179 | self, |
||
| 2180 | *, |
||
| 2181 | trash: Optional[bool] = None, |
||
| 2182 | filter: Optional[str] = None, |
||
| 2183 | filter_id: Optional[str] = None, |
||
| 2184 | ) -> Any: |
||
| 2185 | """Request a list of tickets |
||
| 2186 | |||
| 2187 | Arguments: |
||
| 2188 | filter: Filter term to use for the query |
||
| 2189 | filter_id: UUID of an existing filter to use for the query |
||
| 2190 | trash: True to request the tickets in the trashcan |
||
| 2191 | |||
| 2192 | Returns: |
||
| 2193 | The response. See :py:meth:`send_command` for details. |
||
| 2194 | """ |
||
| 2195 | cmd = XmlCommand("get_tickets") |
||
| 2196 | |||
| 2197 | add_filter(cmd, filter, filter_id) |
||
| 2198 | |||
| 2199 | if trash is not None: |
||
| 2200 | cmd.set_attribute("trash", to_bool(trash)) |
||
| 2201 | |||
| 2202 | return self._send_xml_command(cmd) |
||
| 2203 | |||
| 2204 | def get_ticket(self, ticket_id: str) -> Any: |
||
| 2205 | """Request a single ticket |
||
| 2206 | |||
| 2207 | Arguments: |
||
| 2208 | ticket_id: UUID of an existing ticket |
||
| 2209 | |||
| 2210 | Returns: |
||
| 2211 | The response. See :py:meth:`send_command` for details. |
||
| 2212 | """ |
||
| 2213 | if not ticket_id: |
||
| 2214 | raise RequiredArgument( |
||
| 2215 | function=self.get_ticket.__name__, argument='ticket_id' |
||
| 2216 | ) |
||
| 2217 | |||
| 2218 | cmd = XmlCommand("get_tickets") |
||
| 2219 | cmd.set_attribute("ticket_id", ticket_id) |
||
| 2220 | return self._send_xml_command(cmd) |
||
| 2221 | |||
| 2222 | def get_vulnerabilities( |
||
| 2223 | self, *, filter: Optional[str] = None, filter_id: Optional[str] = None |
||
| 2224 | ) -> Any: |
||
| 2225 | """Request a list of vulnerabilities |
||
| 2226 | |||
| 2227 | Arguments: |
||
| 2228 | filter: Filter term to use for the query |
||
| 2229 | filter_id: UUID of an existing filter to use for the query |
||
| 2230 | Returns: |
||
| 2231 | The response. See :py:meth:`send_command` for details. |
||
| 2232 | """ |
||
| 2233 | cmd = XmlCommand("get_vulns") |
||
| 2234 | |||
| 2235 | add_filter(cmd, filter, filter_id) |
||
| 2236 | |||
| 2237 | return self._send_xml_command(cmd) |
||
| 2238 | |||
| 2239 | def get_vulnerability(self, vulnerability_id: str) -> Any: |
||
| 2240 | """Request a single vulnerability |
||
| 2241 | |||
| 2242 | Arguments: |
||
| 2243 | vulnerability_id: ID of an existing vulnerability |
||
| 2244 | |||
| 2245 | Returns: |
||
| 2246 | The response. See :py:meth:`send_command` for details. |
||
| 2247 | """ |
||
| 2248 | if not vulnerability_id: |
||
| 2249 | raise RequiredArgument( |
||
| 2250 | function=self.get_vulnerability.__name__, |
||
| 2251 | argument='vulnerability_id', |
||
| 2252 | ) |
||
| 2253 | |||
| 2254 | cmd = XmlCommand("get_vulns") |
||
| 2255 | cmd.set_attribute("vuln_id", vulnerability_id) |
||
| 2256 | return self._send_xml_command(cmd) |
||
| 2257 | |||
| 2258 | def modify_ticket( |
||
| 2259 | self, |
||
| 2260 | ticket_id: str, |
||
| 2261 | *, |
||
| 2262 | status: Optional[TicketStatus] = None, |
||
| 2263 | note: Optional[str] = None, |
||
| 2264 | assigned_to_user_id: Optional[str] = None, |
||
| 2265 | comment: Optional[str] = None, |
||
| 2266 | ) -> Any: |
||
| 2267 | """Modify a single ticket |
||
| 2268 | |||
| 2269 | Arguments: |
||
| 2270 | ticket_id: UUID of an existing ticket |
||
| 2271 | status: New status for the ticket |
||
| 2272 | note: Note for the status change. Required if status is set. |
||
| 2273 | assigned_to_user_id: UUID of the user the ticket should be assigned |
||
| 2274 | to |
||
| 2275 | comment: Comment for the ticket |
||
| 2276 | |||
| 2277 | Returns: |
||
| 2278 | The response. See :py:meth:`send_command` for details. |
||
| 2279 | """ |
||
| 2280 | if not ticket_id: |
||
| 2281 | raise RequiredArgument( |
||
| 2282 | function=self.modify_ticket.__name__, argument='ticket_id' |
||
| 2283 | ) |
||
| 2284 | |||
| 2285 | if status and not note: |
||
| 2286 | raise RequiredArgument( |
||
| 2287 | function=self.modify_ticket.__name__, argument='note' |
||
| 2288 | ) |
||
| 2289 | |||
| 2290 | if note and not status: |
||
| 2291 | raise RequiredArgument( |
||
| 2292 | function=self.modify_ticket.__name__, argument='status' |
||
| 2293 | ) |
||
| 2294 | |||
| 2295 | cmd = XmlCommand("modify_ticket") |
||
| 2296 | cmd.set_attribute("ticket_id", ticket_id) |
||
| 2297 | |||
| 2298 | if assigned_to_user_id: |
||
| 2299 | _assigned = cmd.add_element("assigned_to") |
||
| 2300 | _user = _assigned.add_element("user") |
||
| 2301 | _user.set_attribute("id", assigned_to_user_id) |
||
| 2302 | |||
| 2303 | if status: |
||
| 2304 | if not isinstance(status, self.types.TicketStatus): |
||
| 2305 | raise InvalidArgumentType( |
||
| 2306 | function=self.modify_ticket.__name__, |
||
| 2307 | argument='status', |
||
| 2308 | arg_type=TicketStatus.__name__, |
||
| 2309 | ) |
||
| 2310 | |||
| 2311 | cmd.add_element('status', status.value) |
||
| 2312 | cmd.add_element('{}_note'.format(status.name.lower()), note) |
||
| 2313 | |||
| 2314 | if comment: |
||
| 2315 | cmd.add_element("comment", comment) |
||
| 2316 | |||
| 2317 | return self._send_xml_command(cmd) |
||
| 2318 | |||
| 2319 | View Code Duplication | def create_filter( |
|
| 2320 | self, |
||
| 2321 | name: str, |
||
| 2322 | *, |
||
| 2323 | filter_type: Optional[FilterType] = None, |
||
| 2324 | comment: Optional[str] = None, |
||
| 2325 | term: Optional[str] = None, |
||
| 2326 | ) -> Any: |
||
| 2327 | """Create a new filter |
||
| 2328 | |||
| 2329 | Arguments: |
||
| 2330 | name: Name of the new filter |
||
| 2331 | filter_type: Filter for entity type |
||
| 2332 | comment: Comment for the filter |
||
| 2333 | term: Filter term e.g. 'name=foo' |
||
| 2334 | |||
| 2335 | Returns: |
||
| 2336 | The response. See :py:meth:`send_command` for details. |
||
| 2337 | """ |
||
| 2338 | if not name: |
||
| 2339 | raise RequiredArgument( |
||
| 2340 | function=self.create_filter.__name__, argument="name" |
||
| 2341 | ) |
||
| 2342 | |||
| 2343 | cmd = XmlCommand("create_filter") |
||
| 2344 | _xmlname = cmd.add_element("name", name) |
||
| 2345 | |||
| 2346 | if comment: |
||
| 2347 | cmd.add_element("comment", comment) |
||
| 2348 | |||
| 2349 | if term: |
||
| 2350 | cmd.add_element("term", term) |
||
| 2351 | |||
| 2352 | if filter_type: |
||
| 2353 | if not isinstance(filter_type, self.types.FilterType): |
||
| 2354 | raise InvalidArgumentType( |
||
| 2355 | function=self.create_filter.__name__, |
||
| 2356 | argument="filter_type", |
||
| 2357 | arg_type=self.types.FilterType.__name__, |
||
| 2358 | ) |
||
| 2359 | |||
| 2360 | cmd.add_element("type", filter_type.value) |
||
| 2361 | |||
| 2362 | return self._send_xml_command(cmd) |
||
| 2363 | |||
| 2364 | View Code Duplication | def modify_filter( |
|
| 2365 | self, |
||
| 2366 | filter_id: str, |
||
| 2367 | *, |
||
| 2368 | comment: Optional[str] = None, |
||
| 2369 | name: Optional[str] = None, |
||
| 2370 | term: Optional[str] = None, |
||
| 2371 | filter_type: Optional[FilterType] = None, |
||
| 2372 | ) -> Any: |
||
| 2373 | """Modifies an existing filter. |
||
| 2374 | |||
| 2375 | Arguments: |
||
| 2376 | filter_id: UUID of the filter to be modified |
||
| 2377 | comment: Comment on filter. |
||
| 2378 | name: Name of filter. |
||
| 2379 | term: Filter term. |
||
| 2380 | filter_type: Resource type filter applies to. |
||
| 2381 | |||
| 2382 | Returns: |
||
| 2383 | The response. See :py:meth:`send_command` for details. |
||
| 2384 | """ |
||
| 2385 | if not filter_id: |
||
| 2386 | raise RequiredArgument( |
||
| 2387 | function=self.modify_filter.__name__, argument='filter_id' |
||
| 2388 | ) |
||
| 2389 | |||
| 2390 | cmd = XmlCommand("modify_filter") |
||
| 2391 | cmd.set_attribute("filter_id", filter_id) |
||
| 2392 | |||
| 2393 | if comment: |
||
| 2394 | cmd.add_element("comment", comment) |
||
| 2395 | |||
| 2396 | if name: |
||
| 2397 | cmd.add_element("name", name) |
||
| 2398 | |||
| 2399 | if term: |
||
| 2400 | cmd.add_element("term", term) |
||
| 2401 | |||
| 2402 | if filter_type: |
||
| 2403 | if not isinstance(filter_type, self.types.FilterType): |
||
| 2404 | raise InvalidArgumentType( |
||
| 2405 | function=self.modify_filter.__name__, |
||
| 2406 | argument='filter_type', |
||
| 2407 | arg_type=FilterType.__name__, |
||
| 2408 | ) |
||
| 2409 | cmd.add_element("type", filter_type.value) |
||
| 2410 | |||
| 2411 | return self._send_xml_command(cmd) |
||
| 2412 | |||
| 2413 | def create_schedule( |
||
| 2414 | self, |
||
| 2415 | name: str, |
||
| 2416 | icalendar: str, |
||
| 2417 | timezone: str, |
||
| 2418 | *, |
||
| 2419 | comment: Optional[str] = None, |
||
| 2420 | ) -> Any: |
||
| 2421 | """Create a new schedule based in `iCalendar`_ data. |
||
| 2422 | |||
| 2423 | Example: |
||
| 2424 | Requires https://pypi.org/project/icalendar/ |
||
| 2425 | |||
| 2426 | .. code-block:: python |
||
| 2427 | |||
| 2428 | import pytz |
||
| 2429 | |||
| 2430 | from datetime import datetime |
||
| 2431 | |||
| 2432 | from icalendar import Calendar, Event |
||
| 2433 | |||
| 2434 | cal = Calendar() |
||
| 2435 | |||
| 2436 | cal.add('prodid', '-//Foo Bar//') |
||
| 2437 | cal.add('version', '2.0') |
||
| 2438 | |||
| 2439 | event = Event() |
||
| 2440 | event.add('dtstamp', datetime.now(tz=pytz.UTC)) |
||
| 2441 | event.add('dtstart', datetime(2020, 1, 1, tzinfo=pytz.utc)) |
||
| 2442 | |||
| 2443 | cal.add_component(event) |
||
| 2444 | |||
| 2445 | gmp.create_schedule( |
||
| 2446 | name="My Schedule", |
||
| 2447 | icalendar=cal.to_ical(), |
||
| 2448 | timezone='UTC' |
||
| 2449 | ) |
||
| 2450 | |||
| 2451 | |||
| 2452 | Arguments: |
||
| 2453 | name: Name of the new schedule |
||
| 2454 | icalendar: `iCalendar`_ (RFC 5545) based data. |
||
| 2455 | timezone: Timezone to use for the icalender events e.g |
||
| 2456 | Europe/Berlin. If the datetime values in the icalendar data are |
||
| 2457 | missing timezone information this timezone gets applied. |
||
| 2458 | Otherwise the datetime values from the icalendar data are |
||
| 2459 | displayed in this timezone |
||
| 2460 | comment: Comment on schedule. |
||
| 2461 | |||
| 2462 | Returns: |
||
| 2463 | The response. See :py:meth:`send_command` for details. |
||
| 2464 | |||
| 2465 | .. _iCalendar: |
||
| 2466 | https://tools.ietf.org/html/rfc5545 |
||
| 2467 | """ |
||
| 2468 | if not name: |
||
| 2469 | raise RequiredArgument( |
||
| 2470 | function=self.create_schedule.__name__, argument='name' |
||
| 2471 | ) |
||
| 2472 | if not icalendar: |
||
| 2473 | raise RequiredArgument( |
||
| 2474 | function=self.create_schedule.__name__, argument='icalendar' |
||
| 2475 | ) |
||
| 2476 | if not timezone: |
||
| 2477 | raise RequiredArgument( |
||
| 2478 | function=self.create_schedule.__name__, argument='timezone' |
||
| 2479 | ) |
||
| 2480 | |||
| 2481 | cmd = XmlCommand("create_schedule") |
||
| 2482 | |||
| 2483 | cmd.add_element("name", name) |
||
| 2484 | cmd.add_element("icalendar", icalendar) |
||
| 2485 | cmd.add_element("timezone", timezone) |
||
| 2486 | |||
| 2487 | if comment: |
||
| 2488 | cmd.add_element("comment", comment) |
||
| 2489 | |||
| 2490 | return self._send_xml_command(cmd) |
||
| 2491 | |||
| 2492 | def modify_schedule( |
||
| 2493 | self, |
||
| 2494 | schedule_id: str, |
||
| 2495 | *, |
||
| 2496 | name: Optional[str] = None, |
||
| 2497 | icalendar: Optional[str] = None, |
||
| 2498 | timezone: Optional[str] = None, |
||
| 2499 | comment: Optional[str] = None, |
||
| 2500 | ) -> Any: |
||
| 2501 | """Modifies an existing schedule |
||
| 2502 | |||
| 2503 | Arguments: |
||
| 2504 | schedule_id: UUID of the schedule to be modified |
||
| 2505 | name: Name of the schedule |
||
| 2506 | icalendar: `iCalendar`_ (RFC 5545) based data. |
||
| 2507 | timezone: Timezone to use for the icalender events e.g |
||
| 2508 | Europe/Berlin. If the datetime values in the icalendar data are |
||
| 2509 | missing timezone information this timezone gets applied. |
||
| 2510 | Otherwise the datetime values from the icalendar data are |
||
| 2511 | displayed in this timezone |
||
| 2512 | commenhedule. |
||
| 2513 | |||
| 2514 | Returns: |
||
| 2515 | The response. See :py:meth:`send_command` for details. |
||
| 2516 | |||
| 2517 | .. _iCalendar: |
||
| 2518 | https://tools.ietf.org/html/rfc5545 |
||
| 2519 | """ |
||
| 2520 | if not schedule_id: |
||
| 2521 | raise RequiredArgument( |
||
| 2522 | function=self.modify_schedule.__name__, argument='schedule_id' |
||
| 2523 | ) |
||
| 2524 | |||
| 2525 | cmd = XmlCommand("modify_schedule") |
||
| 2526 | cmd.set_attribute("schedule_id", schedule_id) |
||
| 2527 | |||
| 2528 | if name: |
||
| 2529 | cmd.add_element("name", name) |
||
| 2530 | |||
| 2531 | if icalendar: |
||
| 2532 | cmd.add_element("icalendar", icalendar) |
||
| 2533 | |||
| 2534 | if timezone: |
||
| 2535 | cmd.add_element("timezone", timezone) |
||
| 2536 | |||
| 2537 | if comment: |
||
| 2538 | cmd.add_element("comment", comment) |
||
| 2539 | |||
| 2540 | return self._send_xml_command(cmd) |
||
| 2541 | |||
| 2542 | def clone_config(self, config_id: str) -> Any: |
||
| 2543 | """Clone a scan config from an existing one |
||
| 2544 | |||
| 2545 | Arguments: |
||
| 2546 | config_id: UUID of the existing scan config |
||
| 2547 | |||
| 2548 | Returns: |
||
| 2549 | The response. See :py:meth:`send_command` for details. |
||
| 2550 | """ |
||
| 2551 | if not config_id: |
||
| 2552 | raise RequiredArgument( |
||
| 2553 | function=self.clone_config.__name__, argument='config_id' |
||
| 2554 | ) |
||
| 2555 | |||
| 2556 | cmd = XmlCommand("create_config") |
||
| 2557 | cmd.add_element("copy", config_id) |
||
| 2558 | return self._send_xml_command(cmd) |
||
| 2559 | |||
| 2560 | def import_config(self, config: str) -> Any: |
||
| 2561 | """Import a scan config from XML |
||
| 2562 | |||
| 2563 | Arguments: |
||
| 2564 | config: Scan Config XML as string to import. This XML must |
||
| 2565 | contain a :code:`<get_configs_response>` root element. |
||
| 2566 | |||
| 2567 | Returns: |
||
| 2568 | The response. See :py:meth:`send_command` for details. |
||
| 2569 | """ |
||
| 2570 | if not config: |
||
| 2571 | raise RequiredArgument( |
||
| 2572 | function=self.import_config.__name__, argument='config' |
||
| 2573 | ) |
||
| 2574 | |||
| 2575 | cmd = XmlCommand("create_config") |
||
| 2576 | |||
| 2577 | try: |
||
| 2578 | cmd.append_xml_str(config) |
||
| 2579 | except etree.XMLSyntaxError as e: |
||
| 2580 | raise InvalidArgument( |
||
| 2581 | function=self.import_config.__name__, argument='config' |
||
| 2582 | ) from e |
||
| 2583 | |||
| 2584 | return self._send_xml_command(cmd) |
||
| 2585 | |||
| 2586 | def clone_credential(self, credential_id: str) -> Any: |
||
| 2587 | """Clone an existing credential |
||
| 2588 | |||
| 2589 | Arguments: |
||
| 2590 | credential_id: UUID of an existing credential to clone from |
||
| 2591 | |||
| 2592 | Returns: |
||
| 2593 | The response. See :py:meth:`send_command` for details. |
||
| 2594 | """ |
||
| 2595 | if not credential_id: |
||
| 2596 | raise RequiredArgument( |
||
| 2597 | function=self.clone_credential.__name__, |
||
| 2598 | argument='credential_id', |
||
| 2599 | ) |
||
| 2600 | |||
| 2601 | cmd = XmlCommand("create_credential") |
||
| 2602 | cmd.add_element("copy", credential_id) |
||
| 2603 | return self._send_xml_command(cmd) |
||
| 2604 | |||
| 2605 | def clone_filter(self, filter_id: str) -> Any: |
||
| 2606 | """Clone an existing filter |
||
| 2607 | |||
| 2608 | Arguments: |
||
| 2609 | filter_id: UUID of an existing filter to clone from |
||
| 2610 | |||
| 2611 | Returns: |
||
| 2612 | The response. See :py:meth:`send_command` for details. |
||
| 2613 | """ |
||
| 2614 | if not filter_id: |
||
| 2615 | raise RequiredArgument( |
||
| 2616 | function=self.clone_filter.__name__, argument='filter_id' |
||
| 2617 | ) |
||
| 2618 | |||
| 2619 | cmd = XmlCommand("create_filter") |
||
| 2620 | cmd.add_element("copy", filter_id) |
||
| 2621 | return self._send_xml_command(cmd) |
||
| 2622 | |||
| 2623 | def create_group( |
||
| 2624 | self, |
||
| 2625 | name: str, |
||
| 2626 | *, |
||
| 2627 | comment: Optional[str] = None, |
||
| 2628 | special: Optional[bool] = False, |
||
| 2629 | users: Optional[List[str]] = None, |
||
| 2630 | ) -> Any: |
||
| 2631 | """Create a new group |
||
| 2632 | |||
| 2633 | Arguments: |
||
| 2634 | name: Name of the new group |
||
| 2635 | comment: Comment for the group |
||
| 2636 | special: Create permission giving members full access to each |
||
| 2637 | other's entities |
||
| 2638 | users: List of user names to be in the group |
||
| 2639 | |||
| 2640 | Returns: |
||
| 2641 | The response. See :py:meth:`send_command` for details. |
||
| 2642 | """ |
||
| 2643 | if not name: |
||
| 2644 | raise RequiredArgument( |
||
| 2645 | function=self.create_group.__name__, argument='name' |
||
| 2646 | ) |
||
| 2647 | |||
| 2648 | cmd = XmlCommand("create_group") |
||
| 2649 | cmd.add_element("name", name) |
||
| 2650 | |||
| 2651 | if comment: |
||
| 2652 | cmd.add_element("comment", comment) |
||
| 2653 | |||
| 2654 | if special: |
||
| 2655 | _xmlspecial = cmd.add_element("specials") |
||
| 2656 | _xmlspecial.add_element("full") |
||
| 2657 | |||
| 2658 | if users: |
||
| 2659 | cmd.add_element("users", to_comma_list(users)) |
||
| 2660 | |||
| 2661 | return self._send_xml_command(cmd) |
||
| 2662 | |||
| 2663 | def clone_group(self, group_id: str) -> Any: |
||
| 2664 | """Clone an existing group |
||
| 2665 | |||
| 2666 | Arguments: |
||
| 2667 | group_id: UUID of an existing group to clone from |
||
| 2668 | |||
| 2669 | Returns: |
||
| 2670 | The response. See :py:meth:`send_command` for details. |
||
| 2671 | """ |
||
| 2672 | if not group_id: |
||
| 2673 | raise RequiredArgument( |
||
| 2674 | function=self.clone_group.__name__, argument='group_id' |
||
| 2675 | ) |
||
| 2676 | |||
| 2677 | cmd = XmlCommand("create_group") |
||
| 2678 | cmd.add_element("copy", group_id) |
||
| 2679 | return self._send_xml_command(cmd) |
||
| 2680 | |||
| 2681 | def create_host(self, name: str, *, comment: Optional[str] = None) -> Any: |
||
| 2682 | """Create a new host asset |
||
| 2683 | |||
| 2684 | Arguments: |
||
| 2685 | name: Name for the new host asset |
||
| 2686 | comment: Comment for the new host asset |
||
| 2687 | |||
| 2688 | Returns: |
||
| 2689 | The response. See :py:meth:`send_command` for details. |
||
| 2690 | """ |
||
| 2691 | if not name: |
||
| 2692 | raise RequiredArgument( |
||
| 2693 | function=self.create_host.__name__, argument='name' |
||
| 2694 | ) |
||
| 2695 | |||
| 2696 | cmd = XmlCommand("create_asset") |
||
| 2697 | asset = cmd.add_element("asset") |
||
| 2698 | asset.add_element("type", "host") # ignored for gmp7, required for gmp8 |
||
| 2699 | asset.add_element("name", name) |
||
| 2700 | |||
| 2701 | if comment: |
||
| 2702 | asset.add_element("comment", comment) |
||
| 2703 | |||
| 2704 | return self._send_xml_command(cmd) |
||
| 2705 | |||
| 2706 | def clone_permission(self, permission_id: str) -> Any: |
||
| 2707 | """Clone an existing permission |
||
| 2708 | |||
| 2709 | Arguments: |
||
| 2710 | permission_id: UUID of an existing permission to clone from |
||
| 2711 | |||
| 2712 | Returns: |
||
| 2713 | The response. See :py:meth:`send_command` for details. |
||
| 2714 | """ |
||
| 2715 | if not permission_id: |
||
| 2716 | raise RequiredArgument( |
||
| 2717 | function=self.clone_permission.__name__, |
||
| 2718 | argument='permission_id', |
||
| 2719 | ) |
||
| 2720 | |||
| 2721 | cmd = XmlCommand("create_permission") |
||
| 2722 | cmd.add_element("copy", permission_id) |
||
| 2723 | return self._send_xml_command(cmd) |
||
| 2724 | |||
| 2725 | def clone_report_format( |
||
| 2726 | self, report_format_id: [Union[str, ReportFormatType]] |
||
| 2727 | ) -> Any: |
||
| 2728 | """Clone a report format from an existing one |
||
| 2729 | |||
| 2730 | Arguments: |
||
| 2731 | report_format_id: UUID of the existing report format |
||
| 2732 | or ReportFormatType (enum) |
||
| 2733 | |||
| 2734 | Returns: |
||
| 2735 | The response. See :py:meth:`send_command` for details. |
||
| 2736 | """ |
||
| 2737 | if not report_format_id: |
||
| 2738 | raise RequiredArgument( |
||
| 2739 | function=self.clone_report_format.__name__, |
||
| 2740 | argument='report_format_id', |
||
| 2741 | ) |
||
| 2742 | |||
| 2743 | cmd = XmlCommand("create_report_format") |
||
| 2744 | |||
| 2745 | if isinstance(report_format_id, ReportFormatType): |
||
| 2746 | report_format_id = report_format_id.value |
||
| 2747 | |||
| 2748 | cmd.add_element("copy", report_format_id) |
||
| 2749 | return self._send_xml_command(cmd) |
||
| 2750 | |||
| 2751 | def import_report_format(self, report_format: str) -> Any: |
||
| 2752 | """Import a report format from XML |
||
| 2753 | |||
| 2754 | Arguments: |
||
| 2755 | report_format: Report format XML as string to import. This XML must |
||
| 2756 | contain a :code:`<get_report_formats_response>` root element. |
||
| 2757 | |||
| 2758 | Returns: |
||
| 2759 | The response. See :py:meth:`send_command` for details. |
||
| 2760 | """ |
||
| 2761 | if not report_format: |
||
| 2762 | raise RequiredArgument( |
||
| 2763 | function=self.import_report_format.__name__, |
||
| 2764 | argument='report_format', |
||
| 2765 | ) |
||
| 2766 | |||
| 2767 | cmd = XmlCommand("create_report_format") |
||
| 2768 | |||
| 2769 | try: |
||
| 2770 | cmd.append_xml_str(report_format) |
||
| 2771 | except etree.XMLSyntaxError as e: |
||
| 2772 | raise InvalidArgument( |
||
| 2773 | function=self.import_report_format.__name__, |
||
| 2774 | argument='report_format', |
||
| 2775 | ) from e |
||
| 2776 | |||
| 2777 | return self._send_xml_command(cmd) |
||
| 2778 | |||
| 2779 | def create_role( |
||
| 2780 | self, |
||
| 2781 | name: str, |
||
| 2782 | *, |
||
| 2783 | comment: Optional[str] = None, |
||
| 2784 | users: Optional[List[str]] = None, |
||
| 2785 | ) -> Any: |
||
| 2786 | """Create a new role |
||
| 2787 | |||
| 2788 | Arguments: |
||
| 2789 | name: Name of the role |
||
| 2790 | comment: Comment for the role |
||
| 2791 | users: List of user names to add to the role |
||
| 2792 | |||
| 2793 | Returns: |
||
| 2794 | The response. See :py:meth:`send_command` for details. |
||
| 2795 | """ |
||
| 2796 | |||
| 2797 | if not name: |
||
| 2798 | raise RequiredArgument( |
||
| 2799 | function=self.create_role.__name__, argument='name' |
||
| 2800 | ) |
||
| 2801 | |||
| 2802 | cmd = XmlCommand("create_role") |
||
| 2803 | cmd.add_element("name", name) |
||
| 2804 | |||
| 2805 | if comment: |
||
| 2806 | cmd.add_element("comment", comment) |
||
| 2807 | |||
| 2808 | if users: |
||
| 2809 | cmd.add_element("users", to_comma_list(users)) |
||
| 2810 | |||
| 2811 | return self._send_xml_command(cmd) |
||
| 2812 | |||
| 2813 | def clone_role(self, role_id: str) -> Any: |
||
| 2814 | """Clone an existing role |
||
| 2815 | |||
| 2816 | Arguments: |
||
| 2817 | role_id: UUID of an existing role to clone from |
||
| 2818 | |||
| 2819 | Returns: |
||
| 2820 | The response. See :py:meth:`send_command` for details. |
||
| 2821 | """ |
||
| 2822 | if not role_id: |
||
| 2823 | raise RequiredArgument( |
||
| 2824 | function=self.clone_role.__name__, argument='role_id' |
||
| 2825 | ) |
||
| 2826 | |||
| 2827 | cmd = XmlCommand("create_role") |
||
| 2828 | cmd.add_element("copy", role_id) |
||
| 2829 | return self._send_xml_command(cmd) |
||
| 2830 | |||
| 2831 | def create_scanner( |
||
| 2832 | self, |
||
| 2833 | name: str, |
||
| 2834 | host: str, |
||
| 2835 | port: int, |
||
| 2836 | scanner_type: ScannerType, |
||
| 2837 | credential_id: str, |
||
| 2838 | *, |
||
| 2839 | ca_pub: Optional[str] = None, |
||
| 2840 | comment: Optional[str] = None, |
||
| 2841 | ) -> Any: |
||
| 2842 | """Create a new scanner |
||
| 2843 | |||
| 2844 | Arguments: |
||
| 2845 | name: Name of the scanner |
||
| 2846 | host: The host of the scanner |
||
| 2847 | port: The port of the scanner |
||
| 2848 | scanner_type: Type of the scanner. |
||
| 2849 | credential_id: UUID of client certificate credential for the |
||
| 2850 | scanner |
||
| 2851 | ca_pub: Certificate of CA to verify scanner certificate |
||
| 2852 | comment: Comment for the scanner |
||
| 2853 | Returns: |
||
| 2854 | The response. See :py:meth:`send_command` for details. |
||
| 2855 | """ |
||
| 2856 | if not name: |
||
| 2857 | raise RequiredArgument( |
||
| 2858 | function=self.create_scanner.__name__, argument='name' |
||
| 2859 | ) |
||
| 2860 | |||
| 2861 | if not host: |
||
| 2862 | raise RequiredArgument( |
||
| 2863 | function=self.create_scanner.__name__, argument='host' |
||
| 2864 | ) |
||
| 2865 | |||
| 2866 | if not port: |
||
| 2867 | raise RequiredArgument( |
||
| 2868 | function=self.create_scanner.__name__, argument='port' |
||
| 2869 | ) |
||
| 2870 | |||
| 2871 | if not scanner_type: |
||
| 2872 | raise RequiredArgument( |
||
| 2873 | function=self.create_scanner.__name__, argument='scanner_type' |
||
| 2874 | ) |
||
| 2875 | |||
| 2876 | if not credential_id: |
||
| 2877 | raise RequiredArgument( |
||
| 2878 | function=self.create_scanner.__name__, argument='credential_id' |
||
| 2879 | ) |
||
| 2880 | |||
| 2881 | if not isinstance(scanner_type, self.types.ScannerType): |
||
| 2882 | raise InvalidArgumentType( |
||
| 2883 | function=self.create_scanner.__name__, |
||
| 2884 | argument='scanner_type', |
||
| 2885 | arg_type=self.types.ScannerType.__name__, |
||
| 2886 | ) |
||
| 2887 | |||
| 2888 | cmd = XmlCommand("create_scanner") |
||
| 2889 | cmd.add_element("name", name) |
||
| 2890 | cmd.add_element("host", host) |
||
| 2891 | cmd.add_element("port", str(port)) |
||
| 2892 | cmd.add_element("type", scanner_type.value) |
||
| 2893 | |||
| 2894 | if ca_pub: |
||
| 2895 | cmd.add_element("ca_pub", ca_pub) |
||
| 2896 | |||
| 2897 | cmd.add_element("credential", attrs={"id": str(credential_id)}) |
||
| 2898 | |||
| 2899 | if comment: |
||
| 2900 | cmd.add_element("comment", comment) |
||
| 2901 | |||
| 2902 | return self._send_xml_command(cmd) |
||
| 2903 | |||
| 2904 | def clone_scanner(self, scanner_id: str) -> Any: |
||
| 2905 | """Clone an existing scanner |
||
| 2906 | |||
| 2907 | Arguments: |
||
| 2908 | scanner_id: UUID of an existing scanner to clone from |
||
| 2909 | |||
| 2910 | Returns: |
||
| 2911 | The response. See :py:meth:`send_command` for details. |
||
| 2912 | """ |
||
| 2913 | if not scanner_id: |
||
| 2914 | raise RequiredArgument( |
||
| 2915 | function=self.clone_scanner.__name__, argument='scanner_id' |
||
| 2916 | ) |
||
| 2917 | |||
| 2918 | cmd = XmlCommand("create_scanner") |
||
| 2919 | cmd.add_element("copy", scanner_id) |
||
| 2920 | return self._send_xml_command(cmd) |
||
| 2921 | |||
| 2922 | def clone_schedule(self, schedule_id: str) -> Any: |
||
| 2923 | """Clone an existing schedule |
||
| 2924 | |||
| 2925 | Arguments: |
||
| 2926 | schedule_id: UUID of an existing schedule to clone from |
||
| 2927 | |||
| 2928 | Returns: |
||
| 2929 | The response. See :py:meth:`send_command` for details. |
||
| 2930 | """ |
||
| 2931 | if not schedule_id: |
||
| 2932 | raise RequiredArgument( |
||
| 2933 | function=self.clone_schedule.__name__, argument='schedule_id' |
||
| 2934 | ) |
||
| 2935 | |||
| 2936 | cmd = XmlCommand("create_schedule") |
||
| 2937 | cmd.add_element("copy", schedule_id) |
||
| 2938 | return self._send_xml_command(cmd) |
||
| 2939 | |||
| 2940 | def clone_tag(self, tag_id: str) -> Any: |
||
| 2941 | """Clone an existing tag |
||
| 2942 | |||
| 2943 | Arguments: |
||
| 2944 | tag_id: UUID of an existing tag to clone from |
||
| 2945 | |||
| 2946 | Returns: |
||
| 2947 | The response. See :py:meth:`send_command` for details. |
||
| 2948 | """ |
||
| 2949 | if not tag_id: |
||
| 2950 | raise RequiredArgument( |
||
| 2951 | function=self.clone_tag.__name__, argument='tag_id' |
||
| 2952 | ) |
||
| 2953 | |||
| 2954 | cmd = XmlCommand("create_tag") |
||
| 2955 | cmd.add_element("copy", tag_id) |
||
| 2956 | return self._send_xml_command(cmd) |
||
| 2957 | |||
| 2958 | def create_user( |
||
| 2959 | self, |
||
| 2960 | name: str, |
||
| 2961 | *, |
||
| 2962 | password: Optional[str] = None, |
||
| 2963 | hosts: Optional[List[str]] = None, |
||
| 2964 | hosts_allow: Optional[bool] = False, |
||
| 2965 | ifaces: Optional[List[str]] = None, |
||
| 2966 | ifaces_allow: Optional[bool] = False, |
||
| 2967 | role_ids: Optional[List[str]] = None, |
||
| 2968 | ) -> Any: |
||
| 2969 | """Create a new user |
||
| 2970 | |||
| 2971 | Arguments: |
||
| 2972 | name: Name of the user |
||
| 2973 | password: Password of the user |
||
| 2974 | hosts: A list of host addresses (IPs, DNS names) |
||
| 2975 | hosts_allow: If True allow only access to passed hosts otherwise |
||
| 2976 | deny access. Default is False for deny hosts. |
||
| 2977 | ifaces: A list of interface names |
||
| 2978 | ifaces_allow: If True allow only access to passed interfaces |
||
| 2979 | otherwise deny access. Default is False for deny interfaces. |
||
| 2980 | role_ids: A list of role UUIDs for the user |
||
| 2981 | |||
| 2982 | Returns: |
||
| 2983 | The response. See :py:meth:`send_command` for details. |
||
| 2984 | """ |
||
| 2985 | if not name: |
||
| 2986 | raise RequiredArgument( |
||
| 2987 | function=self.create_user.__name__, argument='name' |
||
| 2988 | ) |
||
| 2989 | |||
| 2990 | cmd = XmlCommand("create_user") |
||
| 2991 | cmd.add_element("name", name) |
||
| 2992 | |||
| 2993 | if password: |
||
| 2994 | cmd.add_element("password", password) |
||
| 2995 | |||
| 2996 | if hosts: |
||
| 2997 | cmd.add_element( |
||
| 2998 | "hosts", |
||
| 2999 | to_comma_list(hosts), |
||
| 3000 | attrs={"allow": to_bool(hosts_allow)}, |
||
| 3001 | ) |
||
| 3002 | |||
| 3003 | if ifaces: |
||
| 3004 | cmd.add_element( |
||
| 3005 | "ifaces", |
||
| 3006 | to_comma_list(ifaces), |
||
| 3007 | attrs={"allow": to_bool(ifaces_allow)}, |
||
| 3008 | ) |
||
| 3009 | |||
| 3010 | if role_ids: |
||
| 3011 | for role in role_ids: |
||
| 3012 | cmd.add_element("role", attrs={"id": role}) |
||
| 3013 | |||
| 3014 | return self._send_xml_command(cmd) |
||
| 3015 | |||
| 3016 | def clone_user(self, user_id: str) -> Any: |
||
| 3017 | """Clone an existing user |
||
| 3018 | |||
| 3019 | Arguments: |
||
| 3020 | user_id: UUID of existing user to clone from |
||
| 3021 | |||
| 3022 | Returns: |
||
| 3023 | The response. See :py:meth:`send_command` for details. |
||
| 3024 | """ |
||
| 3025 | if not user_id: |
||
| 3026 | raise RequiredArgument( |
||
| 3027 | function=self.clone_user.__name__, argument='user_id' |
||
| 3028 | ) |
||
| 3029 | |||
| 3030 | cmd = XmlCommand("create_user") |
||
| 3031 | cmd.add_element("copy", user_id) |
||
| 3032 | return self._send_xml_command(cmd) |
||
| 3033 | |||
| 3034 | def delete_asset( |
||
| 3035 | self, *, asset_id: Optional[str] = None, report_id: Optional[str] = None |
||
| 3036 | ) -> Any: |
||
| 3037 | """Deletes an existing asset |
||
| 3038 | |||
| 3039 | Arguments: |
||
| 3040 | asset_id: UUID of the single asset to delete. |
||
| 3041 | report_id: UUID of report from which to get all |
||
| 3042 | assets to delete. |
||
| 3043 | """ |
||
| 3044 | if not asset_id and not report_id: |
||
| 3045 | raise RequiredArgument( |
||
| 3046 | function=self.delete_asset.__name__, |
||
| 3047 | argument='asset_id or report_id', |
||
| 3048 | ) |
||
| 3049 | |||
| 3050 | cmd = XmlCommand("delete_asset") |
||
| 3051 | if asset_id: |
||
| 3052 | cmd.set_attribute("asset_id", asset_id) |
||
| 3053 | else: |
||
| 3054 | cmd.set_attribute("report_id", report_id) |
||
| 3055 | |||
| 3056 | return self._send_xml_command(cmd) |
||
| 3057 | |||
| 3058 | def delete_config( |
||
| 3059 | self, config_id: str, *, ultimate: Optional[bool] = False |
||
| 3060 | ) -> Any: |
||
| 3061 | """Deletes an existing config |
||
| 3062 | |||
| 3063 | Arguments: |
||
| 3064 | config_id: UUID of the config to be deleted. |
||
| 3065 | ultimate: Whether to remove entirely, or to the trashcan. |
||
| 3066 | """ |
||
| 3067 | if not config_id: |
||
| 3068 | raise RequiredArgument( |
||
| 3069 | function=self.delete_config.__name__, argument='config_id' |
||
| 3070 | ) |
||
| 3071 | |||
| 3072 | cmd = XmlCommand("delete_config") |
||
| 3073 | cmd.set_attribute("config_id", config_id) |
||
| 3074 | cmd.set_attribute("ultimate", to_bool(ultimate)) |
||
| 3075 | |||
| 3076 | return self._send_xml_command(cmd) |
||
| 3077 | |||
| 3078 | def delete_credential( |
||
| 3079 | self, credential_id: str, *, ultimate: Optional[bool] = False |
||
| 3080 | ) -> Any: |
||
| 3081 | """Deletes an existing credential |
||
| 3082 | |||
| 3083 | Arguments: |
||
| 3084 | credential_id: UUID of the credential to be deleted. |
||
| 3085 | ultimate: Whether to remove entirely, or to the trashcan. |
||
| 3086 | """ |
||
| 3087 | if not credential_id: |
||
| 3088 | raise RequiredArgument( |
||
| 3089 | function=self.delete_credential.__name__, |
||
| 3090 | argument='credential_id', |
||
| 3091 | ) |
||
| 3092 | |||
| 3093 | cmd = XmlCommand("delete_credential") |
||
| 3094 | cmd.set_attribute("credential_id", credential_id) |
||
| 3095 | cmd.set_attribute("ultimate", to_bool(ultimate)) |
||
| 3096 | |||
| 3097 | return self._send_xml_command(cmd) |
||
| 3098 | |||
| 3099 | def delete_filter( |
||
| 3100 | self, filter_id: str, *, ultimate: Optional[bool] = False |
||
| 3101 | ) -> Any: |
||
| 3102 | """Deletes an existing filter |
||
| 3103 | |||
| 3104 | Arguments: |
||
| 3105 | filter_id: UUID of the filter to be deleted. |
||
| 3106 | ultimate: Whether to remove entirely, or to the trashcan. |
||
| 3107 | """ |
||
| 3108 | if not filter_id: |
||
| 3109 | raise RequiredArgument( |
||
| 3110 | function=self.delete_filter.__name__, argument='filter_id' |
||
| 3111 | ) |
||
| 3112 | |||
| 3113 | cmd = XmlCommand("delete_filter") |
||
| 3114 | cmd.set_attribute("filter_id", filter_id) |
||
| 3115 | cmd.set_attribute("ultimate", to_bool(ultimate)) |
||
| 3116 | |||
| 3117 | return self._send_xml_command(cmd) |
||
| 3118 | |||
| 3119 | def delete_group( |
||
| 3120 | self, group_id: str, *, ultimate: Optional[bool] = False |
||
| 3121 | ) -> Any: |
||
| 3122 | """Deletes an existing group |
||
| 3123 | |||
| 3124 | Arguments: |
||
| 3125 | group_id: UUID of the group to be deleted. |
||
| 3126 | ultimate: Whether to remove entirely, or to the trashcan. |
||
| 3127 | """ |
||
| 3128 | if not group_id: |
||
| 3129 | raise RequiredArgument( |
||
| 3130 | function=self.delete_group.__name__, argument='group_id' |
||
| 3131 | ) |
||
| 3132 | |||
| 3133 | cmd = XmlCommand("delete_group") |
||
| 3134 | cmd.set_attribute("group_id", group_id) |
||
| 3135 | cmd.set_attribute("ultimate", to_bool(ultimate)) |
||
| 3136 | |||
| 3137 | return self._send_xml_command(cmd) |
||
| 3138 | |||
| 3139 | def delete_permission( |
||
| 3140 | self, permission_id: str, *, ultimate: Optional[bool] = False |
||
| 3141 | ) -> Any: |
||
| 3142 | """Deletes an existing permission |
||
| 3143 | |||
| 3144 | Arguments: |
||
| 3145 | permission_id: UUID of the permission to be deleted. |
||
| 3146 | ultimate: Whether to remove entirely, or to the trashcan. |
||
| 3147 | """ |
||
| 3148 | if not permission_id: |
||
| 3149 | raise RequiredArgument( |
||
| 3150 | function=self.delete_permission.__name__, |
||
| 3151 | argument='permission_id', |
||
| 3152 | ) |
||
| 3153 | |||
| 3154 | cmd = XmlCommand("delete_permission") |
||
| 3155 | cmd.set_attribute("permission_id", permission_id) |
||
| 3156 | cmd.set_attribute("ultimate", to_bool(ultimate)) |
||
| 3157 | |||
| 3158 | return self._send_xml_command(cmd) |
||
| 3159 | |||
| 3160 | def delete_report_format( |
||
| 3161 | self, |
||
| 3162 | report_format_id: Optional[Union[str, ReportFormatType]] = None, |
||
| 3163 | *, |
||
| 3164 | ultimate: Optional[bool] = False, |
||
| 3165 | ) -> Any: |
||
| 3166 | """Deletes an existing report format |
||
| 3167 | |||
| 3168 | Arguments: |
||
| 3169 | report_format_id: UUID of the report format to be deleted. |
||
| 3170 | or ReportFormatType (enum) |
||
| 3171 | ultimate: Whether to remove entirely, or to the trashcan. |
||
| 3172 | """ |
||
| 3173 | if not report_format_id: |
||
| 3174 | raise RequiredArgument( |
||
| 3175 | function=self.delete_report_format.__name__, |
||
| 3176 | argument='report_format_id', |
||
| 3177 | ) |
||
| 3178 | |||
| 3179 | cmd = XmlCommand("delete_report_format") |
||
| 3180 | |||
| 3181 | if isinstance(report_format_id, ReportFormatType): |
||
| 3182 | report_format_id = report_format_id.value |
||
| 3183 | |||
| 3184 | cmd.set_attribute("report_format_id", report_format_id) |
||
| 3185 | |||
| 3186 | cmd.set_attribute("ultimate", to_bool(ultimate)) |
||
| 3187 | |||
| 3188 | return self._send_xml_command(cmd) |
||
| 3189 | |||
| 3190 | def delete_role( |
||
| 3191 | self, role_id: str, *, ultimate: Optional[bool] = False |
||
| 3192 | ) -> Any: |
||
| 3193 | """Deletes an existing role |
||
| 3194 | |||
| 3195 | Arguments: |
||
| 3196 | role_id: UUID of the role to be deleted. |
||
| 3197 | ultimate: Whether to remove entirely, or to the trashcan. |
||
| 3198 | """ |
||
| 3199 | if not role_id: |
||
| 3200 | raise RequiredArgument( |
||
| 3201 | function=self.delete_role.__name__, argument='role_id' |
||
| 3202 | ) |
||
| 3203 | |||
| 3204 | cmd = XmlCommand("delete_role") |
||
| 3205 | cmd.set_attribute("role_id", role_id) |
||
| 3206 | cmd.set_attribute("ultimate", to_bool(ultimate)) |
||
| 3207 | |||
| 3208 | return self._send_xml_command(cmd) |
||
| 3209 | |||
| 3210 | def delete_scanner( |
||
| 3211 | self, scanner_id: str, *, ultimate: Optional[bool] = False |
||
| 3212 | ) -> Any: |
||
| 3213 | """Deletes an existing scanner |
||
| 3214 | |||
| 3215 | Arguments: |
||
| 3216 | scanner_id: UUID of the scanner to be deleted. |
||
| 3217 | ultimate: Whether to remove entirely, or to the trashcan. |
||
| 3218 | """ |
||
| 3219 | if not scanner_id: |
||
| 3220 | raise RequiredArgument( |
||
| 3221 | function=self.delete_scanner.__name__, argument='scanner_id' |
||
| 3222 | ) |
||
| 3223 | |||
| 3224 | cmd = XmlCommand("delete_scanner") |
||
| 3225 | cmd.set_attribute("scanner_id", scanner_id) |
||
| 3226 | cmd.set_attribute("ultimate", to_bool(ultimate)) |
||
| 3227 | |||
| 3228 | return self._send_xml_command(cmd) |
||
| 3229 | |||
| 3230 | def delete_schedule( |
||
| 3231 | self, schedule_id: str, *, ultimate: Optional[bool] = False |
||
| 3232 | ) -> Any: |
||
| 3233 | """Deletes an existing schedule |
||
| 3234 | |||
| 3235 | Arguments: |
||
| 3236 | schedule_id: UUID of the schedule to be deleted. |
||
| 3237 | ultimate: Whether to remove entirely, or to the trashcan. |
||
| 3238 | """ |
||
| 3239 | if not schedule_id: |
||
| 3240 | raise RequiredArgument( |
||
| 3241 | function=self.delete_schedule.__name__, argument='schedule_id' |
||
| 3242 | ) |
||
| 3243 | |||
| 3244 | cmd = XmlCommand("delete_schedule") |
||
| 3245 | cmd.set_attribute("schedule_id", schedule_id) |
||
| 3246 | cmd.set_attribute("ultimate", to_bool(ultimate)) |
||
| 3247 | |||
| 3248 | return self._send_xml_command(cmd) |
||
| 3249 | |||
| 3250 | def delete_tag( |
||
| 3251 | self, tag_id: str, *, ultimate: Optional[bool] = False |
||
| 3252 | ) -> Any: |
||
| 3253 | """Deletes an existing tag |
||
| 3254 | |||
| 3255 | Arguments: |
||
| 3256 | tag_id: UUID of the tag to be deleted. |
||
| 3257 | ultimate: Whether to remove entirely, or to the trashcan. |
||
| 3258 | """ |
||
| 3259 | if not tag_id: |
||
| 3260 | raise RequiredArgument( |
||
| 3261 | function=self.delete_tag.__name__, argument='tag_id' |
||
| 3262 | ) |
||
| 3263 | |||
| 3264 | cmd = XmlCommand("delete_tag") |
||
| 3265 | cmd.set_attribute("tag_id", tag_id) |
||
| 3266 | cmd.set_attribute("ultimate", to_bool(ultimate)) |
||
| 3267 | |||
| 3268 | return self._send_xml_command(cmd) |
||
| 3269 | |||
| 3270 | def delete_user( |
||
| 3271 | self, |
||
| 3272 | user_id: str = None, |
||
| 3273 | *, |
||
| 3274 | name: Optional[str] = None, |
||
| 3275 | inheritor_id: Optional[str] = None, |
||
| 3276 | inheritor_name: Optional[str] = None, |
||
| 3277 | ) -> Any: |
||
| 3278 | """Deletes an existing user |
||
| 3279 | |||
| 3280 | Either user_id or name must be passed. |
||
| 3281 | |||
| 3282 | Arguments: |
||
| 3283 | user_id: UUID of the task to be deleted. |
||
| 3284 | name: The name of the user to be deleted. |
||
| 3285 | inheritor_id: The ID of the inheriting user or "self". Overrides |
||
| 3286 | inheritor_name. |
||
| 3287 | inheritor_name: The name of the inheriting user. |
||
| 3288 | |||
| 3289 | """ |
||
| 3290 | if not user_id and not name: |
||
| 3291 | raise RequiredArgument( |
||
| 3292 | function=self.delete_user.__name__, argument='user_id or name' |
||
| 3293 | ) |
||
| 3294 | |||
| 3295 | cmd = XmlCommand("delete_user") |
||
| 3296 | |||
| 3297 | if user_id: |
||
| 3298 | cmd.set_attribute("user_id", user_id) |
||
| 3299 | |||
| 3300 | if name: |
||
| 3301 | cmd.set_attribute("name", name) |
||
| 3302 | |||
| 3303 | if inheritor_id: |
||
| 3304 | cmd.set_attribute("inheritor_id", inheritor_id) |
||
| 3305 | if inheritor_name: |
||
| 3306 | cmd.set_attribute("inheritor_name", inheritor_name) |
||
| 3307 | |||
| 3308 | return self._send_xml_command(cmd) |
||
| 3309 | |||
| 3310 | def describe_auth(self) -> Any: |
||
| 3311 | """Describe authentication methods |
||
| 3312 | |||
| 3313 | Returns a list of all used authentication methods if such a list is |
||
| 3314 | available. |
||
| 3315 | |||
| 3316 | Returns: |
||
| 3317 | The response. See :py:meth:`send_command` for details. |
||
| 3318 | """ |
||
| 3319 | return self._send_xml_command(XmlCommand("describe_auth")) |
||
| 3320 | |||
| 3321 | def empty_trashcan(self) -> Any: |
||
| 3322 | """Empty the trashcan |
||
| 3323 | |||
| 3324 | Remove all entities from the trashcan. **Attention:** this command can |
||
| 3325 | not be reverted |
||
| 3326 | |||
| 3327 | Returns: |
||
| 3328 | The response. See :py:meth:`send_command` for details. |
||
| 3329 | """ |
||
| 3330 | return self._send_xml_command(XmlCommand("empty_trashcan")) |
||
| 3331 | |||
| 3332 | def get_assets( |
||
| 3333 | self, |
||
| 3334 | asset_type: AssetType, |
||
| 3335 | *, |
||
| 3336 | filter: Optional[str] = None, |
||
| 3337 | filter_id: Optional[str] = None, |
||
| 3338 | ) -> Any: |
||
| 3339 | """Request a list of assets |
||
| 3340 | |||
| 3341 | Arguments: |
||
| 3342 | asset_type: Either 'os' or 'host' |
||
| 3343 | filter: Filter term to use for the query |
||
| 3344 | filter_id: UUID of an existing filter to use for the query |
||
| 3345 | |||
| 3346 | Returns: |
||
| 3347 | The response. See :py:meth:`send_command` for details. |
||
| 3348 | """ |
||
| 3349 | if not isinstance(asset_type, AssetType): |
||
| 3350 | raise InvalidArgumentType( |
||
| 3351 | function=self.get_assets.__name__, |
||
| 3352 | argument='asset_type', |
||
| 3353 | arg_type=AssetType.__name__, |
||
| 3354 | ) |
||
| 3355 | |||
| 3356 | cmd = XmlCommand("get_assets") |
||
| 3357 | |||
| 3358 | cmd.set_attribute("type", asset_type.value) |
||
| 3359 | |||
| 3360 | add_filter(cmd, filter, filter_id) |
||
| 3361 | |||
| 3362 | return self._send_xml_command(cmd) |
||
| 3363 | |||
| 3364 | def get_asset(self, asset_id: str, asset_type: AssetType) -> Any: |
||
| 3365 | """Request a single asset |
||
| 3366 | |||
| 3367 | Arguments: |
||
| 3368 | asset_id: UUID of an existing asset |
||
| 3369 | asset_type: Either 'os' or 'host' |
||
| 3370 | |||
| 3371 | Returns: |
||
| 3372 | The response. See :py:meth:`send_command` for details. |
||
| 3373 | """ |
||
| 3374 | cmd = XmlCommand("get_assets") |
||
| 3375 | |||
| 3376 | if not isinstance(asset_type, AssetType): |
||
| 3377 | raise InvalidArgumentType( |
||
| 3378 | function=self.get_asset.__name__, |
||
| 3379 | argument='asset_type', |
||
| 3380 | arg_type=AssetType.__name__, |
||
| 3381 | ) |
||
| 3382 | |||
| 3383 | if not asset_id: |
||
| 3384 | raise RequiredArgument( |
||
| 3385 | function=self.get_asset.__name__, argument='asset_id' |
||
| 3386 | ) |
||
| 3387 | |||
| 3388 | cmd.set_attribute("asset_id", asset_id) |
||
| 3389 | cmd.set_attribute("type", asset_type.value) |
||
| 3390 | |||
| 3391 | return self._send_xml_command(cmd) |
||
| 3392 | |||
| 3393 | View Code Duplication | def get_credentials( |
|
| 3394 | self, |
||
| 3395 | *, |
||
| 3396 | filter: Optional[str] = None, |
||
| 3397 | filter_id: Optional[str] = None, |
||
| 3398 | scanners: Optional[bool] = None, |
||
| 3399 | trash: Optional[bool] = None, |
||
| 3400 | targets: Optional[bool] = None, |
||
| 3401 | ) -> Any: |
||
| 3402 | """Request a list of credentials |
||
| 3403 | |||
| 3404 | Arguments: |
||
| 3405 | filter: Filter term to use for the query |
||
| 3406 | filter_id: UUID of an existing filter to use for the query |
||
| 3407 | scanners: Whether to include a list of scanners using the |
||
| 3408 | credentials |
||
| 3409 | trash: Whether to get the trashcan credentials instead |
||
| 3410 | targets: Whether to include a list of targets using the credentials |
||
| 3411 | |||
| 3412 | Returns: |
||
| 3413 | The response. See :py:meth:`send_command` for details. |
||
| 3414 | """ |
||
| 3415 | cmd = XmlCommand("get_credentials") |
||
| 3416 | |||
| 3417 | add_filter(cmd, filter, filter_id) |
||
| 3418 | |||
| 3419 | if scanners is not None: |
||
| 3420 | cmd.set_attribute("scanners", to_bool(scanners)) |
||
| 3421 | |||
| 3422 | if trash is not None: |
||
| 3423 | cmd.set_attribute("trash", to_bool(trash)) |
||
| 3424 | |||
| 3425 | if targets is not None: |
||
| 3426 | cmd.set_attribute("targets", to_bool(targets)) |
||
| 3427 | |||
| 3428 | return self._send_xml_command(cmd) |
||
| 3429 | |||
| 3430 | def get_credential( |
||
| 3431 | self, |
||
| 3432 | credential_id: str, |
||
| 3433 | *, |
||
| 3434 | scanners: Optional[bool] = None, |
||
| 3435 | targets: Optional[bool] = None, |
||
| 3436 | credential_format: Optional[CredentialFormat] = None, |
||
| 3437 | ) -> Any: |
||
| 3438 | """Request a single credential |
||
| 3439 | |||
| 3440 | Arguments: |
||
| 3441 | credential_id: UUID of an existing credential |
||
| 3442 | scanners: Whether to include a list of scanners using the |
||
| 3443 | credentials |
||
| 3444 | targets: Whether to include a list of targets using the credentials |
||
| 3445 | credential_format: One of "key", "rpm", "deb", "exe" or "pem" |
||
| 3446 | |||
| 3447 | Returns: |
||
| 3448 | The response. See :py:meth:`send_command` for details. |
||
| 3449 | """ |
||
| 3450 | if not credential_id: |
||
| 3451 | raise RequiredArgument( |
||
| 3452 | function=self.get_credential.__name__, argument='credential_id' |
||
| 3453 | ) |
||
| 3454 | |||
| 3455 | cmd = XmlCommand("get_credentials") |
||
| 3456 | cmd.set_attribute("credential_id", credential_id) |
||
| 3457 | |||
| 3458 | if credential_format: |
||
| 3459 | if not isinstance(credential_format, CredentialFormat): |
||
| 3460 | raise InvalidArgumentType( |
||
| 3461 | function=self.get_credential.__name__, |
||
| 3462 | argument='credential_format', |
||
| 3463 | arg_type=CredentialFormat.__name__, |
||
| 3464 | ) |
||
| 3465 | |||
| 3466 | cmd.set_attribute("format", credential_format.value) |
||
| 3467 | |||
| 3468 | if scanners is not None: |
||
| 3469 | cmd.set_attribute("scanners", to_bool(scanners)) |
||
| 3470 | |||
| 3471 | if targets is not None: |
||
| 3472 | cmd.set_attribute("targets", to_bool(targets)) |
||
| 3473 | |||
| 3474 | return self._send_xml_command(cmd) |
||
| 3475 | |||
| 3476 | def get_feeds(self) -> Any: |
||
| 3477 | """Request the list of feeds |
||
| 3478 | |||
| 3479 | Returns: |
||
| 3480 | The response. See :py:meth:`send_command` for details. |
||
| 3481 | """ |
||
| 3482 | return self._send_xml_command(XmlCommand("get_feeds")) |
||
| 3483 | |||
| 3484 | def get_filters( |
||
| 3485 | self, |
||
| 3486 | *, |
||
| 3487 | filter: Optional[str] = None, |
||
| 3488 | filter_id: Optional[str] = None, |
||
| 3489 | trash: Optional[bool] = None, |
||
| 3490 | alerts: Optional[bool] = None, |
||
| 3491 | ) -> Any: |
||
| 3492 | """Request a list of filters |
||
| 3493 | |||
| 3494 | Arguments: |
||
| 3495 | filter: Filter term to use for the query |
||
| 3496 | filter_id: UUID of an existing filter to use for the query |
||
| 3497 | trash: Whether to get the trashcan filters instead |
||
| 3498 | alerts: Whether to include list of alerts that use the filter. |
||
| 3499 | |||
| 3500 | Returns: |
||
| 3501 | The response. See :py:meth:`send_command` for details. |
||
| 3502 | """ |
||
| 3503 | cmd = XmlCommand("get_filters") |
||
| 3504 | |||
| 3505 | add_filter(cmd, filter, filter_id) |
||
| 3506 | |||
| 3507 | if trash is not None: |
||
| 3508 | cmd.set_attribute("trash", to_bool(trash)) |
||
| 3509 | |||
| 3510 | if alerts is not None: |
||
| 3511 | cmd.set_attribute("alerts", to_bool(alerts)) |
||
| 3512 | |||
| 3513 | return self._send_xml_command(cmd) |
||
| 3514 | |||
| 3515 | def get_filter( |
||
| 3516 | self, filter_id: str, *, alerts: Optional[bool] = None |
||
| 3517 | ) -> Any: |
||
| 3518 | """Request a single filter |
||
| 3519 | |||
| 3520 | Arguments: |
||
| 3521 | filter_id: UUID of an existing filter |
||
| 3522 | alerts: Whether to include list of alerts that use the filter. |
||
| 3523 | |||
| 3524 | Returns: |
||
| 3525 | The response. See :py:meth:`send_command` for details. |
||
| 3526 | """ |
||
| 3527 | cmd = XmlCommand("get_filters") |
||
| 3528 | |||
| 3529 | if not filter_id: |
||
| 3530 | raise RequiredArgument( |
||
| 3531 | function=self.get_filter.__name__, argument='filter_id' |
||
| 3532 | ) |
||
| 3533 | |||
| 3534 | cmd.set_attribute("filter_id", filter_id) |
||
| 3535 | |||
| 3536 | if alerts is not None: |
||
| 3537 | cmd.set_attribute("alerts", to_bool(alerts)) |
||
| 3538 | |||
| 3539 | return self._send_xml_command(cmd) |
||
| 3540 | |||
| 3541 | View Code Duplication | def get_groups( |
|
| 3542 | self, |
||
| 3543 | *, |
||
| 3544 | filter: Optional[str] = None, |
||
| 3545 | filter_id: Optional[str] = None, |
||
| 3546 | trash: Optional[bool] = None, |
||
| 3547 | ) -> Any: |
||
| 3548 | """Request a list of groups |
||
| 3549 | |||
| 3550 | Arguments: |
||
| 3551 | filter: Filter term to use for the query |
||
| 3552 | filter_id: UUID of an existing filter to use for the query |
||
| 3553 | trash: Whether to get the trashcan groups instead |
||
| 3554 | |||
| 3555 | Returns: |
||
| 3556 | The response. See :py:meth:`send_command` for details. |
||
| 3557 | """ |
||
| 3558 | cmd = XmlCommand("get_groups") |
||
| 3559 | |||
| 3560 | add_filter(cmd, filter, filter_id) |
||
| 3561 | |||
| 3562 | if trash is not None: |
||
| 3563 | cmd.set_attribute("trash", to_bool(trash)) |
||
| 3564 | |||
| 3565 | return self._send_xml_command(cmd) |
||
| 3566 | |||
| 3567 | def get_group(self, group_id: str) -> Any: |
||
| 3568 | """Request a single group |
||
| 3569 | |||
| 3570 | Arguments: |
||
| 3571 | group_id: UUID of an existing group |
||
| 3572 | |||
| 3573 | Returns: |
||
| 3574 | The response. See :py:meth:`send_command` for details. |
||
| 3575 | """ |
||
| 3576 | cmd = XmlCommand("get_groups") |
||
| 3577 | |||
| 3578 | if not group_id: |
||
| 3579 | raise RequiredArgument( |
||
| 3580 | function=self.get_group.__name__, argument='group_id' |
||
| 3581 | ) |
||
| 3582 | |||
| 3583 | cmd.set_attribute("group_id", group_id) |
||
| 3584 | return self._send_xml_command(cmd) |
||
| 3585 | |||
| 3586 | View Code Duplication | def get_permissions( |
|
| 3587 | self, |
||
| 3588 | *, |
||
| 3589 | filter: Optional[str] = None, |
||
| 3590 | filter_id: Optional[str] = None, |
||
| 3591 | trash: Optional[bool] = None, |
||
| 3592 | ) -> Any: |
||
| 3593 | """Request a list of permissions |
||
| 3594 | |||
| 3595 | Arguments: |
||
| 3596 | filter: Filter term to use for the query |
||
| 3597 | filter_id: UUID of an existing filter to use for the query |
||
| 3598 | trash: Whether to get permissions in the trashcan instead |
||
| 3599 | |||
| 3600 | Returns: |
||
| 3601 | The response. See :py:meth:`send_command` for details. |
||
| 3602 | """ |
||
| 3603 | cmd = XmlCommand("get_permissions") |
||
| 3604 | |||
| 3605 | add_filter(cmd, filter, filter_id) |
||
| 3606 | |||
| 3607 | if trash is not None: |
||
| 3608 | cmd.set_attribute("trash", to_bool(trash)) |
||
| 3609 | |||
| 3610 | return self._send_xml_command(cmd) |
||
| 3611 | |||
| 3612 | def get_permission(self, permission_id: str) -> Any: |
||
| 3613 | """Request a single permission |
||
| 3614 | |||
| 3615 | Arguments: |
||
| 3616 | permission_id: UUID of an existing permission |
||
| 3617 | |||
| 3618 | Returns: |
||
| 3619 | The response. See :py:meth:`send_command` for details. |
||
| 3620 | """ |
||
| 3621 | cmd = XmlCommand("get_permissions") |
||
| 3622 | |||
| 3623 | if not permission_id: |
||
| 3624 | raise RequiredArgument( |
||
| 3625 | function=self.get_permission.__name__, argument='permission_id' |
||
| 3626 | ) |
||
| 3627 | |||
| 3628 | cmd.set_attribute("permission_id", permission_id) |
||
| 3629 | return self._send_xml_command(cmd) |
||
| 3630 | |||
| 3631 | def get_preferences( |
||
| 3632 | self, *, nvt_oid: Optional[str] = None, config_id: Optional[str] = None |
||
| 3633 | ) -> Any: |
||
| 3634 | """Request a list of preferences |
||
| 3635 | |||
| 3636 | When the command includes a config_id attribute, the preference element |
||
| 3637 | includes the preference name, type and value, and the NVT to which the |
||
| 3638 | preference applies. Otherwise, the preference element includes just the |
||
| 3639 | name and value, with the NVT and type built into the name. |
||
| 3640 | |||
| 3641 | Arguments: |
||
| 3642 | nvt_oid: OID of nvt |
||
| 3643 | config_id: UUID of scan config of which to show preference values |
||
| 3644 | |||
| 3645 | Returns: |
||
| 3646 | The response. See :py:meth:`send_command` for details. |
||
| 3647 | """ |
||
| 3648 | cmd = XmlCommand("get_preferences") |
||
| 3649 | |||
| 3650 | if nvt_oid: |
||
| 3651 | cmd.set_attribute("nvt_oid", nvt_oid) |
||
| 3652 | |||
| 3653 | if config_id: |
||
| 3654 | cmd.set_attribute("config_id", config_id) |
||
| 3655 | |||
| 3656 | return self._send_xml_command(cmd) |
||
| 3657 | |||
| 3658 | def get_preference( |
||
| 3659 | self, |
||
| 3660 | name: str, |
||
| 3661 | *, |
||
| 3662 | nvt_oid: Optional[str] = None, |
||
| 3663 | config_id: Optional[str] = None, |
||
| 3664 | ) -> Any: |
||
| 3665 | """Request a nvt preference |
||
| 3666 | |||
| 3667 | Arguments: |
||
| 3668 | name: name of a particular preference |
||
| 3669 | nvt_oid: OID of nvt |
||
| 3670 | config_id: UUID of scan config of which to show preference values |
||
| 3671 | |||
| 3672 | Returns: |
||
| 3673 | The response. See :py:meth:`send_command` for details. |
||
| 3674 | """ |
||
| 3675 | cmd = XmlCommand("get_preferences") |
||
| 3676 | |||
| 3677 | if not name: |
||
| 3678 | raise RequiredArgument( |
||
| 3679 | function=self.get_preference.__name__, argument='name' |
||
| 3680 | ) |
||
| 3681 | |||
| 3682 | cmd.set_attribute("preference", name) |
||
| 3683 | |||
| 3684 | if nvt_oid: |
||
| 3685 | cmd.set_attribute("nvt_oid", nvt_oid) |
||
| 3686 | |||
| 3687 | if config_id: |
||
| 3688 | cmd.set_attribute("config_id", config_id) |
||
| 3689 | |||
| 3690 | return self._send_xml_command(cmd) |
||
| 3691 | |||
| 3692 | def get_report_formats( |
||
| 3693 | self, |
||
| 3694 | *, |
||
| 3695 | filter: Optional[str] = None, |
||
| 3696 | filter_id: Optional[str] = None, |
||
| 3697 | trash: Optional[bool] = None, |
||
| 3698 | alerts: Optional[bool] = None, |
||
| 3699 | params: Optional[bool] = None, |
||
| 3700 | details: Optional[bool] = None, |
||
| 3701 | ) -> Any: |
||
| 3702 | """Request a list of report formats |
||
| 3703 | |||
| 3704 | Arguments: |
||
| 3705 | filter: Filter term to use for the query |
||
| 3706 | filter_id: UUID of an existing filter to use for the query |
||
| 3707 | trash: Whether to get the trashcan report formats instead |
||
| 3708 | alerts: Whether to include alerts that use the report format |
||
| 3709 | params: Whether to include report format parameters |
||
| 3710 | details: Include report format file, signature and parameters |
||
| 3711 | |||
| 3712 | Returns: |
||
| 3713 | The response. See :py:meth:`send_command` for details. |
||
| 3714 | """ |
||
| 3715 | cmd = XmlCommand("get_report_formats") |
||
| 3716 | |||
| 3717 | add_filter(cmd, filter, filter_id) |
||
| 3718 | |||
| 3719 | if details is not None: |
||
| 3720 | cmd.set_attribute("details", to_bool(details)) |
||
| 3721 | |||
| 3722 | if alerts is not None: |
||
| 3723 | cmd.set_attribute("alerts", to_bool(alerts)) |
||
| 3724 | |||
| 3725 | if params is not None: |
||
| 3726 | cmd.set_attribute("params", to_bool(params)) |
||
| 3727 | |||
| 3728 | if trash is not None: |
||
| 3729 | cmd.set_attribute("trash", to_bool(trash)) |
||
| 3730 | |||
| 3731 | return self._send_xml_command(cmd) |
||
| 3732 | |||
| 3733 | View Code Duplication | def get_report_format( |
|
| 3734 | self, report_format_id: Union[str, ReportFormatType] |
||
| 3735 | ) -> Any: |
||
| 3736 | """Request a single report format |
||
| 3737 | |||
| 3738 | Arguments: |
||
| 3739 | report_format_id: UUID of an existing report format |
||
| 3740 | or ReportFormatType (enum) |
||
| 3741 | |||
| 3742 | Returns: |
||
| 3743 | The response. See :py:meth:`send_command` for details. |
||
| 3744 | """ |
||
| 3745 | cmd = XmlCommand("get_report_formats") |
||
| 3746 | |||
| 3747 | if not report_format_id: |
||
| 3748 | raise RequiredArgument( |
||
| 3749 | function=self.get_report_format.__name__, |
||
| 3750 | argument='report_format_id', |
||
| 3751 | ) |
||
| 3752 | |||
| 3753 | if isinstance(report_format_id, ReportFormatType): |
||
| 3754 | report_format_id = report_format_id.value |
||
| 3755 | |||
| 3756 | cmd.set_attribute("report_format_id", report_format_id) |
||
| 3757 | |||
| 3758 | # for single entity always request all details |
||
| 3759 | cmd.set_attribute("details", "1") |
||
| 3760 | return self._send_xml_command(cmd) |
||
| 3761 | |||
| 3762 | View Code Duplication | def get_roles( |
|
| 3763 | self, |
||
| 3764 | *, |
||
| 3765 | filter: Optional[str] = None, |
||
| 3766 | filter_id: Optional[str] = None, |
||
| 3767 | trash: Optional[bool] = None, |
||
| 3768 | ) -> Any: |
||
| 3769 | """Request a list of roles |
||
| 3770 | |||
| 3771 | Arguments: |
||
| 3772 | filter: Filter term to use for the query |
||
| 3773 | filter_id: UUID of an existing filter to use for the query |
||
| 3774 | trash: Whether to get the trashcan roles instead |
||
| 3775 | |||
| 3776 | Returns: |
||
| 3777 | The response. See :py:meth:`send_command` for details. |
||
| 3778 | """ |
||
| 3779 | cmd = XmlCommand("get_roles") |
||
| 3780 | |||
| 3781 | add_filter(cmd, filter, filter_id) |
||
| 3782 | |||
| 3783 | if trash is not None: |
||
| 3784 | cmd.set_attribute("trash", to_bool(trash)) |
||
| 3785 | |||
| 3786 | return self._send_xml_command(cmd) |
||
| 3787 | |||
| 3788 | def get_role(self, role_id: str) -> Any: |
||
| 3789 | """Request a single role |
||
| 3790 | |||
| 3791 | Arguments: |
||
| 3792 | role_id: UUID of an existing role |
||
| 3793 | |||
| 3794 | Returns: |
||
| 3795 | The response. See :py:meth:`send_command` for details. |
||
| 3796 | """ |
||
| 3797 | if not role_id: |
||
| 3798 | raise RequiredArgument( |
||
| 3799 | function=self.get_role.__name__, argument='role_id' |
||
| 3800 | ) |
||
| 3801 | |||
| 3802 | cmd = XmlCommand("get_roles") |
||
| 3803 | cmd.set_attribute("role_id", role_id) |
||
| 3804 | return self._send_xml_command(cmd) |
||
| 3805 | |||
| 3806 | View Code Duplication | def get_scanners( |
|
| 3807 | self, |
||
| 3808 | *, |
||
| 3809 | filter: Optional[str] = None, |
||
| 3810 | filter_id: Optional[str] = None, |
||
| 3811 | trash: Optional[bool] = None, |
||
| 3812 | details: Optional[bool] = None, |
||
| 3813 | ) -> Any: |
||
| 3814 | """Request a list of scanners |
||
| 3815 | |||
| 3816 | Arguments: |
||
| 3817 | filter: Filter term to use for the query |
||
| 3818 | filter_id: UUID of an existing filter to use for the query |
||
| 3819 | trash: Whether to get the trashcan scanners instead |
||
| 3820 | details: Whether to include extra details like tasks using this |
||
| 3821 | scanner |
||
| 3822 | |||
| 3823 | Returns: |
||
| 3824 | The response. See :py:meth:`send_command` for details. |
||
| 3825 | """ |
||
| 3826 | cmd = XmlCommand("get_scanners") |
||
| 3827 | |||
| 3828 | add_filter(cmd, filter, filter_id) |
||
| 3829 | |||
| 3830 | if trash is not None: |
||
| 3831 | cmd.set_attribute("trash", to_bool(trash)) |
||
| 3832 | |||
| 3833 | if details is not None: |
||
| 3834 | cmd.set_attribute("details", to_bool(details)) |
||
| 3835 | |||
| 3836 | return self._send_xml_command(cmd) |
||
| 3837 | |||
| 3838 | def get_scanner(self, scanner_id: str) -> Any: |
||
| 3839 | """Request a single scanner |
||
| 3840 | |||
| 3841 | Arguments: |
||
| 3842 | scanner_id: UUID of an existing scanner |
||
| 3843 | |||
| 3844 | Returns: |
||
| 3845 | The response. See :py:meth:`send_command` for details. |
||
| 3846 | """ |
||
| 3847 | cmd = XmlCommand("get_scanners") |
||
| 3848 | |||
| 3849 | if not scanner_id: |
||
| 3850 | raise RequiredArgument( |
||
| 3851 | function=self.get_scanner.__name__, argument='scanner_id' |
||
| 3852 | ) |
||
| 3853 | |||
| 3854 | cmd.set_attribute("scanner_id", scanner_id) |
||
| 3855 | |||
| 3856 | # for single entity always request all details |
||
| 3857 | cmd.set_attribute("details", "1") |
||
| 3858 | return self._send_xml_command(cmd) |
||
| 3859 | |||
| 3860 | def get_schedules( |
||
| 3861 | self, |
||
| 3862 | *, |
||
| 3863 | filter: Optional[str] = None, |
||
| 3864 | filter_id: Optional[str] = None, |
||
| 3865 | trash: Optional[bool] = None, |
||
| 3866 | tasks: Optional[bool] = None, |
||
| 3867 | ) -> Any: |
||
| 3868 | """Request a list of schedules |
||
| 3869 | |||
| 3870 | Arguments: |
||
| 3871 | filter: Filter term to use for the query |
||
| 3872 | filter_id: UUID of an existing filter to use for the query |
||
| 3873 | trash: Whether to get the trashcan schedules instead |
||
| 3874 | tasks: Whether to include tasks using the schedules |
||
| 3875 | |||
| 3876 | Returns: |
||
| 3877 | The response. See :py:meth:`send_command` for details. |
||
| 3878 | """ |
||
| 3879 | cmd = XmlCommand("get_schedules") |
||
| 3880 | |||
| 3881 | add_filter(cmd, filter, filter_id) |
||
| 3882 | |||
| 3883 | if trash is not None: |
||
| 3884 | cmd.set_attribute("trash", to_bool(trash)) |
||
| 3885 | |||
| 3886 | if tasks is not None: |
||
| 3887 | cmd.set_attribute("tasks", to_bool(tasks)) |
||
| 3888 | |||
| 3889 | return self._send_xml_command(cmd) |
||
| 3890 | |||
| 3891 | def get_schedule( |
||
| 3892 | self, schedule_id: str, *, tasks: Optional[bool] = None |
||
| 3893 | ) -> Any: |
||
| 3894 | """Request a single schedule |
||
| 3895 | |||
| 3896 | Arguments: |
||
| 3897 | schedule_id: UUID of an existing schedule |
||
| 3898 | tasks: Whether to include tasks using the schedules |
||
| 3899 | |||
| 3900 | Returns: |
||
| 3901 | The response. See :py:meth:`send_command` for details. |
||
| 3902 | """ |
||
| 3903 | cmd = XmlCommand("get_schedules") |
||
| 3904 | |||
| 3905 | if not schedule_id: |
||
| 3906 | raise RequiredArgument( |
||
| 3907 | function=self.get_schedule.__name__, argument='schedule_id' |
||
| 3908 | ) |
||
| 3909 | |||
| 3910 | cmd.set_attribute("schedule_id", schedule_id) |
||
| 3911 | |||
| 3912 | if tasks is not None: |
||
| 3913 | cmd.set_attribute("tasks", to_bool(tasks)) |
||
| 3914 | |||
| 3915 | return self._send_xml_command(cmd) |
||
| 3916 | |||
| 3917 | def get_settings(self, *, filter: Optional[str] = None) -> Any: |
||
| 3918 | """Request a list of user settings |
||
| 3919 | |||
| 3920 | Arguments: |
||
| 3921 | filter: Filter term to use for the query |
||
| 3922 | |||
| 3923 | Returns: |
||
| 3924 | The response. See :py:meth:`send_command` for details. |
||
| 3925 | """ |
||
| 3926 | cmd = XmlCommand("get_settings") |
||
| 3927 | |||
| 3928 | if filter: |
||
| 3929 | cmd.set_attribute("filter", filter) |
||
| 3930 | |||
| 3931 | return self._send_xml_command(cmd) |
||
| 3932 | |||
| 3933 | def get_setting(self, setting_id: str) -> Any: |
||
| 3934 | """Request a single setting |
||
| 3935 | |||
| 3936 | Arguments: |
||
| 3937 | setting_id: UUID of an existing setting |
||
| 3938 | |||
| 3939 | Returns: |
||
| 3940 | The response. See :py:meth:`send_command` for details. |
||
| 3941 | """ |
||
| 3942 | cmd = XmlCommand("get_settings") |
||
| 3943 | |||
| 3944 | if not setting_id: |
||
| 3945 | raise RequiredArgument( |
||
| 3946 | function=self.get_setting.__name__, argument='setting_id' |
||
| 3947 | ) |
||
| 3948 | |||
| 3949 | cmd.set_attribute("setting_id", setting_id) |
||
| 3950 | return self._send_xml_command(cmd) |
||
| 3951 | |||
| 3952 | def get_system_reports( |
||
| 3953 | self, |
||
| 3954 | *, |
||
| 3955 | name: Optional[str] = None, |
||
| 3956 | duration: Optional[int] = None, |
||
| 3957 | start_time: Optional[str] = None, |
||
| 3958 | end_time: Optional[str] = None, |
||
| 3959 | brief: Optional[bool] = None, |
||
| 3960 | slave_id: Optional[str] = None, |
||
| 3961 | ) -> Any: |
||
| 3962 | """Request a list of system reports |
||
| 3963 | |||
| 3964 | Arguments: |
||
| 3965 | name: A string describing the required system report |
||
| 3966 | duration: The number of seconds into the past that the system report |
||
| 3967 | should include |
||
| 3968 | start_time: The start of the time interval the system report should |
||
| 3969 | include in ISO time format |
||
| 3970 | end_time: The end of the time interval the system report should |
||
| 3971 | include in ISO time format |
||
| 3972 | brief: Whether to include the actual system reports |
||
| 3973 | slave_id: UUID of GMP scanner from which to get the system reports |
||
| 3974 | |||
| 3975 | Returns: |
||
| 3976 | The response. See :py:meth:`send_command` for details. |
||
| 3977 | """ |
||
| 3978 | cmd = XmlCommand("get_system_reports") |
||
| 3979 | |||
| 3980 | if name: |
||
| 3981 | cmd.set_attribute("name", name) |
||
| 3982 | |||
| 3983 | if duration is not None: |
||
| 3984 | if not isinstance(duration, Integral): |
||
| 3985 | raise InvalidArgument("duration needs to be an integer number") |
||
| 3986 | |||
| 3987 | cmd.set_attribute("duration", str(duration)) |
||
| 3988 | |||
| 3989 | if start_time: |
||
| 3990 | cmd.set_attribute("start_time", str(start_time)) |
||
| 3991 | |||
| 3992 | if end_time: |
||
| 3993 | cmd.set_attribute("end_time", str(end_time)) |
||
| 3994 | |||
| 3995 | if brief is not None: |
||
| 3996 | cmd.set_attribute("brief", to_bool(brief)) |
||
| 3997 | |||
| 3998 | if slave_id: |
||
| 3999 | cmd.set_attribute("slave_id", slave_id) |
||
| 4000 | |||
| 4001 | return self._send_xml_command(cmd) |
||
| 4002 | |||
| 4003 | def get_tags( |
||
| 4004 | self, |
||
| 4005 | *, |
||
| 4006 | filter: Optional[str] = None, |
||
| 4007 | filter_id: Optional[str] = None, |
||
| 4008 | trash: Optional[bool] = None, |
||
| 4009 | names_only: Optional[bool] = None, |
||
| 4010 | ) -> Any: |
||
| 4011 | """Request a list of tags |
||
| 4012 | |||
| 4013 | Arguments: |
||
| 4014 | filter: Filter term to use for the query |
||
| 4015 | filter_id: UUID of an existing filter to use for the query |
||
| 4016 | trash: Whether to get tags from the trashcan instead |
||
| 4017 | names_only: Whether to get only distinct tag names |
||
| 4018 | |||
| 4019 | Returns: |
||
| 4020 | The response. See :py:meth:`send_command` for details. |
||
| 4021 | """ |
||
| 4022 | cmd = XmlCommand("get_tags") |
||
| 4023 | |||
| 4024 | add_filter(cmd, filter, filter_id) |
||
| 4025 | |||
| 4026 | if trash is not None: |
||
| 4027 | cmd.set_attribute("trash", to_bool(trash)) |
||
| 4028 | |||
| 4029 | if names_only is not None: |
||
| 4030 | cmd.set_attribute("names_only", to_bool(names_only)) |
||
| 4031 | |||
| 4032 | return self._send_xml_command(cmd) |
||
| 4033 | |||
| 4034 | def get_tag(self, tag_id: str) -> Any: |
||
| 4035 | """Request a single tag |
||
| 4036 | |||
| 4037 | Arguments: |
||
| 4038 | tag_id: UUID of an existing tag |
||
| 4039 | |||
| 4040 | Returns: |
||
| 4041 | The response. See :py:meth:`send_command` for details. |
||
| 4042 | """ |
||
| 4043 | cmd = XmlCommand("get_tags") |
||
| 4044 | |||
| 4045 | if not tag_id: |
||
| 4046 | raise RequiredArgument( |
||
| 4047 | function=self.get_tag.__name__, argument='tag_id' |
||
| 4048 | ) |
||
| 4049 | |||
| 4050 | cmd.set_attribute("tag_id", tag_id) |
||
| 4051 | return self._send_xml_command(cmd) |
||
| 4052 | |||
| 4053 | def get_users( |
||
| 4054 | self, *, filter: Optional[str] = None, filter_id: Optional[str] = None |
||
| 4055 | ) -> Any: |
||
| 4056 | """Request a list of users |
||
| 4057 | |||
| 4058 | Arguments: |
||
| 4059 | filter: Filter term to use for the query |
||
| 4060 | filter_id: UUID of an existing filter to use for the query |
||
| 4061 | |||
| 4062 | Returns: |
||
| 4063 | The response. See :py:meth:`send_command` for details. |
||
| 4064 | """ |
||
| 4065 | cmd = XmlCommand("get_users") |
||
| 4066 | |||
| 4067 | add_filter(cmd, filter, filter_id) |
||
| 4068 | |||
| 4069 | return self._send_xml_command(cmd) |
||
| 4070 | |||
| 4071 | def get_user(self, user_id: str) -> Any: |
||
| 4072 | """Request a single user |
||
| 4073 | |||
| 4074 | Arguments: |
||
| 4075 | user_id: UUID of an existing user |
||
| 4076 | |||
| 4077 | Returns: |
||
| 4078 | The response. See :py:meth:`send_command` for details. |
||
| 4079 | """ |
||
| 4080 | cmd = XmlCommand("get_users") |
||
| 4081 | |||
| 4082 | if not user_id: |
||
| 4083 | raise RequiredArgument( |
||
| 4084 | function=self.get_user.__name__, argument='user_id' |
||
| 4085 | ) |
||
| 4086 | |||
| 4087 | cmd.set_attribute("user_id", user_id) |
||
| 4088 | return self._send_xml_command(cmd) |
||
| 4089 | |||
| 4090 | def get_version(self) -> Any: |
||
| 4091 | """Get the Greenbone Manager Protocol version used by the remote gvmd |
||
| 4092 | |||
| 4093 | Returns: |
||
| 4094 | The response. See :py:meth:`send_command` for details. |
||
| 4095 | """ |
||
| 4096 | return self._send_xml_command(XmlCommand("get_version")) |
||
| 4097 | |||
| 4098 | def help( |
||
| 4099 | self, *, format: Optional[str] = None, help_type: Optional[str] = "" |
||
| 4100 | ) -> Any: |
||
| 4101 | """Get the help text |
||
| 4102 | |||
| 4103 | Arguments: |
||
| 4104 | format: One of "html", "rnc", "text" or "xml |
||
| 4105 | help_type: One of "brief" or "". Default "" |
||
| 4106 | |||
| 4107 | Returns: |
||
| 4108 | The response. See :py:meth:`send_command` for details. |
||
| 4109 | """ |
||
| 4110 | cmd = XmlCommand("help") |
||
| 4111 | |||
| 4112 | if help_type not in ("", "brief"): |
||
| 4113 | raise InvalidArgument( |
||
| 4114 | 'help_type argument must be an empty string or "brief"' |
||
| 4115 | ) |
||
| 4116 | |||
| 4117 | cmd.set_attribute("type", help_type) |
||
| 4118 | |||
| 4119 | if format: |
||
| 4120 | if not format.lower() in ("html", "rnc", "text", "xml"): |
||
| 4121 | raise InvalidArgument( |
||
| 4122 | "help format Argument must be one of html, rnc, text or " |
||
| 4123 | "xml" |
||
| 4124 | ) |
||
| 4125 | |||
| 4126 | cmd.set_attribute("format", format) |
||
| 4127 | |||
| 4128 | return self._send_xml_command(cmd) |
||
| 4129 | |||
| 4130 | def modify_asset(self, asset_id: str, comment: Optional[str] = "") -> Any: |
||
| 4131 | """Modifies an existing asset. |
||
| 4132 | |||
| 4133 | Arguments: |
||
| 4134 | asset_id: UUID of the asset to be modified. |
||
| 4135 | comment: Comment for the asset. |
||
| 4136 | |||
| 4137 | Returns: |
||
| 4138 | The response. See :py:meth:`send_command` for details. |
||
| 4139 | """ |
||
| 4140 | if not asset_id: |
||
| 4141 | raise RequiredArgument( |
||
| 4142 | function=self.modify_asset.__name__, argument='asset_id' |
||
| 4143 | ) |
||
| 4144 | |||
| 4145 | cmd = XmlCommand("modify_asset") |
||
| 4146 | cmd.set_attribute("asset_id", asset_id) |
||
| 4147 | cmd.add_element("comment", comment) |
||
| 4148 | |||
| 4149 | return self._send_xml_command(cmd) |
||
| 4150 | |||
| 4151 | def modify_auth(self, group_name: str, auth_conf_settings: dict) -> Any: |
||
| 4152 | """Modifies an existing auth. |
||
| 4153 | |||
| 4154 | Arguments: |
||
| 4155 | group_name: Name of the group to be modified. |
||
| 4156 | auth_conf_settings: The new auth config. |
||
| 4157 | |||
| 4158 | Returns: |
||
| 4159 | The response. See :py:meth:`send_command` for details. |
||
| 4160 | """ |
||
| 4161 | if not group_name: |
||
| 4162 | raise RequiredArgument( |
||
| 4163 | function=self.modify_auth.__name__, argument='group_name' |
||
| 4164 | ) |
||
| 4165 | if not auth_conf_settings: |
||
| 4166 | raise RequiredArgument( |
||
| 4167 | function=self.modify_auth.__name__, |
||
| 4168 | argument='auth_conf_settings', |
||
| 4169 | ) |
||
| 4170 | cmd = XmlCommand("modify_auth") |
||
| 4171 | _xmlgroup = cmd.add_element("group", attrs={"name": str(group_name)}) |
||
| 4172 | |||
| 4173 | for key, value in auth_conf_settings.items(): |
||
| 4174 | _xmlauthconf = _xmlgroup.add_element("auth_conf_setting") |
||
| 4175 | _xmlauthconf.add_element("key", key) |
||
| 4176 | _xmlauthconf.add_element("value", value) |
||
| 4177 | |||
| 4178 | return self._send_xml_command(cmd) |
||
| 4179 | |||
| 4180 | def modify_config_set_nvt_preference( |
||
| 4181 | self, |
||
| 4182 | config_id: str, |
||
| 4183 | name: str, |
||
| 4184 | nvt_oid: str, |
||
| 4185 | *, |
||
| 4186 | value: Optional[str] = None, |
||
| 4187 | ) -> Any: |
||
| 4188 | """Modifies the nvt preferences of an existing scan config. |
||
| 4189 | |||
| 4190 | Arguments: |
||
| 4191 | config_id: UUID of scan config to modify. |
||
| 4192 | name: Name for nvt preference to change. |
||
| 4193 | nvt_oid: OID of the NVT associated with preference to modify |
||
| 4194 | value: New value for the preference. None to delete the preference |
||
| 4195 | and to use the default instead. |
||
| 4196 | """ |
||
| 4197 | if not config_id: |
||
| 4198 | raise RequiredArgument( |
||
| 4199 | function=self.modify_config_set_nvt_preference.__name__, |
||
| 4200 | argument='config_id', |
||
| 4201 | ) |
||
| 4202 | |||
| 4203 | if not nvt_oid: |
||
| 4204 | raise RequiredArgument( |
||
| 4205 | function=self.modify_config_set_nvt_preference.__name__, |
||
| 4206 | argument='nvt_oid', |
||
| 4207 | ) |
||
| 4208 | |||
| 4209 | if not name: |
||
| 4210 | raise RequiredArgument( |
||
| 4211 | function=self.modify_config_set_nvt_preference.__name__, |
||
| 4212 | argument='name', |
||
| 4213 | ) |
||
| 4214 | |||
| 4215 | cmd = XmlCommand("modify_config") |
||
| 4216 | cmd.set_attribute("config_id", str(config_id)) |
||
| 4217 | |||
| 4218 | _xmlpref = cmd.add_element("preference") |
||
| 4219 | |||
| 4220 | _xmlpref.add_element("nvt", attrs={"oid": nvt_oid}) |
||
| 4221 | _xmlpref.add_element("name", name) |
||
| 4222 | |||
| 4223 | if value: |
||
| 4224 | _xmlpref.add_element("value", to_base64(value)) |
||
| 4225 | |||
| 4226 | return self._send_xml_command(cmd) |
||
| 4227 | |||
| 4228 | def modify_config_set_name(self, config_id: str, name: str) -> Any: |
||
| 4229 | """Modifies the name of an existing scan config |
||
| 4230 | |||
| 4231 | Arguments: |
||
| 4232 | config_id: UUID of scan config to modify. |
||
| 4233 | name: New name for the config. |
||
| 4234 | """ |
||
| 4235 | if not config_id: |
||
| 4236 | raise RequiredArgument( |
||
| 4237 | function=self.modify_config_set_name.__name__, |
||
| 4238 | argument='config_id', |
||
| 4239 | ) |
||
| 4240 | |||
| 4241 | if not name: |
||
| 4242 | raise RequiredArgument( |
||
| 4243 | function=self.modify_config_set_name.__name__, argument='name' |
||
| 4244 | ) |
||
| 4245 | |||
| 4246 | cmd = XmlCommand("modify_config") |
||
| 4247 | cmd.set_attribute("config_id", str(config_id)) |
||
| 4248 | |||
| 4249 | cmd.add_element("name", name) |
||
| 4250 | |||
| 4251 | return self._send_xml_command(cmd) |
||
| 4252 | |||
| 4253 | def modify_config_set_comment( |
||
| 4254 | self, config_id: str, comment: Optional[str] = "" |
||
| 4255 | ) -> Any: |
||
| 4256 | """Modifies the comment of an existing scan config |
||
| 4257 | |||
| 4258 | Arguments: |
||
| 4259 | config_id: UUID of scan config to modify. |
||
| 4260 | comment: Comment to set on a config. Default: '' |
||
| 4261 | """ |
||
| 4262 | if not config_id: |
||
| 4263 | raise RequiredArgument( |
||
| 4264 | function=self.modify_config_set_comment.__name__, |
||
| 4265 | argument='config_id argument', |
||
| 4266 | ) |
||
| 4267 | |||
| 4268 | cmd = XmlCommand("modify_config") |
||
| 4269 | cmd.set_attribute("config_id", str(config_id)) |
||
| 4270 | |||
| 4271 | cmd.add_element("comment", comment) |
||
| 4272 | |||
| 4273 | return self._send_xml_command(cmd) |
||
| 4274 | |||
| 4275 | def modify_config_set_scanner_preference( |
||
| 4276 | self, config_id: str, name: str, *, value: Optional[str] = None |
||
| 4277 | ) -> Any: |
||
| 4278 | """Modifies the scanner preferences of an existing scan config |
||
| 4279 | |||
| 4280 | Arguments: |
||
| 4281 | config_id: UUID of scan config to modify. |
||
| 4282 | name: Name of the scanner preference to change |
||
| 4283 | value: New value for the preference. None to delete the preference |
||
| 4284 | and to use the default instead. |
||
| 4285 | |||
| 4286 | """ |
||
| 4287 | if not config_id: |
||
| 4288 | raise RequiredArgument( |
||
| 4289 | function=self.modify_config_set_scanner_preference.__name__, |
||
| 4290 | argument='config_id', |
||
| 4291 | ) |
||
| 4292 | |||
| 4293 | if not name: |
||
| 4294 | raise RequiredArgument( |
||
| 4295 | function=self.modify_config_set_scanner_preference.__name__, |
||
| 4296 | argument='name argument', |
||
| 4297 | ) |
||
| 4298 | |||
| 4299 | cmd = XmlCommand("modify_config") |
||
| 4300 | cmd.set_attribute("config_id", str(config_id)) |
||
| 4301 | |||
| 4302 | _xmlpref = cmd.add_element("preference") |
||
| 4303 | |||
| 4304 | _xmlpref.add_element("name", name) |
||
| 4305 | |||
| 4306 | if value: |
||
| 4307 | _xmlpref.add_element("value", to_base64(value)) |
||
| 4308 | |||
| 4309 | return self._send_xml_command(cmd) |
||
| 4310 | |||
| 4311 | def modify_config_set_nvt_selection( |
||
| 4312 | self, config_id: str, family: str, nvt_oids: List[str] |
||
| 4313 | ) -> Any: |
||
| 4314 | """Modifies the selected nvts of an existing scan config |
||
| 4315 | |||
| 4316 | The manager updates the given family in the config to include only the |
||
| 4317 | given NVTs. |
||
| 4318 | |||
| 4319 | Arguments: |
||
| 4320 | config_id: UUID of scan config to modify. |
||
| 4321 | family: Name of the NVT family to include NVTs from |
||
| 4322 | nvt_oids: List of NVTs to select for the family. |
||
| 4323 | """ |
||
| 4324 | if not config_id: |
||
| 4325 | raise RequiredArgument( |
||
| 4326 | function=self.modify_config_set_nvt_selection.__name__, |
||
| 4327 | argument='config_id', |
||
| 4328 | ) |
||
| 4329 | |||
| 4330 | if not family: |
||
| 4331 | raise RequiredArgument( |
||
| 4332 | function=self.modify_config_set_nvt_selection.__name__, |
||
| 4333 | argument='family argument', |
||
| 4334 | ) |
||
| 4335 | |||
| 4336 | if not is_list_like(nvt_oids): |
||
| 4337 | raise InvalidArgumentType( |
||
| 4338 | function=self.modify_config_set_nvt_selection.__name__, |
||
| 4339 | argument='nvt_oids', |
||
| 4340 | arg_type='list', |
||
| 4341 | ) |
||
| 4342 | |||
| 4343 | cmd = XmlCommand("modify_config") |
||
| 4344 | cmd.set_attribute("config_id", str(config_id)) |
||
| 4345 | |||
| 4346 | _xmlnvtsel = cmd.add_element("nvt_selection") |
||
| 4347 | _xmlnvtsel.add_element("family", family) |
||
| 4348 | |||
| 4349 | for nvt in nvt_oids: |
||
| 4350 | _xmlnvtsel.add_element("nvt", attrs={"oid": nvt}) |
||
| 4351 | |||
| 4352 | return self._send_xml_command(cmd) |
||
| 4353 | |||
| 4354 | def modify_config_set_family_selection( |
||
| 4355 | self, |
||
| 4356 | config_id: str, |
||
| 4357 | families: List[Tuple[str, bool, bool]], |
||
| 4358 | *, |
||
| 4359 | auto_add_new_families: Optional[bool] = True, |
||
| 4360 | ) -> Any: |
||
| 4361 | """ |
||
| 4362 | Selected the NVTs of a scan config at a family level. |
||
| 4363 | |||
| 4364 | Arguments: |
||
| 4365 | config_id: UUID of scan config to modify. |
||
| 4366 | families: A list of tuples (str, bool, bool): |
||
| 4367 | str: the name of the NVT family selected, |
||
| 4368 | bool: add new NVTs to the family automatically, |
||
| 4369 | bool: include all NVTs from the family |
||
| 4370 | auto_add_new_families: Whether new families should be added to the |
||
| 4371 | scan config automatically. Default: True. |
||
| 4372 | """ |
||
| 4373 | if not config_id: |
||
| 4374 | raise RequiredArgument( |
||
| 4375 | function=self.modify_config_set_family_selection.__name__, |
||
| 4376 | argument='config_id', |
||
| 4377 | ) |
||
| 4378 | |||
| 4379 | if not is_list_like(families): |
||
| 4380 | raise InvalidArgumentType( |
||
| 4381 | function=self.modify_config_set_family_selection.__name__, |
||
| 4382 | argument='families', |
||
| 4383 | arg_type='list', |
||
| 4384 | ) |
||
| 4385 | |||
| 4386 | cmd = XmlCommand("modify_config") |
||
| 4387 | cmd.set_attribute("config_id", str(config_id)) |
||
| 4388 | |||
| 4389 | _xmlfamsel = cmd.add_element("family_selection") |
||
| 4390 | _xmlfamsel.add_element("growing", to_bool(auto_add_new_families)) |
||
| 4391 | |||
| 4392 | for family in families: |
||
| 4393 | _xmlfamily = _xmlfamsel.add_element("family") |
||
| 4394 | _xmlfamily.add_element("name", family[0]) |
||
| 4395 | |||
| 4396 | if len(family) != 3: |
||
| 4397 | raise InvalidArgument( |
||
| 4398 | "Family must be a tuple of 3. (str, bool, bool)" |
||
| 4399 | ) |
||
| 4400 | |||
| 4401 | if not isinstance(family[1], bool) or not isinstance( |
||
| 4402 | family[2], bool |
||
| 4403 | ): |
||
| 4404 | raise InvalidArgumentType( |
||
| 4405 | function=self.modify_config_set_family_selection.__name__, |
||
| 4406 | argument='families', |
||
| 4407 | arg_type='[tuple(str, bool, bool)]', |
||
| 4408 | ) |
||
| 4409 | |||
| 4410 | _xmlfamily.add_element("all", to_bool(family[2])) |
||
| 4411 | _xmlfamily.add_element("growing", to_bool(family[1])) |
||
| 4412 | |||
| 4413 | return self._send_xml_command(cmd) |
||
| 4414 | |||
| 4415 | def modify_config( |
||
| 4416 | self, config_id: str, selection: Optional[str] = None, **kwargs |
||
| 4417 | ) -> Any: |
||
| 4418 | """Modifies an existing scan config. |
||
| 4419 | |||
| 4420 | DEPRECATED. Please use *modify_config_set_* methods instead. |
||
| 4421 | |||
| 4422 | modify_config has four modes to operate depending on the selection. |
||
| 4423 | |||
| 4424 | Arguments: |
||
| 4425 | config_id: UUID of scan config to modify. |
||
| 4426 | selection: one of 'scan_pref', 'nvt_pref', 'nvt_selection' or |
||
| 4427 | 'family_selection' |
||
| 4428 | name: New name for preference. |
||
| 4429 | value: New value for preference. |
||
| 4430 | nvt_oids: List of NVTs associated with preference to modify. |
||
| 4431 | family: Name of family to modify. |
||
| 4432 | |||
| 4433 | Returns: |
||
| 4434 | The response. See :py:meth:`send_command` for details. |
||
| 4435 | """ |
||
| 4436 | if not config_id: |
||
| 4437 | raise RequiredArgument( |
||
| 4438 | function=self.modify_config.__name__, |
||
| 4439 | argument='config_id argument', |
||
| 4440 | ) |
||
| 4441 | |||
| 4442 | if selection is None: |
||
| 4443 | deprecation( |
||
| 4444 | "Using modify_config to update the comment of a scan config is" |
||
| 4445 | "deprecated. Please use modify_config_set_comment instead." |
||
| 4446 | ) |
||
| 4447 | return self.modify_config_set_comment( |
||
| 4448 | config_id, kwargs.get("comment") |
||
| 4449 | ) |
||
| 4450 | |||
| 4451 | if selection not in ( |
||
| 4452 | "nvt_pref", |
||
| 4453 | "scan_pref", |
||
| 4454 | "family_selection", |
||
| 4455 | "nvt_selection", |
||
| 4456 | ): |
||
| 4457 | raise InvalidArgument( |
||
| 4458 | "selection must be one of nvt_pref, " |
||
| 4459 | "scan_pref, family_selection or " |
||
| 4460 | "nvt_selection" |
||
| 4461 | ) |
||
| 4462 | |||
| 4463 | if selection == "nvt_pref": |
||
| 4464 | deprecation( |
||
| 4465 | "Using modify_config to update a nvt preference of a scan " |
||
| 4466 | "config is deprecated. Please use " |
||
| 4467 | "modify_config_set_nvt_preference instead." |
||
| 4468 | ) |
||
| 4469 | return self.modify_config_set_nvt_preference(config_id, **kwargs) |
||
| 4470 | |||
| 4471 | if selection == "scan_pref": |
||
| 4472 | deprecation( |
||
| 4473 | "Using modify_config to update a scanner preference of a " |
||
| 4474 | "scan config is deprecated. Please use " |
||
| 4475 | "modify_config_set_scanner_preference instead." |
||
| 4476 | ) |
||
| 4477 | return self.modify_config_set_scanner_preference( |
||
| 4478 | config_id, **kwargs |
||
| 4479 | ) |
||
| 4480 | |||
| 4481 | if selection == "nvt_selection": |
||
| 4482 | deprecation( |
||
| 4483 | "Using modify_config to update a nvt selection of a " |
||
| 4484 | "scan config is deprecated. Please use " |
||
| 4485 | "modify_config_set_nvt_selection instead." |
||
| 4486 | ) |
||
| 4487 | return self.modify_config_set_nvt_selection(config_id, **kwargs) |
||
| 4488 | |||
| 4489 | deprecation( |
||
| 4490 | "Using modify_config to update a family selection of a " |
||
| 4491 | "scan config is deprecated. Please use " |
||
| 4492 | "modify_config_set_family_selection instead." |
||
| 4493 | ) |
||
| 4494 | return self.modify_config_set_family_selection(config_id, **kwargs) |
||
| 4495 | |||
| 4496 | View Code Duplication | def modify_group( |
|
| 4497 | self, |
||
| 4498 | group_id: str, |
||
| 4499 | *, |
||
| 4500 | comment: Optional[str] = None, |
||
| 4501 | name: Optional[str] = None, |
||
| 4502 | users: Optional[List[str]] = None, |
||
| 4503 | ) -> Any: |
||
| 4504 | """Modifies an existing group. |
||
| 4505 | |||
| 4506 | Arguments: |
||
| 4507 | group_id: UUID of group to modify. |
||
| 4508 | comment: Comment on group. |
||
| 4509 | name: Name of group. |
||
| 4510 | users: List of user names to be in the group |
||
| 4511 | |||
| 4512 | Returns: |
||
| 4513 | The response. See :py:meth:`send_command` for details. |
||
| 4514 | """ |
||
| 4515 | if not group_id: |
||
| 4516 | raise RequiredArgument( |
||
| 4517 | function=self.modify_group.__name__, argument='group_id' |
||
| 4518 | ) |
||
| 4519 | |||
| 4520 | cmd = XmlCommand("modify_group") |
||
| 4521 | cmd.set_attribute("group_id", group_id) |
||
| 4522 | |||
| 4523 | if comment: |
||
| 4524 | cmd.add_element("comment", comment) |
||
| 4525 | |||
| 4526 | if name: |
||
| 4527 | cmd.add_element("name", name) |
||
| 4528 | |||
| 4529 | if users: |
||
| 4530 | cmd.add_element("users", to_comma_list(users)) |
||
| 4531 | |||
| 4532 | return self._send_xml_command(cmd) |
||
| 4533 | |||
| 4534 | def modify_report_format( |
||
| 4535 | self, |
||
| 4536 | report_format_id: Optional[Union[str, ReportFormatType]] = None, |
||
| 4537 | *, |
||
| 4538 | active: Optional[bool] = None, |
||
| 4539 | name: Optional[str] = None, |
||
| 4540 | summary: Optional[str] = None, |
||
| 4541 | param_name: Optional[str] = None, |
||
| 4542 | param_value: Optional[str] = None, |
||
| 4543 | ) -> Any: |
||
| 4544 | """Modifies an existing report format. |
||
| 4545 | |||
| 4546 | Arguments: |
||
| 4547 | report_format_id: UUID of report format to modify |
||
| 4548 | or ReportFormatType (enum) |
||
| 4549 | active: Whether the report format is active. |
||
| 4550 | name: The name of the report format. |
||
| 4551 | summary: A summary of the report format. |
||
| 4552 | param_name: The name of the param. |
||
| 4553 | param_value: The value of the param. |
||
| 4554 | |||
| 4555 | Returns: |
||
| 4556 | The response. See :py:meth:`send_command` for details. |
||
| 4557 | """ |
||
| 4558 | if not report_format_id: |
||
| 4559 | raise RequiredArgument( |
||
| 4560 | function=self.modify_report_format.__name__, |
||
| 4561 | argument='report_format_id ', |
||
| 4562 | ) |
||
| 4563 | |||
| 4564 | cmd = XmlCommand("modify_report_format") |
||
| 4565 | |||
| 4566 | if isinstance(report_format_id, ReportFormatType): |
||
| 4567 | report_format_id = report_format_id.value |
||
| 4568 | |||
| 4569 | cmd.set_attribute("report_format_id", report_format_id) |
||
| 4570 | |||
| 4571 | if active is not None: |
||
| 4572 | cmd.add_element("active", to_bool(active)) |
||
| 4573 | |||
| 4574 | if name: |
||
| 4575 | cmd.add_element("name", name) |
||
| 4576 | |||
| 4577 | if summary: |
||
| 4578 | cmd.add_element("summary", summary) |
||
| 4579 | |||
| 4580 | if param_name: |
||
| 4581 | _xmlparam = cmd.add_element("param") |
||
| 4582 | _xmlparam.add_element("name", param_name) |
||
| 4583 | |||
| 4584 | if param_value is not None: |
||
| 4585 | _xmlparam.add_element("value", param_value) |
||
| 4586 | |||
| 4587 | return self._send_xml_command(cmd) |
||
| 4588 | |||
| 4589 | View Code Duplication | def modify_role( |
|
| 4590 | self, |
||
| 4591 | role_id: str, |
||
| 4592 | *, |
||
| 4593 | comment: Optional[str] = None, |
||
| 4594 | name: Optional[str] = None, |
||
| 4595 | users: Optional[List[str]] = None, |
||
| 4596 | ) -> Any: |
||
| 4597 | """Modifies an existing role. |
||
| 4598 | |||
| 4599 | Arguments: |
||
| 4600 | role_id: UUID of role to modify. |
||
| 4601 | comment: Name of role. |
||
| 4602 | name: Comment on role. |
||
| 4603 | users: List of user names. |
||
| 4604 | |||
| 4605 | Returns: |
||
| 4606 | The response. See :py:meth:`send_command` for details. |
||
| 4607 | """ |
||
| 4608 | if not role_id: |
||
| 4609 | raise RequiredArgument( |
||
| 4610 | function=self.modify_role.__name__, argument='role_id argument' |
||
| 4611 | ) |
||
| 4612 | |||
| 4613 | cmd = XmlCommand("modify_role") |
||
| 4614 | cmd.set_attribute("role_id", role_id) |
||
| 4615 | |||
| 4616 | if comment: |
||
| 4617 | cmd.add_element("comment", comment) |
||
| 4618 | |||
| 4619 | if name: |
||
| 4620 | cmd.add_element("name", name) |
||
| 4621 | |||
| 4622 | if users: |
||
| 4623 | cmd.add_element("users", to_comma_list(users)) |
||
| 4624 | |||
| 4625 | return self._send_xml_command(cmd) |
||
| 4626 | |||
| 4627 | def modify_scanner( |
||
| 4628 | self, |
||
| 4629 | scanner_id: str, |
||
| 4630 | *, |
||
| 4631 | scanner_type: Optional[ScannerType] = None, |
||
| 4632 | host: Optional[str] = None, |
||
| 4633 | port: Optional[int] = None, |
||
| 4634 | comment: Optional[str] = None, |
||
| 4635 | name: Optional[str] = None, |
||
| 4636 | ca_pub: Optional[str] = None, |
||
| 4637 | credential_id: Optional[str] = None, |
||
| 4638 | ) -> Any: |
||
| 4639 | """Modifies an existing scanner. |
||
| 4640 | |||
| 4641 | Arguments: |
||
| 4642 | scanner_id: UUID of scanner to modify. |
||
| 4643 | scanner_type: New type of the Scanner. |
||
| 4644 | host: Host of the scanner. |
||
| 4645 | port: Port of the scanner. |
||
| 4646 | comment: Comment on scanner. |
||
| 4647 | name: Name of scanner. |
||
| 4648 | ca_pub: Certificate of CA to verify scanner's certificate. |
||
| 4649 | credential_id: UUID of the client certificate credential for the |
||
| 4650 | Scanner. |
||
| 4651 | |||
| 4652 | Returns: |
||
| 4653 | The response. See :py:meth:`send_command` for details. |
||
| 4654 | """ |
||
| 4655 | if not scanner_id: |
||
| 4656 | raise RequiredArgument( |
||
| 4657 | function=self.modify_scanner.__name__, |
||
| 4658 | argument='scanner_id argument', |
||
| 4659 | ) |
||
| 4660 | |||
| 4661 | cmd = XmlCommand("modify_scanner") |
||
| 4662 | cmd.set_attribute("scanner_id", scanner_id) |
||
| 4663 | |||
| 4664 | if scanner_type is not None: |
||
| 4665 | if not isinstance(scanner_type, self.types.ScannerType): |
||
| 4666 | raise InvalidArgumentType( |
||
| 4667 | function=self.modify_scanner.__name__, |
||
| 4668 | argument='scanner_type', |
||
| 4669 | arg_type=self.types.ScannerType.__name__, |
||
| 4670 | ) |
||
| 4671 | |||
| 4672 | cmd.add_element("type", scanner_type.value) |
||
| 4673 | |||
| 4674 | if host: |
||
| 4675 | cmd.add_element("host", host) |
||
| 4676 | |||
| 4677 | if port: |
||
| 4678 | cmd.add_element("port", str(port)) |
||
| 4679 | |||
| 4680 | if comment: |
||
| 4681 | cmd.add_element("comment", comment) |
||
| 4682 | |||
| 4683 | if name: |
||
| 4684 | cmd.add_element("name", name) |
||
| 4685 | |||
| 4686 | if ca_pub: |
||
| 4687 | cmd.add_element("ca_pub", ca_pub) |
||
| 4688 | |||
| 4689 | if credential_id: |
||
| 4690 | cmd.add_element("credential", attrs={"id": str(credential_id)}) |
||
| 4691 | |||
| 4692 | return self._send_xml_command(cmd) |
||
| 4693 | |||
| 4694 | def modify_setting( |
||
| 4695 | self, |
||
| 4696 | setting_id: Optional[str] = None, |
||
| 4697 | name: Optional[str] = None, |
||
| 4698 | value: Optional[str] = None, |
||
| 4699 | ) -> Any: |
||
| 4700 | """Modifies an existing setting. |
||
| 4701 | |||
| 4702 | Arguments: |
||
| 4703 | setting_id: UUID of the setting to be changed. |
||
| 4704 | name: The name of the setting. Either setting_id or name must be |
||
| 4705 | passed. |
||
| 4706 | value: The value of the setting. |
||
| 4707 | |||
| 4708 | Returns: |
||
| 4709 | The response. See :py:meth:`send_command` for details. |
||
| 4710 | """ |
||
| 4711 | if not setting_id and not name: |
||
| 4712 | raise RequiredArgument( |
||
| 4713 | function=self.modify_setting.__name__, |
||
| 4714 | argument='setting_id or name argument', |
||
| 4715 | ) |
||
| 4716 | |||
| 4717 | if value is None: |
||
| 4718 | raise RequiredArgument( |
||
| 4719 | function=self.modify_setting.__name__, argument='value argument' |
||
| 4720 | ) |
||
| 4721 | |||
| 4722 | cmd = XmlCommand("modify_setting") |
||
| 4723 | |||
| 4724 | if setting_id: |
||
| 4725 | cmd.set_attribute("setting_id", setting_id) |
||
| 4726 | else: |
||
| 4727 | cmd.add_element("name", name) |
||
| 4728 | |||
| 4729 | cmd.add_element("value", to_base64(value)) |
||
| 4730 | |||
| 4731 | return self._send_xml_command(cmd) |
||
| 4732 | |||
| 4733 | View Code Duplication | def modify_user( |
|
| 4734 | self, |
||
| 4735 | user_id: str = None, |
||
| 4736 | name: str = None, |
||
| 4737 | *, |
||
| 4738 | new_name: Optional[str] = None, |
||
| 4739 | comment: Optional[str] = None, |
||
| 4740 | password: Optional[str] = None, |
||
| 4741 | auth_source: Optional[UserAuthType] = None, |
||
| 4742 | role_ids: Optional[List[str]] = None, |
||
| 4743 | hosts: Optional[List[str]] = None, |
||
| 4744 | hosts_allow: Optional[bool] = False, |
||
| 4745 | ifaces: Optional[List[str]] = None, |
||
| 4746 | ifaces_allow: Optional[bool] = False, |
||
| 4747 | group_ids: Optional[List[str]] = None, |
||
| 4748 | ) -> Any: |
||
| 4749 | """Modifies an existing user. Most of the fields need to be supplied |
||
| 4750 | for changing a single field even if no change is wanted for those. |
||
| 4751 | Else empty values are inserted for the missing fields instead. |
||
| 4752 | Arguments: |
||
| 4753 | user_id: UUID of the user to be modified. Overrides name element |
||
| 4754 | argument. |
||
| 4755 | name: The name of the user to be modified. Either user_id or name |
||
| 4756 | must be passed. |
||
| 4757 | new_name: The new name for the user. |
||
| 4758 | comment: Comment on the user. |
||
| 4759 | password: The password for the user. |
||
| 4760 | auth_source: Source allowed for authentication for this user. |
||
| 4761 | roles_id: List of roles UUIDs for the user. |
||
| 4762 | hosts: User access rules: List of hosts. |
||
| 4763 | hosts_allow: Defines how the hosts list is to be interpreted. |
||
| 4764 | If False (default) the list is treated as a deny list. |
||
| 4765 | All hosts are allowed by default except those provided by |
||
| 4766 | the hosts parameter. If True the list is treated as a |
||
| 4767 | allow list. All hosts are denied by default except those |
||
| 4768 | provided by the hosts parameter. |
||
| 4769 | ifaces: User access rules: List of ifaces. |
||
| 4770 | ifaces_allow: Defines how the ifaces list is to be interpreted. |
||
| 4771 | If False (default) the list is treated as a deny list. |
||
| 4772 | All ifaces are allowed by default except those provided by |
||
| 4773 | the ifaces parameter. If True the list is treated as a |
||
| 4774 | allow list. All ifaces are denied by default except those |
||
| 4775 | provided by the ifaces parameter. |
||
| 4776 | group_ids: List of group UUIDs for the user. |
||
| 4777 | |||
| 4778 | Returns: |
||
| 4779 | The response. See :py:meth:`send_command` for details. |
||
| 4780 | """ |
||
| 4781 | if not user_id and not name: |
||
| 4782 | raise RequiredArgument( |
||
| 4783 | function=self.modify_user.__name__, argument='user_id or name' |
||
| 4784 | ) |
||
| 4785 | |||
| 4786 | cmd = XmlCommand("modify_user") |
||
| 4787 | |||
| 4788 | if user_id: |
||
| 4789 | cmd.set_attribute("user_id", user_id) |
||
| 4790 | else: |
||
| 4791 | cmd.add_element("name", name) |
||
| 4792 | |||
| 4793 | if new_name: |
||
| 4794 | cmd.add_element("new_name", new_name) |
||
| 4795 | |||
| 4796 | if role_ids: |
||
| 4797 | for role in role_ids: |
||
| 4798 | cmd.add_element("role", attrs={"id": role}) |
||
| 4799 | |||
| 4800 | if hosts: |
||
| 4801 | cmd.add_element( |
||
| 4802 | "hosts", |
||
| 4803 | to_comma_list(hosts), |
||
| 4804 | attrs={"allow": to_bool(hosts_allow)}, |
||
| 4805 | ) |
||
| 4806 | |||
| 4807 | if ifaces: |
||
| 4808 | cmd.add_element( |
||
| 4809 | "ifaces", |
||
| 4810 | to_comma_list(ifaces), |
||
| 4811 | attrs={"allow": to_bool(ifaces_allow)}, |
||
| 4812 | ) |
||
| 4813 | |||
| 4814 | if comment: |
||
| 4815 | cmd.add_element("comment", comment) |
||
| 4816 | |||
| 4817 | if password: |
||
| 4818 | cmd.add_element("password", password) |
||
| 4819 | |||
| 4820 | if auth_source: |
||
| 4821 | _xmlauthsrc = cmd.add_element("sources") |
||
| 4822 | _xmlauthsrc.add_element("source", auth_source.value) |
||
| 4823 | |||
| 4824 | if group_ids: |
||
| 4825 | _xmlgroups = cmd.add_element("groups") |
||
| 4826 | for group_id in group_ids: |
||
| 4827 | _xmlgroups.add_element("group", attrs={"id": group_id}) |
||
| 4828 | |||
| 4829 | return self._send_xml_command(cmd) |
||
| 4830 | |||
| 4831 | def restore(self, entity_id: str) -> Any: |
||
| 4832 | """Restore an entity from the trashcan |
||
| 4833 | |||
| 4834 | Arguments: |
||
| 4835 | entity_id: ID of the entity to be restored from the trashcan |
||
| 4836 | |||
| 4837 | Returns: |
||
| 4838 | The response. See :py:meth:`send_command` for details. |
||
| 4839 | """ |
||
| 4840 | if not entity_id: |
||
| 4841 | raise RequiredArgument( |
||
| 4842 | function=self.restore.__name__, argument='entity_id' |
||
| 4843 | ) |
||
| 4844 | |||
| 4845 | cmd = XmlCommand("restore") |
||
| 4846 | cmd.set_attribute("id", entity_id) |
||
| 4847 | |||
| 4848 | return self._send_xml_command(cmd) |
||
| 4849 | |||
| 4850 | def sync_cert(self) -> Any: |
||
| 4851 | """Request a synchronization with the CERT feed service |
||
| 4852 | |||
| 4853 | Returns: |
||
| 4854 | The response. See :py:meth:`send_command` for details. |
||
| 4855 | """ |
||
| 4856 | return self._send_xml_command(XmlCommand("sync_cert")) |
||
| 4857 | |||
| 4858 | def sync_config(self) -> Any: |
||
| 4859 | """Request an OSP config synchronization with scanner |
||
| 4860 | |||
| 4861 | Returns: |
||
| 4862 | The response. See :py:meth:`send_command` for details. |
||
| 4863 | """ |
||
| 4864 | return self._send_xml_command(XmlCommand("sync_config")) |
||
| 4865 | |||
| 4866 | def sync_feed(self) -> Any: |
||
| 4867 | """Request a synchronization with the NVT feed service |
||
| 4868 | |||
| 4869 | Returns: |
||
| 4870 | The response. See :py:meth:`send_command` for details. |
||
| 4871 | """ |
||
| 4872 | return self._send_xml_command(XmlCommand("sync_feed")) |
||
| 4873 | |||
| 4874 | def sync_scap(self) -> Any: |
||
| 4875 | """Request a synchronization with the SCAP feed service |
||
| 4876 | |||
| 4877 | Returns: |
||
| 4878 | The response. See :py:meth:`send_command` for details. |
||
| 4879 | """ |
||
| 4880 | return self._send_xml_command(XmlCommand("sync_scap")) |
||
| 4881 | |||
| 4882 | View Code Duplication | def verify_report_format( |
|
| 4883 | self, report_format_id: Union[str, ReportFormatType] |
||
| 4884 | ) -> Any: |
||
| 4885 | """Verify an existing report format |
||
| 4886 | |||
| 4887 | Verifies the trust level of an existing report format. It will be |
||
| 4888 | checked whether the signature of the report format currently matches the |
||
| 4889 | report format. This includes the script and files used to generate |
||
| 4890 | reports of this format. It is *not* verified if the report format works |
||
| 4891 | as expected by the user. |
||
| 4892 | |||
| 4893 | Arguments: |
||
| 4894 | report_format_id: UUID of the report format to be verified |
||
| 4895 | or ReportFormatType (enum) |
||
| 4896 | |||
| 4897 | Returns: |
||
| 4898 | The response. See :py:meth:`send_command` for details. |
||
| 4899 | """ |
||
| 4900 | if not report_format_id: |
||
| 4901 | raise RequiredArgument( |
||
| 4902 | function=self.verify_report_format.__name__, |
||
| 4903 | argument='report_format_id', |
||
| 4904 | ) |
||
| 4905 | |||
| 4906 | cmd = XmlCommand("verify_report_format") |
||
| 4907 | |||
| 4908 | if isinstance(report_format_id, ReportFormatType): |
||
| 4909 | report_format_id = report_format_id.value |
||
| 4910 | |||
| 4911 | cmd.set_attribute("report_format_id", report_format_id) |
||
| 4912 | |||
| 4913 | return self._send_xml_command(cmd) |
||
| 4914 | |||
| 4915 | def verify_scanner(self, scanner_id: str) -> Any: |
||
| 4916 | """Verify an existing scanner |
||
| 4917 | |||
| 4918 | Verifies if it is possible to connect to an existing scanner. It is |
||
| 4919 | *not* verified if the scanner works as expected by the user. |
||
| 4920 | |||
| 4921 | Arguments: |
||
| 4922 | scanner_id: UUID of the scanner to be verified |
||
| 4923 | |||
| 4924 | Returns: |
||
| 4925 | The response. See :py:meth:`send_command` for details. |
||
| 4926 | """ |
||
| 4927 | if not scanner_id: |
||
| 4928 | raise RequiredArgument( |
||
| 4929 | function=self.verify_scanner.__name__, argument='scanner_id' |
||
| 4930 | ) |
||
| 4931 | |||
| 4932 | cmd = XmlCommand("verify_scanner") |
||
| 4933 | cmd.set_attribute("scanner_id", scanner_id) |
||
| 4934 | |||
| 4935 | return self._send_xml_command(cmd) |
||
| 4936 |