Code Duplication    Length = 43-46 lines in 2 locations

gvm/protocols/gmpv7.py 2 locations

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