Code Duplication    Length = 72-73 lines in 2 locations

gvm/protocols/gmpv214/gmpv214.py 2 locations

@@ 65-137 (lines=73) @@
62
        # Is authenticated on gvmd
63
        self._authenticated = False
64
65
    def create_note(
66
        self,
67
        text: str,
68
        nvt_oid: str,
69
        *,
70
        days_active: Optional[int] = None,
71
        hosts: Optional[List[str]] = None,
72
        port: Optional[int] = None,
73
        result_id: Optional[str] = None,
74
        severity: Optional[Severity] = None,
75
        task_id: Optional[str] = None,
76
        threat: Optional[SeverityLevel] = None,
77
    ) -> Any:
78
        """Create a new note
79
80
        Arguments:
81
            text: Text of the new note
82
            nvt_id: OID of the nvt to which note applies
83
            days_active: Days note will be active. -1 on
84
                always, 0 off
85
            hosts: A list of hosts addresses
86
            port: Port to which the note applies
87
            result_id: UUID of a result to which note applies
88
            severity: Severity to which note applies
89
            task_id: UUID of task to which note applies
90
            threat: Severity level to which note applies. Will be converted to
91
                severity.
92
93
        Returns:
94
            The response. See :py:meth:`send_command` for details.
95
        """
96
        if not text:
97
            raise RequiredArgument(
98
                function=self.create_note.__name__, argument='text'
99
            )
100
101
        if not nvt_oid:
102
            raise RequiredArgument(
103
                function=self.create_note.__name__, argument='nvt_oid'
104
            )
105
106
        cmd = XmlCommand("create_note")
107
        cmd.add_element("text", text)
108
        cmd.add_element("nvt", attrs={"oid": nvt_oid})
109
110
        if days_active is not None:
111
            cmd.add_element("active", str(days_active))
112
113
        if hosts:
114
            cmd.add_element("hosts", _to_comma_list(hosts))
115
116
        if port:
117
            cmd.add_element("port", str(port))
118
119
        if result_id:
120
            cmd.add_element("result", attrs={"id": result_id})
121
122
        if severity:
123
            cmd.add_element("severity", str(severity))
124
125
        if task_id:
126
            cmd.add_element("task", attrs={"id": task_id})
127
128
        if threat is not None:
129
            deprecation(
130
                "The threat parameter has been removed in GMP"
131
                " version {}{}".format(
132
                    self.get_protocol_version()[0],
133
                    self.get_protocol_version()[1],
134
                )
135
            )
136
137
        return self._send_xml_command(cmd)
138
139
    def create_override(
140
        self,
@@ 355-426 (lines=72) @@
352
353
        return self._send_xml_command(cmd)
354
355
    def modify_note(
356
        self,
357
        note_id: str,
358
        text: str,
359
        *,
360
        days_active: Optional[int] = None,
361
        hosts: Optional[List[str]] = None,
362
        port: Optional[int] = None,
363
        result_id: Optional[str] = None,
364
        severity: Optional[Severity] = None,
365
        task_id: Optional[str] = None,
366
        threat: Optional[SeverityLevel] = None,
367
    ) -> Any:
368
        """Modifies an existing note.
369
370
        Arguments:
371
            note_id: UUID of note to modify.
372
            text: The text of the note.
373
            days_active: Days note will be active. -1 on always, 0 off.
374
            hosts: A list of hosts addresses
375
            port: Port to which note applies.
376
            result_id: Result to which note applies.
377
            severity: Severity to which note applies.
378
            task_id: Task to which note applies.
379
            threat: Threat level to which note applies. Will be converted to
380
                severity.
381
382
        Returns:
383
            The response. See :py:meth:`send_command` for details.
384
        """
385
        if not note_id:
386
            raise RequiredArgument(
387
                function=self.modify_note.__name__, argument='note_id'
388
            )
389
390
        if not text:
391
            raise RequiredArgument(
392
                function=self.modify_note.__name__, argument='text'
393
            )
394
395
        cmd = XmlCommand("modify_note")
396
        cmd.set_attribute("note_id", note_id)
397
        cmd.add_element("text", text)
398
399
        if days_active is not None:
400
            cmd.add_element("active", str(days_active))
401
402
        if hosts:
403
            cmd.add_element("hosts", _to_comma_list(hosts))
404
405
        if port:
406
            cmd.add_element("port", str(port))
407
408
        if result_id:
409
            cmd.add_element("result", attrs={"id": result_id})
410
411
        if severity:
412
            cmd.add_element("severity", str(severity))
413
414
        if task_id:
415
            cmd.add_element("task", attrs={"id": task_id})
416
417
        if threat is not None:
418
            deprecation(
419
                "The threat parameter has been removed in GMP"
420
                " version {}{}".format(
421
                    self.get_protocol_version()[0],
422
                    self.get_protocol_version()[1],
423
                )
424
            )
425
426
        return self._send_xml_command(cmd)
427
428
    def modify_override(
429
        self,