| @@ 6067-6162 (lines=96) @@ | ||
| 6064 | ||
| 6065 | return self._send_xml_command(cmd) |
|
| 6066 | ||
| 6067 | def modify_user( |
|
| 6068 | self, |
|
| 6069 | user_id: str = None, |
|
| 6070 | name: str = None, |
|
| 6071 | *, |
|
| 6072 | new_name: Optional[str] = None, |
|
| 6073 | comment: Optional[str] = None, |
|
| 6074 | password: Optional[str] = None, |
|
| 6075 | auth_source: Optional[UserAuthType] = None, |
|
| 6076 | role_ids: Optional[List[str]] = None, |
|
| 6077 | hosts: Optional[List[str]] = None, |
|
| 6078 | hosts_allow: Optional[bool] = False, |
|
| 6079 | ifaces: Optional[List[str]] = None, |
|
| 6080 | ifaces_allow: Optional[bool] = False, |
|
| 6081 | group_ids: Optional[List[str]] = None |
|
| 6082 | ) -> Any: |
|
| 6083 | """Modifies an existing user. Most of the fields need to be supplied |
|
| 6084 | for changing a single field even if no change is wanted for those. |
|
| 6085 | Else empty values are inserted for the missing fields instead. |
|
| 6086 | ||
| 6087 | Arguments: |
|
| 6088 | user_id: UUID of the user to be modified. Overrides name element |
|
| 6089 | argument. |
|
| 6090 | name: The name of the user to be modified. Either user_id or name |
|
| 6091 | must be passed. |
|
| 6092 | new_name: The new name for the user. |
|
| 6093 | comment: Comment on the user. |
|
| 6094 | password: The password for the user. |
|
| 6095 | auth_source: Source allowed for authentication for this user. |
|
| 6096 | roles_id: List of roles UUIDs for the user. |
|
| 6097 | hosts: User access rules: List of hosts. |
|
| 6098 | hosts_allow: Defines how the hosts list is to be interpreted. |
|
| 6099 | If False (default) the list is treated as a deny list. |
|
| 6100 | All hosts are allowed by default except those provided by |
|
| 6101 | the hosts parameter. If True the list is treated as a |
|
| 6102 | allow list. All hosts are denied by default except those |
|
| 6103 | provided by the hosts parameter. |
|
| 6104 | ifaces: User access rules: List of ifaces. |
|
| 6105 | ifaces_allow: Defines how the ifaces list is to be interpreted. |
|
| 6106 | If False (default) the list is treated as a deny list. |
|
| 6107 | All ifaces are allowed by default except those provided by |
|
| 6108 | the ifaces parameter. If True the list is treated as a |
|
| 6109 | allow list. All ifaces are denied by default except those |
|
| 6110 | provided by the ifaces parameter. |
|
| 6111 | group_ids: List of group UUIDs for the user. |
|
| 6112 | ||
| 6113 | Returns: |
|
| 6114 | The response. See :py:meth:`send_command` for details. |
|
| 6115 | """ |
|
| 6116 | if not user_id and not name: |
|
| 6117 | raise RequiredArgument( |
|
| 6118 | function=self.modify_user.__name__, argument='user_id or name' |
|
| 6119 | ) |
|
| 6120 | ||
| 6121 | cmd = XmlCommand("modify_user") |
|
| 6122 | ||
| 6123 | if user_id: |
|
| 6124 | cmd.set_attribute("user_id", user_id) |
|
| 6125 | else: |
|
| 6126 | cmd.add_element("name", name) |
|
| 6127 | ||
| 6128 | if new_name: |
|
| 6129 | cmd.add_element("new_name", new_name) |
|
| 6130 | ||
| 6131 | if role_ids: |
|
| 6132 | for role in role_ids: |
|
| 6133 | cmd.add_element("role", attrs={"id": role}) |
|
| 6134 | ||
| 6135 | if hosts: |
|
| 6136 | cmd.add_element( |
|
| 6137 | "hosts", |
|
| 6138 | _to_comma_list(hosts), |
|
| 6139 | attrs={"allow": _to_bool(hosts_allow)}, |
|
| 6140 | ) |
|
| 6141 | ||
| 6142 | if ifaces: |
|
| 6143 | cmd.add_element( |
|
| 6144 | "ifaces", |
|
| 6145 | _to_comma_list(ifaces), |
|
| 6146 | attrs={"allow": _to_bool(ifaces_allow)}, |
|
| 6147 | ) |
|
| 6148 | ||
| 6149 | if comment: |
|
| 6150 | cmd.add_element("comment", comment) |
|
| 6151 | ||
| 6152 | if password: |
|
| 6153 | cmd.add_element("password", password) |
|
| 6154 | ||
| 6155 | if auth_source: |
|
| 6156 | _xmlauthsrc = cmd.add_element("sources") |
|
| 6157 | _xmlauthsrc.add_element("source", auth_source.value) |
|
| 6158 | ||
| 6159 | if group_ids: |
|
| 6160 | _xmlgroups = cmd.add_element("groups") |
|
| 6161 | for group_id in group_ids: |
|
| 6162 | _xmlgroups.add_element("group", attrs={"id": group_id}) |
|
| 6163 | ||
| 6164 | return self._send_xml_command(cmd) |
|
| 6165 | ||
| @@ 392-484 (lines=93) @@ | ||
| 389 | ||
| 390 | return self._send_xml_command(cmd) |
|
| 391 | ||
| 392 | def modify_user( |
|
| 393 | self, |
|
| 394 | user_id: str = None, |
|
| 395 | *, |
|
| 396 | name: Optional[str] = None, |
|
| 397 | comment: Optional[str] = None, |
|
| 398 | password: Optional[str] = None, |
|
| 399 | auth_source: Optional[UserAuthType] = None, |
|
| 400 | role_ids: Optional[List[str]] = None, |
|
| 401 | hosts: Optional[List[str]] = None, |
|
| 402 | hosts_allow: Optional[bool] = False, |
|
| 403 | ifaces: Optional[List[str]] = None, |
|
| 404 | ifaces_allow: Optional[bool] = False, |
|
| 405 | group_ids: Optional[List[str]] = None |
|
| 406 | ) -> Any: |
|
| 407 | ||
| 408 | """Modifies an existing user. Most of the fields need to be supplied |
|
| 409 | for changing a single field even if no change is wanted for those. |
|
| 410 | Else empty values are inserted for the missing fields instead. |
|
| 411 | ||
| 412 | Arguments: |
|
| 413 | user_id: UUID of the user to be modified. |
|
| 414 | name: The new name for the user. |
|
| 415 | comment: Comment on the user. |
|
| 416 | password: The password for the user. |
|
| 417 | auth_source: Source allowed for authentication for this user. |
|
| 418 | roles_id: List of roles UUIDs for the user. |
|
| 419 | hosts: User access rules: List of hosts. |
|
| 420 | hosts_allow: Defines how the hosts list is to be interpreted. |
|
| 421 | If False (default) the list is treated as a deny list. |
|
| 422 | All hosts are allowed by default except those provided by |
|
| 423 | the hosts parameter. If True the list is treated as a |
|
| 424 | allow list. All hosts are denied by default except those |
|
| 425 | provided by the hosts parameter. |
|
| 426 | ifaces: User access rules: List of ifaces. |
|
| 427 | ifaces_allow: Defines how the ifaces list is to be interpreted. |
|
| 428 | If False (default) the list is treated as a deny list. |
|
| 429 | All ifaces are allowed by default except those provided by |
|
| 430 | the ifaces parameter. If True the list is treated as a |
|
| 431 | allow list. All ifaces are denied by default except those |
|
| 432 | provided by the ifaces parameter. |
|
| 433 | group_ids: List of group UUIDs for the user. |
|
| 434 | ||
| 435 | Returns: |
|
| 436 | The response. See :py:meth:`send_command` for details. |
|
| 437 | """ |
|
| 438 | if not user_id: |
|
| 439 | raise RequiredArgument( |
|
| 440 | function=self.modify_user.__name__, argument='user_id' |
|
| 441 | ) |
|
| 442 | ||
| 443 | cmd = XmlCommand("modify_user") |
|
| 444 | ||
| 445 | if user_id: |
|
| 446 | cmd.set_attribute("user_id", user_id) |
|
| 447 | ||
| 448 | if name: |
|
| 449 | cmd.add_element("new_name", name) |
|
| 450 | ||
| 451 | if role_ids: |
|
| 452 | for role in role_ids: |
|
| 453 | cmd.add_element("role", attrs={"id": role}) |
|
| 454 | ||
| 455 | if hosts: |
|
| 456 | cmd.add_element( |
|
| 457 | "hosts", |
|
| 458 | _to_comma_list(hosts), |
|
| 459 | attrs={"allow": _to_bool(hosts_allow)}, |
|
| 460 | ) |
|
| 461 | ||
| 462 | if ifaces: |
|
| 463 | cmd.add_element( |
|
| 464 | "ifaces", |
|
| 465 | _to_comma_list(ifaces), |
|
| 466 | attrs={"allow": _to_bool(ifaces_allow)}, |
|
| 467 | ) |
|
| 468 | ||
| 469 | if comment: |
|
| 470 | cmd.add_element("comment", comment) |
|
| 471 | ||
| 472 | if password: |
|
| 473 | cmd.add_element("password", password) |
|
| 474 | ||
| 475 | if auth_source: |
|
| 476 | _xmlauthsrc = cmd.add_element("sources") |
|
| 477 | _xmlauthsrc.add_element("source", auth_source.value) |
|
| 478 | ||
| 479 | if group_ids: |
|
| 480 | _xmlgroups = cmd.add_element("groups") |
|
| 481 | for group_id in group_ids: |
|
| 482 | _xmlgroups.add_element("group", attrs={"id": group_id}) |
|
| 483 | ||
| 484 | return self._send_xml_command(cmd) |
|
| 485 | ||