| @@ 6870-6967 (lines=98) @@ | ||
| 6867 | ||
| 6868 | return self._send_xml_command(cmd) |
|
| 6869 | ||
| 6870 | def modify_user( |
|
| 6871 | self, |
|
| 6872 | user_id: str = None, |
|
| 6873 | name: str = None, |
|
| 6874 | *, |
|
| 6875 | new_name: Optional[str] = None, |
|
| 6876 | comment: Optional[str] = None, |
|
| 6877 | password: Optional[str] = None, |
|
| 6878 | auth_source: Optional[UserAuthType] = None, |
|
| 6879 | role_ids: Optional[List[str]] = None, |
|
| 6880 | hosts: Optional[List[str]] = None, |
|
| 6881 | hosts_allow: Optional[bool] = False, |
|
| 6882 | ifaces: Optional[List[str]] = None, |
|
| 6883 | ifaces_allow: Optional[bool] = False, |
|
| 6884 | group_ids: Optional[List[str]] = None, |
|
| 6885 | ) -> Any: |
|
| 6886 | """Modifies an existing user. Most of the fields need to be supplied |
|
| 6887 | for changing a single field even if no change is wanted for those. |
|
| 6888 | Else empty values are inserted for the missing fields instead. |
|
| 6889 | ||
| 6890 | Arguments: |
|
| 6891 | user_id: UUID of the user to be modified. Overrides name element |
|
| 6892 | argument. |
|
| 6893 | name: The name of the user to be modified. Either user_id or name |
|
| 6894 | must be passed. |
|
| 6895 | new_name: The new name for the user. |
|
| 6896 | comment: Comment on the user. |
|
| 6897 | password: The password for the user. |
|
| 6898 | auth_source: Source allowed for authentication for this user. |
|
| 6899 | roles_id: List of roles UUIDs for the user. |
|
| 6900 | hosts: User access rules: List of hosts. |
|
| 6901 | hosts_allow: Defines how the hosts list is to be interpreted. |
|
| 6902 | If False (default) the list is treated as a deny list. |
|
| 6903 | All hosts are allowed by default except those provided by |
|
| 6904 | the hosts parameter. If True the list is treated as a |
|
| 6905 | allow list. All hosts are denied by default except those |
|
| 6906 | provided by the hosts parameter. |
|
| 6907 | ifaces: User access rules: List of ifaces. |
|
| 6908 | ifaces_allow: Defines how the ifaces list is to be interpreted. |
|
| 6909 | If False (default) the list is treated as a deny list. |
|
| 6910 | All ifaces are allowed by default except those provided by |
|
| 6911 | the ifaces parameter. If True the list is treated as a |
|
| 6912 | allow list. All ifaces are denied by default except those |
|
| 6913 | provided by the ifaces parameter. |
|
| 6914 | group_ids: List of group UUIDs for the user. |
|
| 6915 | ||
| 6916 | Returns: |
|
| 6917 | The response. See :py:meth:`send_command` for details. |
|
| 6918 | """ |
|
| 6919 | if not user_id and not name: |
|
| 6920 | raise RequiredArgument( |
|
| 6921 | function=self.modify_user.__name__, argument='user_id or name' |
|
| 6922 | ) |
|
| 6923 | ||
| 6924 | cmd = XmlCommand("modify_user") |
|
| 6925 | ||
| 6926 | if user_id: |
|
| 6927 | cmd.set_attribute("user_id", user_id) |
|
| 6928 | else: |
|
| 6929 | cmd.add_element("name", name) |
|
| 6930 | ||
| 6931 | if new_name: |
|
| 6932 | cmd.add_element("new_name", new_name) |
|
| 6933 | ||
| 6934 | if role_ids: |
|
| 6935 | for role in role_ids: |
|
| 6936 | cmd.add_element("role", attrs={"id": role}) |
|
| 6937 | ||
| 6938 | if hosts: |
|
| 6939 | cmd.add_element( |
|
| 6940 | "hosts", |
|
| 6941 | to_comma_list(hosts), |
|
| 6942 | attrs={"allow": to_bool(hosts_allow)}, |
|
| 6943 | ) |
|
| 6944 | ||
| 6945 | if ifaces: |
|
| 6946 | cmd.add_element( |
|
| 6947 | "ifaces", |
|
| 6948 | to_comma_list(ifaces), |
|
| 6949 | attrs={"allow": to_bool(ifaces_allow)}, |
|
| 6950 | ) |
|
| 6951 | ||
| 6952 | if comment: |
|
| 6953 | cmd.add_element("comment", comment) |
|
| 6954 | ||
| 6955 | if password: |
|
| 6956 | cmd.add_element("password", password) |
|
| 6957 | ||
| 6958 | if auth_source: |
|
| 6959 | _xmlauthsrc = cmd.add_element("sources") |
|
| 6960 | _xmlauthsrc.add_element("source", auth_source.value) |
|
| 6961 | ||
| 6962 | if group_ids: |
|
| 6963 | _xmlgroups = cmd.add_element("groups") |
|
| 6964 | for group_id in group_ids: |
|
| 6965 | _xmlgroups.add_element("group", attrs={"id": group_id}) |
|
| 6966 | ||
| 6967 | return self._send_xml_command(cmd) |
|
| 6968 | ||
| 6969 | def move_task(self, task_id: str, *, slave_id: Optional[str] = None) -> Any: |
|
| 6970 | """Move an existing task to another GMP slave scanner or the master |
|
| @@ 623-715 (lines=93) @@ | ||
| 620 | ||
| 621 | return self._send_xml_command(cmd) |
|
| 622 | ||
| 623 | def modify_user( |
|
| 624 | self, |
|
| 625 | user_id: str = None, |
|
| 626 | *, |
|
| 627 | name: Optional[str] = None, |
|
| 628 | comment: Optional[str] = None, |
|
| 629 | password: Optional[str] = None, |
|
| 630 | auth_source: Optional[UserAuthType] = None, |
|
| 631 | role_ids: Optional[List[str]] = None, |
|
| 632 | hosts: Optional[List[str]] = None, |
|
| 633 | hosts_allow: Optional[bool] = False, |
|
| 634 | ifaces: Optional[List[str]] = None, |
|
| 635 | ifaces_allow: Optional[bool] = False, |
|
| 636 | group_ids: Optional[List[str]] = None, |
|
| 637 | ) -> Any: |
|
| 638 | ||
| 639 | """Modifies an existing user. Most of the fields need to be supplied |
|
| 640 | for changing a single field even if no change is wanted for those. |
|
| 641 | Else empty values are inserted for the missing fields instead. |
|
| 642 | ||
| 643 | Arguments: |
|
| 644 | user_id: UUID of the user to be modified. |
|
| 645 | name: The new name for the user. |
|
| 646 | comment: Comment on the user. |
|
| 647 | password: The password for the user. |
|
| 648 | auth_source: Source allowed for authentication for this user. |
|
| 649 | roles_id: List of roles UUIDs for the user. |
|
| 650 | hosts: User access rules: List of hosts. |
|
| 651 | hosts_allow: Defines how the hosts list is to be interpreted. |
|
| 652 | If False (default) the list is treated as a deny list. |
|
| 653 | All hosts are allowed by default except those provided by |
|
| 654 | the hosts parameter. If True the list is treated as a |
|
| 655 | allow list. All hosts are denied by default except those |
|
| 656 | provided by the hosts parameter. |
|
| 657 | ifaces: User access rules: List of ifaces. |
|
| 658 | ifaces_allow: Defines how the ifaces list is to be interpreted. |
|
| 659 | If False (default) the list is treated as a deny list. |
|
| 660 | All ifaces are allowed by default except those provided by |
|
| 661 | the ifaces parameter. If True the list is treated as a |
|
| 662 | allow list. All ifaces are denied by default except those |
|
| 663 | provided by the ifaces parameter. |
|
| 664 | group_ids: List of group UUIDs for the user. |
|
| 665 | ||
| 666 | Returns: |
|
| 667 | The response. See :py:meth:`send_command` for details. |
|
| 668 | """ |
|
| 669 | if not user_id: |
|
| 670 | raise RequiredArgument( |
|
| 671 | function=self.modify_user.__name__, argument='user_id' |
|
| 672 | ) |
|
| 673 | ||
| 674 | cmd = XmlCommand("modify_user") |
|
| 675 | ||
| 676 | if user_id: |
|
| 677 | cmd.set_attribute("user_id", user_id) |
|
| 678 | ||
| 679 | if name: |
|
| 680 | cmd.add_element("new_name", name) |
|
| 681 | ||
| 682 | if role_ids: |
|
| 683 | for role in role_ids: |
|
| 684 | cmd.add_element("role", attrs={"id": role}) |
|
| 685 | ||
| 686 | if hosts: |
|
| 687 | cmd.add_element( |
|
| 688 | "hosts", |
|
| 689 | to_comma_list(hosts), |
|
| 690 | attrs={"allow": to_bool(hosts_allow)}, |
|
| 691 | ) |
|
| 692 | ||
| 693 | if ifaces: |
|
| 694 | cmd.add_element( |
|
| 695 | "ifaces", |
|
| 696 | to_comma_list(ifaces), |
|
| 697 | attrs={"allow": to_bool(ifaces_allow)}, |
|
| 698 | ) |
|
| 699 | ||
| 700 | if comment: |
|
| 701 | cmd.add_element("comment", comment) |
|
| 702 | ||
| 703 | if password: |
|
| 704 | cmd.add_element("password", password) |
|
| 705 | ||
| 706 | if auth_source: |
|
| 707 | _xmlauthsrc = cmd.add_element("sources") |
|
| 708 | _xmlauthsrc.add_element("source", auth_source.value) |
|
| 709 | ||
| 710 | if group_ids: |
|
| 711 | _xmlgroups = cmd.add_element("groups") |
|
| 712 | for group_id in group_ids: |
|
| 713 | _xmlgroups.add_element("group", attrs={"id": group_id}) |
|
| 714 | ||
| 715 | return self._send_xml_command(cmd) |
|
| 716 | ||