Code Duplication    Length = 58-69 lines in 2 locations

gvm/protocols/gmpv7.py 2 locations

@@ 685-753 (lines=69) @@
682
        cmd.add_element('copy', note_id)
683
        return self._send_xml_command(cmd)
684
685
    def create_override(self, text, nvt_oid, seconds_active=None, hosts=None,
686
                        port=None, result_id=None, severity=None, comment=None,
687
                        new_severity=None, task_id=None, threat=None,
688
                        new_threat=None):
689
        """Create a new override
690
691
        Arguments:
692
            text (str): Text of the new override
693
            nvt_id (str): OID of the nvt to which override applies
694
            seconds_active (int, optional): Seconds override will be active.
695
                -1 on always, 0 off
696
            comment (str, optional): Comment for the override
697
            hosts (list, optional): A list of host addresses
698
            port (str, optional): Port to which the override applies
699
            result_id (str, optional): UUID of a result to which override
700
                applies
701
            severity (decimal, optional): Severity to which override applies
702
            new_severity (decimal, optional): New severity for result
703
            task_id (str, optional): UUID of task to which override applies
704
            threat (str, optional): Threat level to which override applies. Will
705
                be converted to severity
706
            new_threat (str, optional): New threat level for result, will be
707
                converted to a new_severity
708
709
        Returns:
710
            The response. See :py:meth:`send_command` for details.
711
        """
712
        if not text:
713
            raise RequiredArgument('create_override requires a text argument')
714
715
        if not nvt_oid:
716
            raise RequiredArgument('create_override requires a nvt_oid '
717
                                   'argument')
718
719
        cmd = XmlCommand('create_override')
720
        cmd.add_element('text', text)
721
        cmd.add_element('nvt', attrs={'oid': nvt_oid})
722
723
        if not seconds_active is None:
724
            cmd.add_element('active', str(seconds_active))
725
726
        if comment:
727
            cmd.add_element('comment', comment)
728
729
        if hosts:
730
            cmd.add_element('hosts', ', '.join(hosts))
731
732
        if port:
733
            cmd.add_element('port', port)
734
735
        if result_id:
736
            cmd.add_element('result', attrs={'id': result_id})
737
738
        if severity:
739
            cmd.add_element('severity', severity)
740
741
        if new_severity:
742
            cmd.add_element('new_severity', new_severity)
743
744
        if task_id:
745
            cmd.add_element('task', attrs={'id': task_id})
746
747
        if threat:
748
            cmd.add_element('threat', threat)
749
750
        if new_threat:
751
            cmd.add_element('new_threat', new_threat)
752
753
        return self._send_xml_command(cmd)
754
755
    def clone_override(self, override_id):
756
        """Clone an existing override
@@ 3624-3681 (lines=58) @@
3621
3622
        return self._send_xml_command(cmd)
3623
3624
    def modify_override(self, override_id, text, seconds_active=None,
3625
                        hosts=None, port=None, result_id=None, severity=None,
3626
                        new_severity=None, task_id=None, threat=None,
3627
                        new_threat=None):
3628
        """Modifies an existing override.
3629
3630
        Arguments:
3631
            override_id (str): UUID of override to modify.
3632
            text (str): The text of the override.
3633
            seconds_active (int, optional): Seconds override will be active.
3634
                -1 on always, 0 off.
3635
            hosts (list, optional): A list of host addresses
3636
            port (str, optional): Port to which override applies.
3637
            result_id (str, optional): Result to which override applies.
3638
            severity (str, optional): Severity to which override applies.
3639
            new_severity (str, optional): New severity score for result.
3640
            task_id (str, optional): Task to which override applies.
3641
            threat (str, optional): Threat level to which override applies.
3642
            new_threat (str, optional): New threat level for results.
3643
3644
        Returns:
3645
            The response. See :py:meth:`send_command` for details.
3646
        """
3647
        if not override_id:
3648
            raise RequiredArgument('modify_override requires a override_id '
3649
                                   'argument')
3650
        if not text:
3651
            raise RequiredArgument('modify_override requires a text argument')
3652
3653
        cmd = XmlCommand('modify_override')
3654
        cmd.set_attribute('override_id', override_id)
3655
        cmd.add_element('text', text)
3656
3657
        if not seconds_active is None:
3658
            cmd.add_element('active', str(seconds_active))
3659
3660
        if hosts:
3661
            cmd.add_element('hosts', ', '.join(hosts))
3662
3663
        if port:
3664
            cmd.add_element('port', port)
3665
3666
        if result_id:
3667
            cmd.add_element('result', attrs={'id': result_id})
3668
3669
        if severity:
3670
            cmd.add_element('severity', severity)
3671
3672
        if new_severity:
3673
            cmd.add_element('new_severity', new_severity)
3674
3675
        if task_id:
3676
            cmd.add_element('task', attrs={'id': task_id})
3677
3678
        if threat:
3679
            cmd.add_element('threat', threat)
3680
3681
        if new_threat:
3682
            cmd.add_element('new_threat', new_threat)
3683
3684
        return self._send_xml_command(cmd)