Code Duplication    Length = 58-69 lines in 2 locations

gvm/protocols/gmpv7.py 2 locations

@@ 870-938 (lines=69) @@
867
        cmd.add_element('copy', note_id)
868
        return self._send_xml_command(cmd)
869
870
    def create_override(self, text, nvt_oid, *, seconds_active=None, hosts=None,
871
                        port=None, result_id=None, severity=None, comment=None,
872
                        new_severity=None, task_id=None, threat=None,
873
                        new_threat=None):
874
        """Create a new override
875
876
        Arguments:
877
            text (str): Text of the new override
878
            nvt_id (str): OID of the nvt to which override applies
879
            seconds_active (int, optional): Seconds override will be active.
880
                -1 on always, 0 off
881
            comment (str, optional): Comment for the override
882
            hosts (list, optional): A list of host addresses
883
            port (str, optional): Port to which the override applies
884
            result_id (str, optional): UUID of a result to which override
885
                applies
886
            severity (decimal, optional): Severity to which override applies
887
            new_severity (decimal, optional): New severity for result
888
            task_id (str, optional): UUID of task to which override applies
889
            threat (str, optional): Threat level to which override applies. Will
890
                be converted to severity
891
            new_threat (str, optional): New threat level for result, will be
892
                converted to a new_severity
893
894
        Returns:
895
            The response. See :py:meth:`send_command` for details.
896
        """
897
        if not text:
898
            raise RequiredArgument('create_override requires a text argument')
899
900
        if not nvt_oid:
901
            raise RequiredArgument('create_override requires a nvt_oid '
902
                                   'argument')
903
904
        cmd = XmlCommand('create_override')
905
        cmd.add_element('text', text)
906
        cmd.add_element('nvt', attrs={'oid': nvt_oid})
907
908
        if not seconds_active is None:
909
            cmd.add_element('active', str(seconds_active))
910
911
        if comment:
912
            cmd.add_element('comment', comment)
913
914
        if hosts:
915
            cmd.add_element('hosts', ', '.join(hosts))
916
917
        if port:
918
            cmd.add_element('port', port)
919
920
        if result_id:
921
            cmd.add_element('result', attrs={'id': result_id})
922
923
        if severity:
924
            cmd.add_element('severity', severity)
925
926
        if new_severity:
927
            cmd.add_element('new_severity', new_severity)
928
929
        if task_id:
930
            cmd.add_element('task', attrs={'id': task_id})
931
932
        if threat:
933
            cmd.add_element('threat', threat)
934
935
        if new_threat:
936
            cmd.add_element('new_threat', new_threat)
937
938
        return self._send_xml_command(cmd)
939
940
    def clone_override(self, override_id):
941
        """Clone an existing override
@@ 4025-4082 (lines=58) @@
4022
4023
        return self._send_xml_command(cmd)
4024
4025
    def modify_override(self, override_id, text, *, seconds_active=None,
4026
                        hosts=None, port=None, result_id=None, severity=None,
4027
                        new_severity=None, task_id=None, threat=None,
4028
                        new_threat=None):
4029
        """Modifies an existing override.
4030
4031
        Arguments:
4032
            override_id (str): UUID of override to modify.
4033
            text (str): The text of the override.
4034
            seconds_active (int, optional): Seconds override will be active.
4035
                -1 on always, 0 off.
4036
            hosts (list, optional): A list of host addresses
4037
            port (str, optional): Port to which override applies.
4038
            result_id (str, optional): Result to which override applies.
4039
            severity (str, optional): Severity to which override applies.
4040
            new_severity (str, optional): New severity score for result.
4041
            task_id (str, optional): Task to which override applies.
4042
            threat (str, optional): Threat level to which override applies.
4043
            new_threat (str, optional): New threat level for results.
4044
4045
        Returns:
4046
            The response. See :py:meth:`send_command` for details.
4047
        """
4048
        if not override_id:
4049
            raise RequiredArgument('modify_override requires a override_id '
4050
                                   'argument')
4051
        if not text:
4052
            raise RequiredArgument('modify_override requires a text argument')
4053
4054
        cmd = XmlCommand('modify_override')
4055
        cmd.set_attribute('override_id', override_id)
4056
        cmd.add_element('text', text)
4057
4058
        if not seconds_active is None:
4059
            cmd.add_element('active', str(seconds_active))
4060
4061
        if hosts:
4062
            cmd.add_element('hosts', ', '.join(hosts))
4063
4064
        if port:
4065
            cmd.add_element('port', port)
4066
4067
        if result_id:
4068
            cmd.add_element('result', attrs={'id': result_id})
4069
4070
        if severity:
4071
            cmd.add_element('severity', severity)
4072
4073
        if new_severity:
4074
            cmd.add_element('new_severity', new_severity)
4075
4076
        if task_id:
4077
            cmd.add_element('task', attrs={'id': task_id})
4078
4079
        if threat:
4080
            cmd.add_element('threat', threat)
4081
4082
        if new_threat:
4083
            cmd.add_element('new_threat', new_threat)
4084
4085
        return self._send_xml_command(cmd)