Code Duplication    Length = 79-82 lines in 2 locations

gvm/protocols/gmpv7.py 2 locations

@@ 938-1019 (lines=82) @@
935
        cmd.add_element("copy", note_id)
936
        return self._send_xml_command(cmd)
937
938
    def create_override(
939
        self,
940
        text,
941
        nvt_oid,
942
        *,
943
        seconds_active=None,
944
        hosts=None,
945
        port=None,
946
        result_id=None,
947
        severity=None,
948
        new_severity=None,
949
        task_id=None,
950
        threat=None,
951
        new_threat=None,
952
    ):
953
        """Create a new override
954
955
        Arguments:
956
            text (str): Text of the new override
957
            nvt_id (str): OID of the nvt to which override applies
958
            seconds_active (int, optional): Seconds override will be active.
959
                -1 on always, 0 off
960
            hosts (list, optional): A list of host addresses
961
            port (int, optional): Port to which the override applies
962
            result_id (str, optional): UUID of a result to which override
963
                applies
964
            severity (decimal, optional): Severity to which override applies
965
            new_severity (decimal, optional): New severity for result
966
            task_id (str, optional): UUID of task to which override applies
967
            threat (str, optional): Threat level to which override applies. One
968
                of High, Medium, Low, Alarm, Log or Debug. Will be converted to
969
                severity.
970
            new_threat (str, optional): New threat level for results. One
971
                of High, Medium, Low, Alarm, Log or Debug. Will be converted to
972
                new_severity.
973
974
        Returns:
975
            The response. See :py:meth:`send_command` for details.
976
        """
977
        if not text:
978
            raise RequiredArgument("create_override requires a text argument")
979
980
        if not nvt_oid:
981
            raise RequiredArgument(
982
                "create_override requires a nvt_oid " "argument"
983
            )
984
985
        cmd = XmlCommand("create_override")
986
        cmd.add_element("text", text)
987
        cmd.add_element("nvt", attrs={"oid": nvt_oid})
988
989
        if not seconds_active is None:
990
            cmd.add_element("active", str(seconds_active))
991
992
        if hosts:
993
            cmd.add_element("hosts", _to_comma_list(hosts))
994
995
        if port:
996
            cmd.add_element("port", str(port))
997
998
        if result_id:
999
            cmd.add_element("result", attrs={"id": result_id})
1000
1001
        if severity:
1002
            cmd.add_element("severity", str(severity))
1003
1004
        if new_severity:
1005
            cmd.add_element("new_severity", str(new_severity))
1006
1007
        if task_id:
1008
            cmd.add_element("task", attrs={"id": task_id})
1009
1010
        if threat is not None:
1011
            if threat not in THREAD_TYPES:
1012
                raise InvalidArgument(
1013
                    "create_override threat argument {0} is invalid. threat"
1014
                    "must be one of {1}".format(threat, ", ".join(THREAD_TYPES))
1015
                )
1016
1017
            cmd.add_element("threat", threat)
1018
1019
        if new_threat is not None:
1020
            if new_threat not in THREAD_TYPES:
1021
                raise InvalidArgument(
1022
                    "create_override new_threat argument {0} is invalid. "
@@ 4614-4692 (lines=79) @@
4611
4612
        return self._send_xml_command(cmd)
4613
4614
    def modify_override(
4615
        self,
4616
        override_id,
4617
        text,
4618
        *,
4619
        seconds_active=None,
4620
        hosts=None,
4621
        port=None,
4622
        result_id=None,
4623
        severity=None,
4624
        new_severity=None,
4625
        task_id=None,
4626
        threat=None,
4627
        new_threat=None,
4628
    ):
4629
        """Modifies an existing override.
4630
4631
        Arguments:
4632
            override_id (str): UUID of override to modify.
4633
            text (str): The text of the override.
4634
            seconds_active (int, optional): Seconds override will be active.
4635
                -1 on always, 0 off.
4636
            hosts (list, optional): A list of host addresses
4637
            port (int, optional): Port to which override applies.
4638
            result_id (str, optional): Result to which override applies.
4639
            severity (decimal, optional): Severity to which override applies.
4640
            new_severity (decimal, optional): New severity score for result.
4641
            task_id (str, optional): Task to which override applies.
4642
            threat (str, optional): Threat level to which override applies. One
4643
                of High, Medium, Low, Alarm, Log or Debug. Will be converted to
4644
                severity.
4645
            new_threat (str, optional): New threat level for results. One
4646
                of High, Medium, Low, Alarm, Log or Debug. Will be converted to
4647
                new_severity.
4648
4649
        Returns:
4650
            The response. See :py:meth:`send_command` for details.
4651
        """
4652
        if not override_id:
4653
            raise RequiredArgument(
4654
                "modify_override requires a override_id " "argument"
4655
            )
4656
        if not text:
4657
            raise RequiredArgument("modify_override requires a text argument")
4658
4659
        cmd = XmlCommand("modify_override")
4660
        cmd.set_attribute("override_id", override_id)
4661
        cmd.add_element("text", text)
4662
4663
        if not seconds_active is None:
4664
            cmd.add_element("active", str(seconds_active))
4665
4666
        if hosts:
4667
            cmd.add_element("hosts", _to_comma_list(hosts))
4668
4669
        if port:
4670
            cmd.add_element("port", str(port))
4671
4672
        if result_id:
4673
            cmd.add_element("result", attrs={"id": result_id})
4674
4675
        if severity:
4676
            cmd.add_element("severity", str(severity))
4677
4678
        if new_severity:
4679
            cmd.add_element("new_severity", str(new_severity))
4680
4681
        if task_id:
4682
            cmd.add_element("task", attrs={"id": task_id})
4683
4684
        if threat is not None:
4685
            if threat not in THREAD_TYPES:
4686
                raise InvalidArgument(
4687
                    "modify_override threat argument {0} is invalid. threat"
4688
                    "must be one of {1}".format(threat, ", ".join(THREAD_TYPES))
4689
                )
4690
            cmd.add_element("threat", threat)
4691
4692
        if new_threat is not None:
4693
            if new_threat not in THREAD_TYPES:
4694
                raise InvalidArgument(
4695
                    "modify_override new_threat argument {0} is invalid. "