| @@ 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 | ||
| @@ 5651-5748 (lines=98) @@ | ||
| 5648 | ||
| 5649 | return self._send_xml_command(cmd) |
|
| 5650 | ||
| 5651 | def modify_user( |
|
| 5652 | self, |
|
| 5653 | user_id: str = None, |
|
| 5654 | name: str = None, |
|
| 5655 | *, |
|
| 5656 | new_name: Optional[str] = None, |
|
| 5657 | comment: Optional[str] = None, |
|
| 5658 | password: Optional[str] = None, |
|
| 5659 | auth_source: Optional[UserAuthType] = None, |
|
| 5660 | role_ids: Optional[List[str]] = None, |
|
| 5661 | hosts: Optional[List[str]] = None, |
|
| 5662 | hosts_allow: Optional[bool] = False, |
|
| 5663 | ifaces: Optional[List[str]] = None, |
|
| 5664 | ifaces_allow: Optional[bool] = False, |
|
| 5665 | group_ids: Optional[List[str]] = None, |
|
| 5666 | ) -> Any: |
|
| 5667 | """Modifies an existing user. Most of the fields need to be supplied |
|
| 5668 | for changing a single field even if no change is wanted for those. |
|
| 5669 | Else empty values are inserted for the missing fields instead. |
|
| 5670 | Arguments: |
|
| 5671 | user_id: UUID of the user to be modified. Overrides name element |
|
| 5672 | argument. |
|
| 5673 | name: The name of the user to be modified. Either user_id or name |
|
| 5674 | must be passed. |
|
| 5675 | new_name: The new name for the user. |
|
| 5676 | comment: Comment on the user. |
|
| 5677 | password: The password for the user. |
|
| 5678 | auth_source: Source allowed for authentication for this user. |
|
| 5679 | roles_id: List of roles UUIDs for the user. |
|
| 5680 | hosts: User access rules: List of hosts. |
|
| 5681 | hosts_allow: Defines how the hosts list is to be interpreted. |
|
| 5682 | If False (default) the list is treated as a deny list. |
|
| 5683 | All hosts are allowed by default except those provided by |
|
| 5684 | the hosts parameter. If True the list is treated as a |
|
| 5685 | allow list. All hosts are denied by default except those |
|
| 5686 | provided by the hosts parameter. |
|
| 5687 | ifaces: User access rules: List of ifaces. |
|
| 5688 | ifaces_allow: Defines how the ifaces list is to be interpreted. |
|
| 5689 | If False (default) the list is treated as a deny list. |
|
| 5690 | All ifaces are allowed by default except those provided by |
|
| 5691 | the ifaces parameter. If True the list is treated as a |
|
| 5692 | allow list. All ifaces are denied by default except those |
|
| 5693 | provided by the ifaces parameter. |
|
| 5694 | group_ids: List of group UUIDs for the user. |
|
| 5695 | ||
| 5696 | Returns: |
|
| 5697 | The response. See :py:meth:`send_command` for details. |
|
| 5698 | """ |
|
| 5699 | if not user_id and not name: |
|
| 5700 | raise RequiredArgument( |
|
| 5701 | function=self.modify_user.__name__, argument='user_id or name' |
|
| 5702 | ) |
|
| 5703 | ||
| 5704 | cmd = XmlCommand("modify_user") |
|
| 5705 | ||
| 5706 | if user_id: |
|
| 5707 | cmd.set_attribute("user_id", user_id) |
|
| 5708 | else: |
|
| 5709 | cmd.add_element("name", name) |
|
| 5710 | ||
| 5711 | if new_name: |
|
| 5712 | cmd.add_element("new_name", new_name) |
|
| 5713 | ||
| 5714 | if role_ids: |
|
| 5715 | for role in role_ids: |
|
| 5716 | cmd.add_element("role", attrs={"id": role}) |
|
| 5717 | ||
| 5718 | if hosts: |
|
| 5719 | cmd.add_element( |
|
| 5720 | "hosts", |
|
| 5721 | to_comma_list(hosts), |
|
| 5722 | attrs={"allow": to_bool(hosts_allow)}, |
|
| 5723 | ) |
|
| 5724 | ||
| 5725 | if ifaces: |
|
| 5726 | cmd.add_element( |
|
| 5727 | "ifaces", |
|
| 5728 | to_comma_list(ifaces), |
|
| 5729 | attrs={"allow": to_bool(ifaces_allow)}, |
|
| 5730 | ) |
|
| 5731 | ||
| 5732 | if comment: |
|
| 5733 | cmd.add_element("comment", comment) |
|
| 5734 | ||
| 5735 | if password: |
|
| 5736 | cmd.add_element("password", password) |
|
| 5737 | ||
| 5738 | if auth_source: |
|
| 5739 | _xmlauthsrc = cmd.add_element("sources") |
|
| 5740 | _xmlauthsrc.add_element("source", auth_source.value) |
|
| 5741 | ||
| 5742 | if group_ids: |
|
| 5743 | _xmlgroups = cmd.add_element("groups") |
|
| 5744 | for group_id in group_ids: |
|
| 5745 | _xmlgroups.add_element("group", attrs={"id": group_id}) |
|
| 5746 | ||
| 5747 | return self._send_xml_command(cmd) |
|
| 5748 | ||
| 5749 | def restore(self, entity_id: str) -> Any: |
|
| 5750 | """Restore an entity from the trashcan |
|
| 5751 | ||