Code Duplication    Length = 71-71 lines in 2 locations

gvm/protocols/gmpv7.py 2 locations

@@ 5282-5352 (lines=71) @@
5279
5280
        return self._send_xml_command(cmd)
5281
5282
    def modify_note(
5283
        self,
5284
        note_id: str,
5285
        text: str,
5286
        *,
5287
        seconds_active: Optional[int] = None,
5288
        hosts: Optional[List[str]] = None,
5289
        port: Optional[int] = None,
5290
        result_id: Optional[str] = None,
5291
        severity: Optional[Severity] = None,
5292
        task_id: Optional[str] = None,
5293
        threat: Optional[SeverityLevel] = None
5294
    ) -> Any:
5295
        """Modifies an existing note.
5296
5297
        Arguments:
5298
            note_id: UUID of note to modify.
5299
            text: The text of the note.
5300
            seconds_active: Seconds note will be active. -1 on always, 0 off.
5301
            hosts: A list of hosts addresses
5302
            port: Port to which note applies.
5303
            result_id: Result to which note applies.
5304
            severity: Severity to which note applies.
5305
            task_id: Task to which note applies.
5306
            threat: Threat level to which note applies. Will be converted to
5307
                severity.
5308
5309
        Returns:
5310
            The response. See :py:meth:`send_command` for details.
5311
        """
5312
        if not note_id:
5313
            raise RequiredArgument("modify_note requires a note_id attribute")
5314
5315
        if not text:
5316
            raise RequiredArgument("modify_note requires a text element")
5317
5318
        cmd = XmlCommand("modify_note")
5319
        cmd.set_attribute("note_id", note_id)
5320
        cmd.add_element("text", text)
5321
5322
        if not seconds_active is None:
5323
            cmd.add_element("active", str(seconds_active))
5324
5325
        if hosts:
5326
            cmd.add_element("hosts", _to_comma_list(hosts))
5327
5328
        if port:
5329
            cmd.add_element("port", str(port))
5330
5331
        if result_id:
5332
            cmd.add_element("result", attrs={"id": result_id})
5333
5334
        if severity:
5335
            cmd.add_element("severity", str(severity))
5336
5337
        if task_id:
5338
            cmd.add_element("task", attrs={"id": task_id})
5339
5340
        if threat is not None:
5341
5342
            if not isinstance(threat, SeverityLevel):
5343
                raise InvalidArgument(
5344
                    "modify_note threat argument {} is invalid. threat must "
5345
                    "be a SeverityLevel instance".format(threat),
5346
                    function="modify_note",
5347
                    argument="threat",
5348
                )
5349
5350
            cmd.add_element("threat", threat.value)
5351
5352
        return self._send_xml_command(cmd)
5353
5354
    def modify_override(
5355
        self,
@@ 1476-1546 (lines=71) @@
1473
1474
        return self._send_xml_command(cmd)
1475
1476
    def create_note(
1477
        self,
1478
        text: str,
1479
        nvt_oid: str,
1480
        *,
1481
        seconds_active: Optional[int] = None,
1482
        hosts: Optional[List[str]] = None,
1483
        port: Optional[int] = None,
1484
        result_id: Optional[str] = None,
1485
        severity: Optional[Severity] = None,
1486
        task_id: Optional[str] = None,
1487
        threat: Optional[SeverityLevel] = None
1488
    ) -> Any:
1489
        """Create a new note
1490
1491
        Arguments:
1492
            text: Text of the new note
1493
            nvt_id: OID of the nvt to which note applies
1494
            seconds_active: Seconds note will be active. -1 on
1495
                always, 0 off
1496
            hosts: A list of hosts addresses
1497
            port: Port to which the note applies
1498
            result_id: UUID of a result to which note applies
1499
            severity: Severity to which note applies
1500
            task_id: UUID of task to which note applies
1501
            threat: Severity level to which note applies. Will be converted to
1502
                severity.
1503
1504
        Returns:
1505
            The response. See :py:meth:`send_command` for details.
1506
        """
1507
        if not text:
1508
            raise RequiredArgument("create_note requires a text argument")
1509
1510
        if not nvt_oid:
1511
            raise RequiredArgument("create_note requires a nvt_oid argument")
1512
1513
        cmd = XmlCommand("create_note")
1514
        cmd.add_element("text", text)
1515
        cmd.add_element("nvt", attrs={"oid": nvt_oid})
1516
1517
        if not seconds_active is None:
1518
            cmd.add_element("active", str(seconds_active))
1519
1520
        if hosts:
1521
            cmd.add_element("hosts", _to_comma_list(hosts))
1522
1523
        if port:
1524
            cmd.add_element("port", str(port))
1525
1526
        if result_id:
1527
            cmd.add_element("result", attrs={"id": result_id})
1528
1529
        if severity:
1530
            cmd.add_element("severity", str(severity))
1531
1532
        if task_id:
1533
            cmd.add_element("task", attrs={"id": task_id})
1534
1535
        if threat is not None:
1536
            if not isinstance(threat, SeverityLevel):
1537
                raise InvalidArgument(
1538
                    "create_note threat argument {0} is invalid. threat must "
1539
                    "be a SeverityLevel instance",
1540
                    function="create_note",
1541
                    argument="threat",
1542
                )
1543
1544
            cmd.add_element("threat", threat.value)
1545
1546
        return self._send_xml_command(cmd)
1547
1548
    def clone_note(self, note_id: str) -> Any:
1549
        """Clone an existing note