Code Duplication    Length = 58-69 lines in 2 locations

gvm/protocols/gmpv7.py 2 locations

@@ 637-705 (lines=69) @@
634
        cmd.add_element('copy', note_id)
635
        return self._send_xml_command(cmd)
636
637
    def create_override(self, text, nvt_oid, seconds_active=None, hosts=None,
638
                        port=None, result_id=None, severity=None, comment=None,
639
                        new_severity=None, task_id=None, threat=None,
640
                        new_threat=None):
641
        """Create a new override
642
643
        Arguments:
644
            text (str): Text of the new override
645
            nvt_id (str): OID of the nvt to which override applies
646
            seconds_active (int, optional): Seconds override will be active.
647
                -1 on always, 0 off
648
            comment (str, optional): Comment for the override
649
            hosts (list, optional): A list of host addresses
650
            port (str, optional): Port ot which the override applies
651
            result_id (str, optional): UUID of a result to which override
652
                applies
653
            severity (decimal, optional): Severity to which override applies
654
            new_severity (decimal, optional): New severity for result
655
            task_id (str, optional): UUID of task to which override applies
656
            threat (str, optional): Threat level to which override applies. Will
657
                be converted to severity
658
            new_threat (str, optional): New threat level for result, will be
659
                converted to a new_severity
660
661
        Returns:
662
            The response. See :py:meth:`send_command` for details.
663
        """
664
        if not text:
665
            raise RequiredArgument('create_override requires a text argument')
666
667
        if not nvt_oid:
668
            raise RequiredArgument('create_override requires a nvt_oid '
669
                                   'argument')
670
671
        cmd = XmlCommand('create_override')
672
        cmd.add_element('text', text)
673
        cmd.add_element('nvt', attrs={'oid': nvt_oid})
674
675
        if not seconds_active is None:
676
            cmd.add_element('active', str(seconds_active))
677
678
        if comment:
679
            cmd.add_element('comment', comment)
680
681
        if hosts:
682
            cmd.add_element('hosts', ', '.join(hosts))
683
684
        if port:
685
            cmd.add_element('port', port)
686
687
        if result_id:
688
            cmd.add_element('result', attrs={'id': result_id})
689
690
        if severity:
691
            cmd.add_element('severity', severity)
692
693
        if new_severity:
694
            cmd.add_element('new_severity', new_severity)
695
696
        if task_id:
697
            cmd.add_element('task', attrs={'id': task_id})
698
699
        if threat:
700
            cmd.add_element('threat', threat)
701
702
        if new_threat:
703
            cmd.add_element('new_threat', new_threat)
704
705
        return self._send_xml_command(cmd)
706
707
    def clone_override(self, override_id):
708
        """Clone an existing override
@@ 2700-2757 (lines=58) @@
2697
2698
        return self._send_xml_command(cmd)
2699
2700
    def modify_override(self, override_id, text, seconds_active=None,
2701
                        hosts=None, port=None, result_id=None, severity=None,
2702
                        new_severity=None, task_id=None, threat=None,
2703
                        new_threat=None):
2704
        """Modifies an existing override.
2705
2706
        Arguments:
2707
            override_id (str): UUID of override to modify.
2708
            text (str): The text of the override.
2709
            seconds_active (int, optional): Seconds override will be active.
2710
                -1 on always, 0 off.
2711
            hosts (list, optional): A list of host addresses
2712
            port (str, optional): Port to which override applies.
2713
            result_id (str, optional): Result to which override applies.
2714
            severity (str, optional): Severity to which override applies.
2715
            new_severity (str, optional): New severity score for result.
2716
            task_id (str, optional): Task to which override applies.
2717
            threat (str, optional): Threat level to which override applies.
2718
            new_threat (str, optional): New threat level for results.
2719
        """
2720
        if not override_id:
2721
            raise RequiredArgument('modify_override requires a override_id '
2722
                                   'argument')
2723
        if not text:
2724
            raise RequiredArgument('modify_override requires a text argument')
2725
2726
        cmd = XmlCommand('modify_override')
2727
        cmd.set_attribute('override_id', override_id)
2728
        cmd.add_element('text', text)
2729
2730
        if not seconds_active is None:
2731
            cmd.add_element('active', str(seconds_active))
2732
2733
        if hosts:
2734
            cmd.add_element('hosts', ', '.join(hosts))
2735
2736
        if port:
2737
            cmd.add_element('port', port)
2738
2739
        if result_id:
2740
            cmd.add_element('result', attrs={'id': result_id})
2741
2742
        if severity:
2743
            cmd.add_element('severity', severity)
2744
2745
        if new_severity:
2746
            cmd.add_element('new_severity', new_severity)
2747
2748
        if task_id:
2749
            cmd.add_element('task', attrs={'id': task_id})
2750
2751
        if threat:
2752
            cmd.add_element('threat', threat)
2753
2754
        if new_threat:
2755
            cmd.add_element('new_threat', new_threat)
2756
2757
        return self._send_xml_command(cmd)
2758
2759
    def modify_permission(self, permission_id, comment=None, name=None,
2760
                          resource_id=None, resource_type=None,