Code Duplication    Length = 74-74 lines in 2 locations

gvm/protocols/gmpv208/gmpv208.py 2 locations

@@ 5536-5609 (lines=74) @@
5533
5534
        return self._send_xml_command(cmd)
5535
5536
    def modify_note(
5537
        self,
5538
        note_id: str,
5539
        text: str,
5540
        *,
5541
        days_active: Optional[int] = None,
5542
        hosts: Optional[List[str]] = None,
5543
        port: Optional[int] = None,
5544
        result_id: Optional[str] = None,
5545
        severity: Optional[Severity] = None,
5546
        task_id: Optional[str] = None,
5547
        threat: Optional[SeverityLevel] = None,
5548
    ) -> Any:
5549
        """Modifies an existing note.
5550
5551
        Arguments:
5552
            note_id: UUID of note to modify.
5553
            text: The text of the note.
5554
            days_active: Days note will be active. -1 on always, 0 off.
5555
            hosts: A list of hosts addresses
5556
            port: Port to which note applies.
5557
            result_id: Result to which note applies.
5558
            severity: Severity to which note applies.
5559
            task_id: Task to which note applies.
5560
            threat: Threat level to which note applies. Will be converted to
5561
                severity.
5562
5563
        Returns:
5564
            The response. See :py:meth:`send_command` for details.
5565
        """
5566
        if not note_id:
5567
            raise RequiredArgument(
5568
                function=self.modify_note.__name__, argument='note_id'
5569
            )
5570
5571
        if not text:
5572
            raise RequiredArgument(
5573
                function=self.modify_note.__name__, argument='text'
5574
            )
5575
5576
        cmd = XmlCommand("modify_note")
5577
        cmd.set_attribute("note_id", note_id)
5578
        cmd.add_element("text", text)
5579
5580
        if days_active is not None:
5581
            cmd.add_element("active", str(days_active))
5582
5583
        if hosts:
5584
            cmd.add_element("hosts", to_comma_list(hosts))
5585
5586
        if port:
5587
            cmd.add_element("port", str(port))
5588
5589
        if result_id:
5590
            cmd.add_element("result", attrs={"id": result_id})
5591
5592
        if severity:
5593
            cmd.add_element("severity", str(severity))
5594
5595
        if task_id:
5596
            cmd.add_element("task", attrs={"id": task_id})
5597
5598
        if threat is not None:
5599
5600
            if not isinstance(threat, SeverityLevel):
5601
                raise InvalidArgumentType(
5602
                    function=self.modify_note.__name__,
5603
                    argument='threat',
5604
                    arg_type=SeverityLevel.__name__,
5605
                )
5606
5607
            cmd.add_element("threat", threat.value)
5608
5609
        return self._send_xml_command(cmd)
5610
5611
    def modify_override(
5612
        self,
@@ 3123-3196 (lines=74) @@
3120
3121
        return self._send_xml_command(cmd)
3122
3123
    def create_note(
3124
        self,
3125
        text: str,
3126
        nvt_oid: str,
3127
        *,
3128
        days_active: Optional[int] = None,
3129
        hosts: Optional[List[str]] = None,
3130
        port: Optional[int] = None,
3131
        result_id: Optional[str] = None,
3132
        severity: Optional[Severity] = None,
3133
        task_id: Optional[str] = None,
3134
        threat: Optional[SeverityLevel] = None,
3135
    ) -> Any:
3136
        """Create a new note
3137
3138
        Arguments:
3139
            text: Text of the new note
3140
            nvt_id: OID of the nvt to which note applies
3141
            days_active: Days note will be active. -1 on
3142
                always, 0 off
3143
            hosts: A list of hosts addresses
3144
            port: Port to which the note applies
3145
            result_id: UUID of a result to which note applies
3146
            severity: Severity to which note applies
3147
            task_id: UUID of task to which note applies
3148
            threat: Severity level to which note applies. Will be converted to
3149
                severity.
3150
3151
        Returns:
3152
            The response. See :py:meth:`send_command` for details.
3153
        """
3154
        if not text:
3155
            raise RequiredArgument(
3156
                function=self.create_note.__name__, argument='text'
3157
            )
3158
3159
        if not nvt_oid:
3160
            raise RequiredArgument(
3161
                function=self.create_note.__name__, argument='nvt_oid'
3162
            )
3163
3164
        cmd = XmlCommand("create_note")
3165
        cmd.add_element("text", text)
3166
        cmd.add_element("nvt", attrs={"oid": nvt_oid})
3167
3168
        if days_active is not None:
3169
            cmd.add_element("active", str(days_active))
3170
3171
        if hosts:
3172
            cmd.add_element("hosts", to_comma_list(hosts))
3173
3174
        if port:
3175
            cmd.add_element("port", str(port))
3176
3177
        if result_id:
3178
            cmd.add_element("result", attrs={"id": result_id})
3179
3180
        if severity:
3181
            cmd.add_element("severity", str(severity))
3182
3183
        if task_id:
3184
            cmd.add_element("task", attrs={"id": task_id})
3185
3186
        if threat is not None:
3187
            if not isinstance(threat, SeverityLevel):
3188
                raise InvalidArgumentType(
3189
                    function="create_note",
3190
                    argument="threat",
3191
                    arg_type=SeverityLevel.__name__,
3192
                )
3193
3194
            cmd.add_element("threat", threat.value)
3195
3196
        return self._send_xml_command(cmd)
3197
3198
    def clone_note(self, note_id: str) -> Any:
3199
        """Clone an existing note