Code Duplication    Length = 74-74 lines in 2 locations

gvm/protocols/gmpv208/gmpv208.py 2 locations

@@ 6290-6363 (lines=74) @@
6287
6288
        return self._send_xml_command(cmd)
6289
6290
    def modify_note(
6291
        self,
6292
        note_id: str,
6293
        text: str,
6294
        *,
6295
        days_active: Optional[int] = None,
6296
        hosts: Optional[List[str]] = None,
6297
        port: Optional[int] = None,
6298
        result_id: Optional[str] = None,
6299
        severity: Optional[Severity] = None,
6300
        task_id: Optional[str] = None,
6301
        threat: Optional[SeverityLevel] = None,
6302
    ) -> Any:
6303
        """Modifies an existing note.
6304
6305
        Arguments:
6306
            note_id: UUID of note to modify.
6307
            text: The text of the note.
6308
            days_active: Days note will be active. -1 on always, 0 off.
6309
            hosts: A list of hosts addresses
6310
            port: Port to which note applies.
6311
            result_id: Result to which note applies.
6312
            severity: Severity to which note applies.
6313
            task_id: Task to which note applies.
6314
            threat: Threat level to which note applies. Will be converted to
6315
                severity.
6316
6317
        Returns:
6318
            The response. See :py:meth:`send_command` for details.
6319
        """
6320
        if not note_id:
6321
            raise RequiredArgument(
6322
                function=self.modify_note.__name__, argument='note_id'
6323
            )
6324
6325
        if not text:
6326
            raise RequiredArgument(
6327
                function=self.modify_note.__name__, argument='text'
6328
            )
6329
6330
        cmd = XmlCommand("modify_note")
6331
        cmd.set_attribute("note_id", note_id)
6332
        cmd.add_element("text", text)
6333
6334
        if days_active is not None:
6335
            cmd.add_element("active", str(days_active))
6336
6337
        if hosts:
6338
            cmd.add_element("hosts", _to_comma_list(hosts))
6339
6340
        if port:
6341
            cmd.add_element("port", str(port))
6342
6343
        if result_id:
6344
            cmd.add_element("result", attrs={"id": result_id})
6345
6346
        if severity:
6347
            cmd.add_element("severity", str(severity))
6348
6349
        if task_id:
6350
            cmd.add_element("task", attrs={"id": task_id})
6351
6352
        if threat is not None:
6353
6354
            if not isinstance(threat, SeverityLevel):
6355
                raise InvalidArgumentType(
6356
                    function=self.modify_note.__name__,
6357
                    argument='threat',
6358
                    arg_type=SeverityLevel.__name__,
6359
                )
6360
6361
            cmd.add_element("threat", threat.value)
6362
6363
        return self._send_xml_command(cmd)
6364
6365
    def modify_override(
6366
        self,
@@ 3391-3464 (lines=74) @@
3388
3389
        return self._send_xml_command(cmd)
3390
3391
    def create_note(
3392
        self,
3393
        text: str,
3394
        nvt_oid: str,
3395
        *,
3396
        days_active: Optional[int] = None,
3397
        hosts: Optional[List[str]] = None,
3398
        port: Optional[int] = None,
3399
        result_id: Optional[str] = None,
3400
        severity: Optional[Severity] = None,
3401
        task_id: Optional[str] = None,
3402
        threat: Optional[SeverityLevel] = None,
3403
    ) -> Any:
3404
        """Create a new note
3405
3406
        Arguments:
3407
            text: Text of the new note
3408
            nvt_id: OID of the nvt to which note applies
3409
            days_active: Days note will be active. -1 on
3410
                always, 0 off
3411
            hosts: A list of hosts addresses
3412
            port: Port to which the note applies
3413
            result_id: UUID of a result to which note applies
3414
            severity: Severity to which note applies
3415
            task_id: UUID of task to which note applies
3416
            threat: Severity level to which note applies. Will be converted to
3417
                severity.
3418
3419
        Returns:
3420
            The response. See :py:meth:`send_command` for details.
3421
        """
3422
        if not text:
3423
            raise RequiredArgument(
3424
                function=self.create_note.__name__, argument='text'
3425
            )
3426
3427
        if not nvt_oid:
3428
            raise RequiredArgument(
3429
                function=self.create_note.__name__, argument='nvt_oid'
3430
            )
3431
3432
        cmd = XmlCommand("create_note")
3433
        cmd.add_element("text", text)
3434
        cmd.add_element("nvt", attrs={"oid": nvt_oid})
3435
3436
        if days_active is not None:
3437
            cmd.add_element("active", str(days_active))
3438
3439
        if hosts:
3440
            cmd.add_element("hosts", _to_comma_list(hosts))
3441
3442
        if port:
3443
            cmd.add_element("port", str(port))
3444
3445
        if result_id:
3446
            cmd.add_element("result", attrs={"id": result_id})
3447
3448
        if severity:
3449
            cmd.add_element("severity", str(severity))
3450
3451
        if task_id:
3452
            cmd.add_element("task", attrs={"id": task_id})
3453
3454
        if threat is not None:
3455
            if not isinstance(threat, SeverityLevel):
3456
                raise InvalidArgumentType(
3457
                    function="create_note",
3458
                    argument="threat",
3459
                    arg_type=SeverityLevel.__name__,
3460
                )
3461
3462
            cmd.add_element("threat", threat.value)
3463
3464
        return self._send_xml_command(cmd)
3465
3466
    def clone_note(self, note_id: str) -> Any:
3467
        """Clone an existing note