@@ 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 |
@@ 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 |