@@ 808-853 (lines=46) @@ | ||
805 | cmd.add_element('copy', override_id) |
|
806 | return self._send_xml_command(cmd) |
|
807 | ||
808 | def create_permission(self, name, subject_id, subject_type, *, |
|
809 | resource_id=None, resource_type=None, |
|
810 | comment=None): |
|
811 | """Create a new permission |
|
812 | ||
813 | Arguments: |
|
814 | name (str): Name of the new permission |
|
815 | subject_id (str): UUID of subject to whom the permission is granted |
|
816 | subject_type (str): Type of the subject user, group or role |
|
817 | comment (str, optional): Comment for the permission |
|
818 | resource_id (str, optional): UUID of entity to which the permission |
|
819 | applies |
|
820 | resource_type (str, optional): Type of the resource. For Super |
|
821 | permissions user, group or role |
|
822 | ||
823 | Returns: |
|
824 | The response. See :py:meth:`send_command` for details. |
|
825 | """ |
|
826 | if not name: |
|
827 | raise RequiredArgument('create_permission requires a name argument') |
|
828 | ||
829 | if not subject_id: |
|
830 | raise RequiredArgument( |
|
831 | 'create_permission requires a subject_id argument') |
|
832 | ||
833 | if subject_type not in ('user', 'group', 'role'): |
|
834 | raise InvalidArgument( |
|
835 | 'create_permission requires subject_type to be either user, ' |
|
836 | 'group or role') |
|
837 | ||
838 | cmd = XmlCommand('create_permission') |
|
839 | cmd.add_element('name', name) |
|
840 | ||
841 | _xmlsubject = cmd.add_element('subject', attrs={'id': subject_id}) |
|
842 | _xmlsubject.add_element('type', type) |
|
843 | ||
844 | if comment: |
|
845 | cmd.add_element('comment', comment) |
|
846 | ||
847 | if resource_id and resource_type: |
|
848 | _xmlresource = cmd.add_element('resource', |
|
849 | attrs={'id': resource_id}) |
|
850 | _xmlresource.add_element('type', resource_type) |
|
851 | ||
852 | ||
853 | return self._send_xml_command(cmd) |
|
854 | ||
855 | def clone_permission(self, permission_id): |
|
856 | """Clone an existing permission |
|
@@ 3720-3762 (lines=43) @@ | ||
3717 | ||
3718 | return self._send_xml_command(cmd) |
|
3719 | ||
3720 | def modify_permission(self, permission_id, *, comment=None, name=None, |
|
3721 | resource_id=None, resource_type=None, |
|
3722 | subject_id=None, subject_type=None): |
|
3723 | """Modifies an existing permission. |
|
3724 | ||
3725 | Arguments: |
|
3726 | permission_id (str): UUID of permission to be modified. |
|
3727 | comment (str, optional): The comment on the permission. |
|
3728 | name (str, optional): Permission name, currently the name of |
|
3729 | a command. |
|
3730 | subject_id (str, optional): UUID of subject to whom the permission |
|
3731 | is granted |
|
3732 | subject_type (str, optional): Type of the subject user, group or |
|
3733 | role |
|
3734 | resource_id (str, optional): UUID of entity to which the permission |
|
3735 | applies |
|
3736 | resource_type (str, optional): Type of the resource. For Super |
|
3737 | permissions user, group or role |
|
3738 | ||
3739 | Returns: |
|
3740 | The response. See :py:meth:`send_command` for details. |
|
3741 | """ |
|
3742 | if not permission_id: |
|
3743 | raise RequiredArgument('modify_permission requires ' |
|
3744 | 'a permission_id element') |
|
3745 | ||
3746 | cmd = XmlCommand('modify_permission') |
|
3747 | cmd.set_attribute('permission_id', permission_id) |
|
3748 | ||
3749 | if comment: |
|
3750 | cmd.add_element('comment', comment) |
|
3751 | ||
3752 | if name: |
|
3753 | cmd.add_element('name', name) |
|
3754 | ||
3755 | if resource_id and resource_type: |
|
3756 | _xmlresource = cmd.add_element('resource', |
|
3757 | attrs={'id': resource_id}) |
|
3758 | _xmlresource.add_element('type', resource_type) |
|
3759 | ||
3760 | if subject_id and subject_type: |
|
3761 | _xmlsubject = cmd.add_element('subject', |
|
3762 | attrs={'id': subject_id}) |
|
3763 | _xmlsubject.add_element('type', subject_type) |
|
3764 | ||
3765 | return self._send_xml_command(cmd) |