Code Duplication    Length = 43-46 lines in 2 locations

gvm/protocols/gmpv7.py 2 locations

@@ 730-775 (lines=46) @@
727
        cmd.add_element('copy', override_id)
728
        return self._send_xml_command(cmd)
729
730
    def create_permission(self, name, subject_id, subject_type,
731
                          resource_id=None, resource_type=None,
732
                          comment=None):
733
        """Create a new permission
734
735
        Arguments:
736
            name (str): Name of the new permission
737
            subject_id (str): UUID of subject to whom the permission is granted
738
            subject_type (str): Type of the subject user, group or role
739
            comment (str, optional): Comment for the permission
740
            resource_id (str, optional): UUID of entity to which the permission
741
                applies
742
            resource_type (str, optional): Type of the resource. For Super
743
                permissions user, group or role
744
745
        Returns:
746
            The response. See :py:meth:`send_command` for details.
747
        """
748
        if not name:
749
            raise RequiredArgument('create_permission requires a name argument')
750
751
        if not subject_id:
752
            raise RequiredArgument(
753
                'create_permission requires a subject_id argument')
754
755
        if subject_type not in ('user', 'group', 'role'):
756
            raise InvalidArgument(
757
                'create_permission requires subject_type to be either user, '
758
                'group or role')
759
760
        cmd = XmlCommand('create_permission')
761
        cmd.add_element('name', name)
762
763
        _xmlsubject = cmd.add_element('subject', attrs={'id': subject_id})
764
        _xmlsubject.add_element('type', type)
765
766
        if comment:
767
            cmd.add_element('comment', comment)
768
769
        if resource_id and resource_type:
770
            _xmlresource = cmd.add_element('resource',
771
                                           attrs={'id': resource_id})
772
            _xmlresource.add_element('type', resource_type)
773
774
775
        return self._send_xml_command(cmd)
776
777
    def clone_permission(self, permission_id):
778
        """Clone an existing permission
@@ 2769-2811 (lines=43) @@
2766
2767
        return self._send_xml_command(cmd)
2768
2769
    def modify_permission(self, permission_id, comment=None, name=None,
2770
                          resource_id=None, resource_type=None,
2771
                          subject_id=None, subject_type=None):
2772
        """Modifies an existing permission.
2773
2774
        Arguments:
2775
            permission_id (str): UUID of permission to be modified.
2776
            comment (str, optional): The comment on the permission.
2777
            name (str, optional): Permission name, currently the name of
2778
                a command.
2779
            subject_id (str, optional): UUID of subject to whom the permission
2780
                is granted
2781
            subject_type (str, optional): Type of the subject user, group or
2782
                role
2783
            resource_id (str, optional): UUID of entity to which the permission
2784
                applies
2785
            resource_type (str, optional): Type of the resource. For Super
2786
                permissions user, group or role
2787
        """
2788
        if not permission_id:
2789
            raise RequiredArgument('modify_permission requires '
2790
                                   'a permission_id element')
2791
2792
        cmd = XmlCommand('modify_permission')
2793
        cmd.set_attribute('permission_id', permission_id)
2794
2795
        if comment:
2796
            cmd.add_element('comment', comment)
2797
2798
        if name:
2799
            cmd.add_element('name', name)
2800
2801
        if resource_id and resource_type:
2802
            _xmlresource = cmd.add_element('resource',
2803
                                           attrs={'id': resource_id})
2804
            _xmlresource.add_element('type', resource_type)
2805
2806
        if subject_id and subject_type:
2807
            _xmlsubject = cmd.add_element('subject',
2808
                                          attrs={'id': subject_id})
2809
            _xmlsubject.add_element('type', subject_type)
2810
2811
        return self._send_xml_command(cmd)
2812
2813
    def modify_port_list(self, port_list_id, comment=None, name=None, ):
2814
        """Modifies an existing port list.