Code Duplication    Length = 58-69 lines in 2 locations

gvm/protocols/gmpv7.py 2 locations

@@ 742-810 (lines=69) @@
739
        cmd.add_element('copy', note_id)
740
        return self._send_xml_command(cmd)
741
742
    def create_override(self, text, nvt_oid, *, seconds_active=None, hosts=None,
743
                        port=None, result_id=None, severity=None, comment=None,
744
                        new_severity=None, task_id=None, threat=None,
745
                        new_threat=None):
746
        """Create a new override
747
748
        Arguments:
749
            text (str): Text of the new override
750
            nvt_id (str): OID of the nvt to which override applies
751
            seconds_active (int, optional): Seconds override will be active.
752
                -1 on always, 0 off
753
            comment (str, optional): Comment for the override
754
            hosts (list, optional): A list of host addresses
755
            port (str, optional): Port to which the override applies
756
            result_id (str, optional): UUID of a result to which override
757
                applies
758
            severity (decimal, optional): Severity to which override applies
759
            new_severity (decimal, optional): New severity for result
760
            task_id (str, optional): UUID of task to which override applies
761
            threat (str, optional): Threat level to which override applies. Will
762
                be converted to severity
763
            new_threat (str, optional): New threat level for result, will be
764
                converted to a new_severity
765
766
        Returns:
767
            The response. See :py:meth:`send_command` for details.
768
        """
769
        if not text:
770
            raise RequiredArgument('create_override requires a text argument')
771
772
        if not nvt_oid:
773
            raise RequiredArgument('create_override requires a nvt_oid '
774
                                   'argument')
775
776
        cmd = XmlCommand('create_override')
777
        cmd.add_element('text', text)
778
        cmd.add_element('nvt', attrs={'oid': nvt_oid})
779
780
        if not seconds_active is None:
781
            cmd.add_element('active', str(seconds_active))
782
783
        if comment:
784
            cmd.add_element('comment', comment)
785
786
        if hosts:
787
            cmd.add_element('hosts', ', '.join(hosts))
788
789
        if port:
790
            cmd.add_element('port', port)
791
792
        if result_id:
793
            cmd.add_element('result', attrs={'id': result_id})
794
795
        if severity:
796
            cmd.add_element('severity', severity)
797
798
        if new_severity:
799
            cmd.add_element('new_severity', new_severity)
800
801
        if task_id:
802
            cmd.add_element('task', attrs={'id': task_id})
803
804
        if threat:
805
            cmd.add_element('threat', threat)
806
807
        if new_threat:
808
            cmd.add_element('new_threat', new_threat)
809
810
        return self._send_xml_command(cmd)
811
812
    def clone_override(self, override_id):
813
        """Clone an existing override
@@ 3695-3752 (lines=58) @@
3692
3693
        return self._send_xml_command(cmd)
3694
3695
    def modify_override(self, override_id, text, *, seconds_active=None,
3696
                        hosts=None, port=None, result_id=None, severity=None,
3697
                        new_severity=None, task_id=None, threat=None,
3698
                        new_threat=None):
3699
        """Modifies an existing override.
3700
3701
        Arguments:
3702
            override_id (str): UUID of override to modify.
3703
            text (str): The text of the override.
3704
            seconds_active (int, optional): Seconds override will be active.
3705
                -1 on always, 0 off.
3706
            hosts (list, optional): A list of host addresses
3707
            port (str, optional): Port to which override applies.
3708
            result_id (str, optional): Result to which override applies.
3709
            severity (str, optional): Severity to which override applies.
3710
            new_severity (str, optional): New severity score for result.
3711
            task_id (str, optional): Task to which override applies.
3712
            threat (str, optional): Threat level to which override applies.
3713
            new_threat (str, optional): New threat level for results.
3714
3715
        Returns:
3716
            The response. See :py:meth:`send_command` for details.
3717
        """
3718
        if not override_id:
3719
            raise RequiredArgument('modify_override requires a override_id '
3720
                                   'argument')
3721
        if not text:
3722
            raise RequiredArgument('modify_override requires a text argument')
3723
3724
        cmd = XmlCommand('modify_override')
3725
        cmd.set_attribute('override_id', override_id)
3726
        cmd.add_element('text', text)
3727
3728
        if not seconds_active is None:
3729
            cmd.add_element('active', str(seconds_active))
3730
3731
        if hosts:
3732
            cmd.add_element('hosts', ', '.join(hosts))
3733
3734
        if port:
3735
            cmd.add_element('port', port)
3736
3737
        if result_id:
3738
            cmd.add_element('result', attrs={'id': result_id})
3739
3740
        if severity:
3741
            cmd.add_element('severity', severity)
3742
3743
        if new_severity:
3744
            cmd.add_element('new_severity', new_severity)
3745
3746
        if task_id:
3747
            cmd.add_element('task', attrs={'id': task_id})
3748
3749
        if threat:
3750
            cmd.add_element('threat', threat)
3751
3752
        if new_threat:
3753
            cmd.add_element('new_threat', new_threat)
3754
3755
        return self._send_xml_command(cmd)