@@ 6079-6174 (lines=96) @@ | ||
6076 | ||
6077 | return self._send_xml_command(cmd) |
|
6078 | ||
6079 | def modify_user( |
|
6080 | self, |
|
6081 | user_id: str = None, |
|
6082 | name: str = None, |
|
6083 | *, |
|
6084 | new_name: Optional[str] = None, |
|
6085 | comment: Optional[str] = None, |
|
6086 | password: Optional[str] = None, |
|
6087 | auth_source: Optional[UserAuthType] = None, |
|
6088 | role_ids: Optional[List[str]] = None, |
|
6089 | hosts: Optional[List[str]] = None, |
|
6090 | hosts_allow: Optional[bool] = False, |
|
6091 | ifaces: Optional[List[str]] = None, |
|
6092 | ifaces_allow: Optional[bool] = False, |
|
6093 | group_ids: Optional[List[str]] = None, |
|
6094 | ) -> Any: |
|
6095 | """Modifies an existing user. Most of the fields need to be supplied |
|
6096 | for changing a single field even if no change is wanted for those. |
|
6097 | Else empty values are inserted for the missing fields instead. |
|
6098 | ||
6099 | Arguments: |
|
6100 | user_id: UUID of the user to be modified. Overrides name element |
|
6101 | argument. |
|
6102 | name: The name of the user to be modified. Either user_id or name |
|
6103 | must be passed. |
|
6104 | new_name: The new name for the user. |
|
6105 | comment: Comment on the user. |
|
6106 | password: The password for the user. |
|
6107 | auth_source: Source allowed for authentication for this user. |
|
6108 | roles_id: List of roles UUIDs for the user. |
|
6109 | hosts: User access rules: List of hosts. |
|
6110 | hosts_allow: Defines how the hosts list is to be interpreted. |
|
6111 | If False (default) the list is treated as a deny list. |
|
6112 | All hosts are allowed by default except those provided by |
|
6113 | the hosts parameter. If True the list is treated as a |
|
6114 | allow list. All hosts are denied by default except those |
|
6115 | provided by the hosts parameter. |
|
6116 | ifaces: User access rules: List of ifaces. |
|
6117 | ifaces_allow: Defines how the ifaces list is to be interpreted. |
|
6118 | If False (default) the list is treated as a deny list. |
|
6119 | All ifaces are allowed by default except those provided by |
|
6120 | the ifaces parameter. If True the list is treated as a |
|
6121 | allow list. All ifaces are denied by default except those |
|
6122 | provided by the ifaces parameter. |
|
6123 | group_ids: List of group UUIDs for the user. |
|
6124 | ||
6125 | Returns: |
|
6126 | The response. See :py:meth:`send_command` for details. |
|
6127 | """ |
|
6128 | if not user_id and not name: |
|
6129 | raise RequiredArgument( |
|
6130 | function=self.modify_user.__name__, argument='user_id or name' |
|
6131 | ) |
|
6132 | ||
6133 | cmd = XmlCommand("modify_user") |
|
6134 | ||
6135 | if user_id: |
|
6136 | cmd.set_attribute("user_id", user_id) |
|
6137 | else: |
|
6138 | cmd.add_element("name", name) |
|
6139 | ||
6140 | if new_name: |
|
6141 | cmd.add_element("new_name", new_name) |
|
6142 | ||
6143 | if role_ids: |
|
6144 | for role in role_ids: |
|
6145 | cmd.add_element("role", attrs={"id": role}) |
|
6146 | ||
6147 | if hosts: |
|
6148 | cmd.add_element( |
|
6149 | "hosts", |
|
6150 | _to_comma_list(hosts), |
|
6151 | attrs={"allow": _to_bool(hosts_allow)}, |
|
6152 | ) |
|
6153 | ||
6154 | if ifaces: |
|
6155 | cmd.add_element( |
|
6156 | "ifaces", |
|
6157 | _to_comma_list(ifaces), |
|
6158 | attrs={"allow": _to_bool(ifaces_allow)}, |
|
6159 | ) |
|
6160 | ||
6161 | if comment: |
|
6162 | cmd.add_element("comment", comment) |
|
6163 | ||
6164 | if password: |
|
6165 | cmd.add_element("password", password) |
|
6166 | ||
6167 | if auth_source: |
|
6168 | _xmlauthsrc = cmd.add_element("sources") |
|
6169 | _xmlauthsrc.add_element("source", auth_source.value) |
|
6170 | ||
6171 | if group_ids: |
|
6172 | _xmlgroups = cmd.add_element("groups") |
|
6173 | for group_id in group_ids: |
|
6174 | _xmlgroups.add_element("group", attrs={"id": group_id}) |
|
6175 | ||
6176 | return self._send_xml_command(cmd) |
|
6177 |
@@ 630-722 (lines=93) @@ | ||
627 | ||
628 | return self._send_xml_command(cmd) |
|
629 | ||
630 | def modify_user( |
|
631 | self, |
|
632 | user_id: str = None, |
|
633 | *, |
|
634 | name: Optional[str] = None, |
|
635 | comment: Optional[str] = None, |
|
636 | password: Optional[str] = None, |
|
637 | auth_source: Optional[UserAuthType] = None, |
|
638 | role_ids: Optional[List[str]] = None, |
|
639 | hosts: Optional[List[str]] = None, |
|
640 | hosts_allow: Optional[bool] = False, |
|
641 | ifaces: Optional[List[str]] = None, |
|
642 | ifaces_allow: Optional[bool] = False, |
|
643 | group_ids: Optional[List[str]] = None, |
|
644 | ) -> Any: |
|
645 | ||
646 | """Modifies an existing user. Most of the fields need to be supplied |
|
647 | for changing a single field even if no change is wanted for those. |
|
648 | Else empty values are inserted for the missing fields instead. |
|
649 | ||
650 | Arguments: |
|
651 | user_id: UUID of the user to be modified. |
|
652 | name: The new name for the user. |
|
653 | comment: Comment on the user. |
|
654 | password: The password for the user. |
|
655 | auth_source: Source allowed for authentication for this user. |
|
656 | roles_id: List of roles UUIDs for the user. |
|
657 | hosts: User access rules: List of hosts. |
|
658 | hosts_allow: Defines how the hosts list is to be interpreted. |
|
659 | If False (default) the list is treated as a deny list. |
|
660 | All hosts are allowed by default except those provided by |
|
661 | the hosts parameter. If True the list is treated as a |
|
662 | allow list. All hosts are denied by default except those |
|
663 | provided by the hosts parameter. |
|
664 | ifaces: User access rules: List of ifaces. |
|
665 | ifaces_allow: Defines how the ifaces list is to be interpreted. |
|
666 | If False (default) the list is treated as a deny list. |
|
667 | All ifaces are allowed by default except those provided by |
|
668 | the ifaces parameter. If True the list is treated as a |
|
669 | allow list. All ifaces are denied by default except those |
|
670 | provided by the ifaces parameter. |
|
671 | group_ids: List of group UUIDs for the user. |
|
672 | ||
673 | Returns: |
|
674 | The response. See :py:meth:`send_command` for details. |
|
675 | """ |
|
676 | if not user_id: |
|
677 | raise RequiredArgument( |
|
678 | function=self.modify_user.__name__, argument='user_id' |
|
679 | ) |
|
680 | ||
681 | cmd = XmlCommand("modify_user") |
|
682 | ||
683 | if user_id: |
|
684 | cmd.set_attribute("user_id", user_id) |
|
685 | ||
686 | if name: |
|
687 | cmd.add_element("new_name", name) |
|
688 | ||
689 | if role_ids: |
|
690 | for role in role_ids: |
|
691 | cmd.add_element("role", attrs={"id": role}) |
|
692 | ||
693 | if hosts: |
|
694 | cmd.add_element( |
|
695 | "hosts", |
|
696 | _to_comma_list(hosts), |
|
697 | attrs={"allow": _to_bool(hosts_allow)}, |
|
698 | ) |
|
699 | ||
700 | if ifaces: |
|
701 | cmd.add_element( |
|
702 | "ifaces", |
|
703 | _to_comma_list(ifaces), |
|
704 | attrs={"allow": _to_bool(ifaces_allow)}, |
|
705 | ) |
|
706 | ||
707 | if comment: |
|
708 | cmd.add_element("comment", comment) |
|
709 | ||
710 | if password: |
|
711 | cmd.add_element("password", password) |
|
712 | ||
713 | if auth_source: |
|
714 | _xmlauthsrc = cmd.add_element("sources") |
|
715 | _xmlauthsrc.add_element("source", auth_source.value) |
|
716 | ||
717 | if group_ids: |
|
718 | _xmlgroups = cmd.add_element("groups") |
|
719 | for group_id in group_ids: |
|
720 | _xmlgroups.add_element("group", attrs={"id": group_id}) |
|
721 | ||
722 | return self._send_xml_command(cmd) |
|
723 |