@@ 391-483 (lines=93) @@ | ||
388 | ||
389 | return self._send_xml_command(cmd) |
|
390 | ||
391 | def modify_user( |
|
392 | self, |
|
393 | user_id: str = None, |
|
394 | *, |
|
395 | name: Optional[str] = None, |
|
396 | comment: Optional[str] = None, |
|
397 | password: Optional[str] = None, |
|
398 | auth_source: Optional[UserAuthType] = None, |
|
399 | role_ids: Optional[List[str]] = None, |
|
400 | hosts: Optional[List[str]] = None, |
|
401 | hosts_allow: Optional[bool] = False, |
|
402 | ifaces: Optional[List[str]] = None, |
|
403 | ifaces_allow: Optional[bool] = False, |
|
404 | group_ids: Optional[List[str]] = None, |
|
405 | ) -> Any: |
|
406 | ||
407 | """Modifies an existing user. Most of the fields need to be supplied |
|
408 | for changing a single field even if no change is wanted for those. |
|
409 | Else empty values are inserted for the missing fields instead. |
|
410 | ||
411 | Arguments: |
|
412 | user_id: UUID of the user to be modified. |
|
413 | name: The new name for the user. |
|
414 | comment: Comment on the user. |
|
415 | password: The password for the user. |
|
416 | auth_source: Source allowed for authentication for this user. |
|
417 | roles_id: List of roles UUIDs for the user. |
|
418 | hosts: User access rules: List of hosts. |
|
419 | hosts_allow: Defines how the hosts list is to be interpreted. |
|
420 | If False (default) the list is treated as a deny list. |
|
421 | All hosts are allowed by default except those provided by |
|
422 | the hosts parameter. If True the list is treated as a |
|
423 | allow list. All hosts are denied by default except those |
|
424 | provided by the hosts parameter. |
|
425 | ifaces: User access rules: List of ifaces. |
|
426 | ifaces_allow: Defines how the ifaces list is to be interpreted. |
|
427 | If False (default) the list is treated as a deny list. |
|
428 | All ifaces are allowed by default except those provided by |
|
429 | the ifaces parameter. If True the list is treated as a |
|
430 | allow list. All ifaces are denied by default except those |
|
431 | provided by the ifaces parameter. |
|
432 | group_ids: List of group UUIDs for the user. |
|
433 | ||
434 | Returns: |
|
435 | The response. See :py:meth:`send_command` for details. |
|
436 | """ |
|
437 | if not user_id: |
|
438 | raise RequiredArgument( |
|
439 | function=self.modify_user.__name__, argument='user_id' |
|
440 | ) |
|
441 | ||
442 | cmd = XmlCommand("modify_user") |
|
443 | ||
444 | if user_id: |
|
445 | cmd.set_attribute("user_id", user_id) |
|
446 | ||
447 | if name: |
|
448 | cmd.add_element("new_name", name) |
|
449 | ||
450 | if role_ids: |
|
451 | for role in role_ids: |
|
452 | cmd.add_element("role", attrs={"id": role}) |
|
453 | ||
454 | if hosts: |
|
455 | cmd.add_element( |
|
456 | "hosts", |
|
457 | to_comma_list(hosts), |
|
458 | attrs={"allow": to_bool(hosts_allow)}, |
|
459 | ) |
|
460 | ||
461 | if ifaces: |
|
462 | cmd.add_element( |
|
463 | "ifaces", |
|
464 | to_comma_list(ifaces), |
|
465 | attrs={"allow": to_bool(ifaces_allow)}, |
|
466 | ) |
|
467 | ||
468 | if comment: |
|
469 | cmd.add_element("comment", comment) |
|
470 | ||
471 | if password: |
|
472 | cmd.add_element("password", password) |
|
473 | ||
474 | if auth_source: |
|
475 | _xmlauthsrc = cmd.add_element("sources") |
|
476 | _xmlauthsrc.add_element("source", auth_source.value) |
|
477 | ||
478 | if group_ids: |
|
479 | _xmlgroups = cmd.add_element("groups") |
|
480 | for group_id in group_ids: |
|
481 | _xmlgroups.add_element("group", attrs={"id": group_id}) |
|
482 | ||
483 | return self._send_xml_command(cmd) |
|
484 |
@@ 5838-5935 (lines=98) @@ | ||
5835 | ||
5836 | return self._send_xml_command(cmd) |
|
5837 | ||
5838 | def modify_user( |
|
5839 | self, |
|
5840 | user_id: str = None, |
|
5841 | name: str = None, |
|
5842 | *, |
|
5843 | new_name: Optional[str] = None, |
|
5844 | comment: Optional[str] = None, |
|
5845 | password: Optional[str] = None, |
|
5846 | auth_source: Optional[UserAuthType] = None, |
|
5847 | role_ids: Optional[List[str]] = None, |
|
5848 | hosts: Optional[List[str]] = None, |
|
5849 | hosts_allow: Optional[bool] = False, |
|
5850 | ifaces: Optional[List[str]] = None, |
|
5851 | ifaces_allow: Optional[bool] = False, |
|
5852 | group_ids: Optional[List[str]] = None, |
|
5853 | ) -> Any: |
|
5854 | """Modifies an existing user. Most of the fields need to be supplied |
|
5855 | for changing a single field even if no change is wanted for those. |
|
5856 | Else empty values are inserted for the missing fields instead. |
|
5857 | Arguments: |
|
5858 | user_id: UUID of the user to be modified. Overrides name element |
|
5859 | argument. |
|
5860 | name: The name of the user to be modified. Either user_id or name |
|
5861 | must be passed. |
|
5862 | new_name: The new name for the user. |
|
5863 | comment: Comment on the user. |
|
5864 | password: The password for the user. |
|
5865 | auth_source: Source allowed for authentication for this user. |
|
5866 | roles_id: List of roles UUIDs for the user. |
|
5867 | hosts: User access rules: List of hosts. |
|
5868 | hosts_allow: Defines how the hosts list is to be interpreted. |
|
5869 | If False (default) the list is treated as a deny list. |
|
5870 | All hosts are allowed by default except those provided by |
|
5871 | the hosts parameter. If True the list is treated as a |
|
5872 | allow list. All hosts are denied by default except those |
|
5873 | provided by the hosts parameter. |
|
5874 | ifaces: User access rules: List of ifaces. |
|
5875 | ifaces_allow: Defines how the ifaces list is to be interpreted. |
|
5876 | If False (default) the list is treated as a deny list. |
|
5877 | All ifaces are allowed by default except those provided by |
|
5878 | the ifaces parameter. If True the list is treated as a |
|
5879 | allow list. All ifaces are denied by default except those |
|
5880 | provided by the ifaces parameter. |
|
5881 | group_ids: List of group UUIDs for the user. |
|
5882 | ||
5883 | Returns: |
|
5884 | The response. See :py:meth:`send_command` for details. |
|
5885 | """ |
|
5886 | if not user_id and not name: |
|
5887 | raise RequiredArgument( |
|
5888 | function=self.modify_user.__name__, argument='user_id or name' |
|
5889 | ) |
|
5890 | ||
5891 | cmd = XmlCommand("modify_user") |
|
5892 | ||
5893 | if user_id: |
|
5894 | cmd.set_attribute("user_id", user_id) |
|
5895 | else: |
|
5896 | cmd.add_element("name", name) |
|
5897 | ||
5898 | if new_name: |
|
5899 | cmd.add_element("new_name", new_name) |
|
5900 | ||
5901 | if role_ids: |
|
5902 | for role in role_ids: |
|
5903 | cmd.add_element("role", attrs={"id": role}) |
|
5904 | ||
5905 | if hosts: |
|
5906 | cmd.add_element( |
|
5907 | "hosts", |
|
5908 | to_comma_list(hosts), |
|
5909 | attrs={"allow": to_bool(hosts_allow)}, |
|
5910 | ) |
|
5911 | ||
5912 | if ifaces: |
|
5913 | cmd.add_element( |
|
5914 | "ifaces", |
|
5915 | to_comma_list(ifaces), |
|
5916 | attrs={"allow": to_bool(ifaces_allow)}, |
|
5917 | ) |
|
5918 | ||
5919 | if comment: |
|
5920 | cmd.add_element("comment", comment) |
|
5921 | ||
5922 | if password: |
|
5923 | cmd.add_element("password", password) |
|
5924 | ||
5925 | if auth_source: |
|
5926 | _xmlauthsrc = cmd.add_element("sources") |
|
5927 | _xmlauthsrc.add_element("source", auth_source.value) |
|
5928 | ||
5929 | if group_ids: |
|
5930 | _xmlgroups = cmd.add_element("groups") |
|
5931 | for group_id in group_ids: |
|
5932 | _xmlgroups.add_element("group", attrs={"id": group_id}) |
|
5933 | ||
5934 | return self._send_xml_command(cmd) |
|
5935 | ||
5936 | def restore(self, entity_id: str) -> Any: |
|
5937 | """Restore an entity from the trashcan |
|
5938 |