Code Duplication    Length = 74-74 lines in 2 locations

gvm/protocols/gmpv7/gmpv7.py 2 locations

@@ 4903-4976 (lines=74) @@
4900
4901
        return self._send_xml_command(cmd)
4902
4903
    def modify_note(
4904
        self,
4905
        note_id: str,
4906
        text: str,
4907
        *,
4908
        seconds_active: Optional[int] = None,
4909
        hosts: Optional[List[str]] = None,
4910
        port: Optional[int] = None,
4911
        result_id: Optional[str] = None,
4912
        severity: Optional[Severity] = None,
4913
        task_id: Optional[str] = None,
4914
        threat: Optional[SeverityLevel] = None
4915
    ) -> Any:
4916
        """Modifies an existing note.
4917
4918
        Arguments:
4919
            note_id: UUID of note to modify.
4920
            text: The text of the note.
4921
            seconds_active: Seconds note will be active. -1 on always, 0 off.
4922
            hosts: A list of hosts addresses
4923
            port: Port to which note applies.
4924
            result_id: Result to which note applies.
4925
            severity: Severity to which note applies.
4926
            task_id: Task to which note applies.
4927
            threat: Threat level to which note applies. Will be converted to
4928
                severity.
4929
4930
        Returns:
4931
            The response. See :py:meth:`send_command` for details.
4932
        """
4933
        if not note_id:
4934
            raise RequiredArgument(
4935
                function=self.modify_note.__name__, argument='note_id'
4936
            )
4937
4938
        if not text:
4939
            raise RequiredArgument(
4940
                function=self.modify_note.__name__, argument='text'
4941
            )
4942
4943
        cmd = XmlCommand("modify_note")
4944
        cmd.set_attribute("note_id", note_id)
4945
        cmd.add_element("text", text)
4946
4947
        if seconds_active is not None:
4948
            cmd.add_element("active", str(seconds_active))
4949
4950
        if hosts:
4951
            cmd.add_element("hosts", _to_comma_list(hosts))
4952
4953
        if port:
4954
            cmd.add_element("port", str(port))
4955
4956
        if result_id:
4957
            cmd.add_element("result", attrs={"id": result_id})
4958
4959
        if severity:
4960
            cmd.add_element("severity", str(severity))
4961
4962
        if task_id:
4963
            cmd.add_element("task", attrs={"id": task_id})
4964
4965
        if threat is not None:
4966
4967
            if not isinstance(threat, SeverityLevel):
4968
                raise InvalidArgumentType(
4969
                    function=self.modify_note.__name__,
4970
                    argument='threat',
4971
                    arg_type=SeverityLevel.__name__,
4972
                )
4973
4974
            cmd.add_element("threat", threat.value)
4975
4976
        return self._send_xml_command(cmd)
4977
4978
    def modify_override(
4979
        self,
@@ 885-958 (lines=74) @@
882
883
        return self._send_xml_command(cmd)
884
885
    def create_note(
886
        self,
887
        text: str,
888
        nvt_oid: str,
889
        *,
890
        seconds_active: Optional[int] = None,
891
        hosts: Optional[List[str]] = None,
892
        port: Optional[int] = None,
893
        result_id: Optional[str] = None,
894
        severity: Optional[Severity] = None,
895
        task_id: Optional[str] = None,
896
        threat: Optional[SeverityLevel] = None
897
    ) -> Any:
898
        """Create a new note
899
900
        Arguments:
901
            text: Text of the new note
902
            nvt_id: OID of the nvt to which note applies
903
            seconds_active: Seconds note will be active. -1 on
904
                always, 0 off
905
            hosts: A list of hosts addresses
906
            port: Port to which the note applies
907
            result_id: UUID of a result to which note applies
908
            severity: Severity to which note applies
909
            task_id: UUID of task to which note applies
910
            threat: Severity level to which note applies. Will be converted to
911
                severity.
912
913
        Returns:
914
            The response. See :py:meth:`send_command` for details.
915
        """
916
        if not text:
917
            raise RequiredArgument(
918
                function=self.create_note.__name__, argument='text'
919
            )
920
921
        if not nvt_oid:
922
            raise RequiredArgument(
923
                function=self.create_note.__name__, argument='nvt_oid'
924
            )
925
926
        cmd = XmlCommand("create_note")
927
        cmd.add_element("text", text)
928
        cmd.add_element("nvt", attrs={"oid": nvt_oid})
929
930
        if seconds_active is not None:
931
            cmd.add_element("active", str(seconds_active))
932
933
        if hosts:
934
            cmd.add_element("hosts", _to_comma_list(hosts))
935
936
        if port:
937
            cmd.add_element("port", str(port))
938
939
        if result_id:
940
            cmd.add_element("result", attrs={"id": result_id})
941
942
        if severity:
943
            cmd.add_element("severity", str(severity))
944
945
        if task_id:
946
            cmd.add_element("task", attrs={"id": task_id})
947
948
        if threat is not None:
949
            if not isinstance(threat, SeverityLevel):
950
                raise InvalidArgumentType(
951
                    function="create_note",
952
                    argument="threat",
953
                    arg_type=SeverityLevel.__name__,
954
                )
955
956
            cmd.add_element("threat", threat.value)
957
958
        return self._send_xml_command(cmd)
959
960
    def clone_note(self, note_id: str) -> Any:
961
        """Clone an existing note