Code Duplication    Length = 43-46 lines in 2 locations

gvm/protocols/gmpv7.py 2 locations

@@ 727-772 (lines=46) @@
724
        cmd.add_element('copy', override_id)
725
        return self._send_xml_command(cmd)
726
727
    def create_permission(self, name, subject_id, subject_type,
728
                          resource_id=None, resource_type=None,
729
                          comment=None):
730
        """Create a new permission
731
732
        Arguments:
733
            name (str): Name of the new permission
734
            subject_id (str): UUID of subject to whom the permission is granted
735
            subject_type (str): Type of the subject user, group or role
736
            comment (str, optional): Comment for the permission
737
            resource_id (str, optional): UUID of entity to which the permission
738
                applies
739
            resource_type (str, optional): Type of the resource. For Super
740
                permissions user, group or role
741
742
        Returns:
743
            The response. See :py:meth:`send_command` for details.
744
        """
745
        if not name:
746
            raise RequiredArgument('create_permission requires a name argument')
747
748
        if not subject_id:
749
            raise RequiredArgument(
750
                'create_permission requires a subject_id argument')
751
752
        if subject_type not in ('user', 'group', 'role'):
753
            raise InvalidArgument(
754
                'create_permission requires subject_type to be either user, '
755
                'group or role')
756
757
        cmd = XmlCommand('create_permission')
758
        cmd.add_element('name', name)
759
760
        _xmlsubject = cmd.add_element('subject', attrs={'id': subject_id})
761
        _xmlsubject.add_element('type', type)
762
763
        if comment:
764
            cmd.add_element('comment', comment)
765
766
        if resource_id and resource_type:
767
            _xmlresource = cmd.add_element('resource',
768
                                           attrs={'id': resource_id})
769
            _xmlresource.add_element('type', resource_type)
770
771
772
        return self._send_xml_command(cmd)
773
774
    def clone_permission(self, permission_id):
775
        """Clone an existing permission
@@ 3501-3543 (lines=43) @@
3498
3499
        return self._send_xml_command(cmd)
3500
3501
    def modify_permission(self, permission_id, comment=None, name=None,
3502
                          resource_id=None, resource_type=None,
3503
                          subject_id=None, subject_type=None):
3504
        """Modifies an existing permission.
3505
3506
        Arguments:
3507
            permission_id (str): UUID of permission to be modified.
3508
            comment (str, optional): The comment on the permission.
3509
            name (str, optional): Permission name, currently the name of
3510
                a command.
3511
            subject_id (str, optional): UUID of subject to whom the permission
3512
                is granted
3513
            subject_type (str, optional): Type of the subject user, group or
3514
                role
3515
            resource_id (str, optional): UUID of entity to which the permission
3516
                applies
3517
            resource_type (str, optional): Type of the resource. For Super
3518
                permissions user, group or role
3519
        """
3520
        if not permission_id:
3521
            raise RequiredArgument('modify_permission requires '
3522
                                   'a permission_id element')
3523
3524
        cmd = XmlCommand('modify_permission')
3525
        cmd.set_attribute('permission_id', permission_id)
3526
3527
        if comment:
3528
            cmd.add_element('comment', comment)
3529
3530
        if name:
3531
            cmd.add_element('name', name)
3532
3533
        if resource_id and resource_type:
3534
            _xmlresource = cmd.add_element('resource',
3535
                                           attrs={'id': resource_id})
3536
            _xmlresource.add_element('type', resource_type)
3537
3538
        if subject_id and subject_type:
3539
            _xmlsubject = cmd.add_element('subject',
3540
                                          attrs={'id': subject_id})
3541
            _xmlsubject.add_element('type', subject_type)
3542
3543
        return self._send_xml_command(cmd)
3544
3545
    def modify_port_list(self, port_list_id, comment=None, name=None, ):
3546
        """Modifies an existing port list.