@@ 61-153 (lines=93) @@ | ||
58 | # Is authenticated on gvmd |
|
59 | self._authenticated = False |
|
60 | ||
61 | def modify_user( |
|
62 | self, |
|
63 | user_id: str = None, |
|
64 | *, |
|
65 | name: Optional[str] = None, |
|
66 | comment: Optional[str] = None, |
|
67 | password: Optional[str] = None, |
|
68 | auth_source: Optional[UserAuthType] = None, |
|
69 | role_ids: Optional[List[str]] = None, |
|
70 | hosts: Optional[List[str]] = None, |
|
71 | hosts_allow: Optional[bool] = False, |
|
72 | ifaces: Optional[List[str]] = None, |
|
73 | ifaces_allow: Optional[bool] = False, |
|
74 | group_ids: Optional[List[str]] = None, |
|
75 | ) -> Any: |
|
76 | ||
77 | """Modifies an existing user. Most of the fields need to be supplied |
|
78 | for changing a single field even if no change is wanted for those. |
|
79 | Else empty values are inserted for the missing fields instead. |
|
80 | ||
81 | Arguments: |
|
82 | user_id: UUID of the user to be modified. |
|
83 | name: The new name for the user. |
|
84 | comment: Comment on the user. |
|
85 | password: The password for the user. |
|
86 | auth_source: Source allowed for authentication for this user. |
|
87 | roles_id: List of roles UUIDs for the user. |
|
88 | hosts: User access rules: List of hosts. |
|
89 | hosts_allow: Defines how the hosts list is to be interpreted. |
|
90 | If False (default) the list is treated as a deny list. |
|
91 | All hosts are allowed by default except those provided by |
|
92 | the hosts parameter. If True the list is treated as a |
|
93 | allow list. All hosts are denied by default except those |
|
94 | provided by the hosts parameter. |
|
95 | ifaces: User access rules: List of ifaces. |
|
96 | ifaces_allow: Defines how the ifaces list is to be interpreted. |
|
97 | If False (default) the list is treated as a deny list. |
|
98 | All ifaces are allowed by default except those provided by |
|
99 | the ifaces parameter. If True the list is treated as a |
|
100 | allow list. All ifaces are denied by default except those |
|
101 | provided by the ifaces parameter. |
|
102 | group_ids: List of group UUIDs for the user. |
|
103 | ||
104 | Returns: |
|
105 | The response. See :py:meth:`send_command` for details. |
|
106 | """ |
|
107 | if not user_id: |
|
108 | raise RequiredArgument( |
|
109 | function=self.modify_user.__name__, argument='user_id' |
|
110 | ) |
|
111 | ||
112 | cmd = XmlCommand("modify_user") |
|
113 | ||
114 | if user_id: |
|
115 | cmd.set_attribute("user_id", user_id) |
|
116 | ||
117 | if name: |
|
118 | cmd.add_element("new_name", name) |
|
119 | ||
120 | if role_ids: |
|
121 | for role in role_ids: |
|
122 | cmd.add_element("role", attrs={"id": role}) |
|
123 | ||
124 | if hosts: |
|
125 | cmd.add_element( |
|
126 | "hosts", |
|
127 | to_comma_list(hosts), |
|
128 | attrs={"allow": to_bool(hosts_allow)}, |
|
129 | ) |
|
130 | ||
131 | if ifaces: |
|
132 | cmd.add_element( |
|
133 | "ifaces", |
|
134 | to_comma_list(ifaces), |
|
135 | attrs={"allow": to_bool(ifaces_allow)}, |
|
136 | ) |
|
137 | ||
138 | if comment: |
|
139 | cmd.add_element("comment", comment) |
|
140 | ||
141 | if password: |
|
142 | cmd.add_element("password", password) |
|
143 | ||
144 | if auth_source: |
|
145 | _xmlauthsrc = cmd.add_element("sources") |
|
146 | _xmlauthsrc.add_element("source", auth_source.value) |
|
147 | ||
148 | if group_ids: |
|
149 | _xmlgroups = cmd.add_element("groups") |
|
150 | for group_id in group_ids: |
|
151 | _xmlgroups.add_element("group", attrs={"id": group_id}) |
|
152 | ||
153 | return self._send_xml_command(cmd) |
|
154 |
@@ 3979-4076 (lines=98) @@ | ||
3976 | ||
3977 | return self._send_xml_command(cmd) |
|
3978 | ||
3979 | def modify_user( |
|
3980 | self, |
|
3981 | user_id: str = None, |
|
3982 | name: str = None, |
|
3983 | *, |
|
3984 | new_name: Optional[str] = None, |
|
3985 | comment: Optional[str] = None, |
|
3986 | password: Optional[str] = None, |
|
3987 | auth_source: Optional[UserAuthType] = None, |
|
3988 | role_ids: Optional[List[str]] = None, |
|
3989 | hosts: Optional[List[str]] = None, |
|
3990 | hosts_allow: Optional[bool] = False, |
|
3991 | ifaces: Optional[List[str]] = None, |
|
3992 | ifaces_allow: Optional[bool] = False, |
|
3993 | group_ids: Optional[List[str]] = None, |
|
3994 | ) -> Any: |
|
3995 | """Modifies an existing user. Most of the fields need to be supplied |
|
3996 | for changing a single field even if no change is wanted for those. |
|
3997 | Else empty values are inserted for the missing fields instead. |
|
3998 | Arguments: |
|
3999 | user_id: UUID of the user to be modified. Overrides name element |
|
4000 | argument. |
|
4001 | name: The name of the user to be modified. Either user_id or name |
|
4002 | must be passed. |
|
4003 | new_name: The new name for the user. |
|
4004 | comment: Comment on the user. |
|
4005 | password: The password for the user. |
|
4006 | auth_source: Source allowed for authentication for this user. |
|
4007 | roles_id: List of roles UUIDs for the user. |
|
4008 | hosts: User access rules: List of hosts. |
|
4009 | hosts_allow: Defines how the hosts list is to be interpreted. |
|
4010 | If False (default) the list is treated as a deny list. |
|
4011 | All hosts are allowed by default except those provided by |
|
4012 | the hosts parameter. If True the list is treated as a |
|
4013 | allow list. All hosts are denied by default except those |
|
4014 | provided by the hosts parameter. |
|
4015 | ifaces: User access rules: List of ifaces. |
|
4016 | ifaces_allow: Defines how the ifaces list is to be interpreted. |
|
4017 | If False (default) the list is treated as a deny list. |
|
4018 | All ifaces are allowed by default except those provided by |
|
4019 | the ifaces parameter. If True the list is treated as a |
|
4020 | allow list. All ifaces are denied by default except those |
|
4021 | provided by the ifaces parameter. |
|
4022 | group_ids: List of group UUIDs for the user. |
|
4023 | ||
4024 | Returns: |
|
4025 | The response. See :py:meth:`send_command` for details. |
|
4026 | """ |
|
4027 | if not user_id and not name: |
|
4028 | raise RequiredArgument( |
|
4029 | function=self.modify_user.__name__, argument='user_id or name' |
|
4030 | ) |
|
4031 | ||
4032 | cmd = XmlCommand("modify_user") |
|
4033 | ||
4034 | if user_id: |
|
4035 | cmd.set_attribute("user_id", user_id) |
|
4036 | else: |
|
4037 | cmd.add_element("name", name) |
|
4038 | ||
4039 | if new_name: |
|
4040 | cmd.add_element("new_name", new_name) |
|
4041 | ||
4042 | if role_ids: |
|
4043 | for role in role_ids: |
|
4044 | cmd.add_element("role", attrs={"id": role}) |
|
4045 | ||
4046 | if hosts: |
|
4047 | cmd.add_element( |
|
4048 | "hosts", |
|
4049 | to_comma_list(hosts), |
|
4050 | attrs={"allow": to_bool(hosts_allow)}, |
|
4051 | ) |
|
4052 | ||
4053 | if ifaces: |
|
4054 | cmd.add_element( |
|
4055 | "ifaces", |
|
4056 | to_comma_list(ifaces), |
|
4057 | attrs={"allow": to_bool(ifaces_allow)}, |
|
4058 | ) |
|
4059 | ||
4060 | if comment: |
|
4061 | cmd.add_element("comment", comment) |
|
4062 | ||
4063 | if password: |
|
4064 | cmd.add_element("password", password) |
|
4065 | ||
4066 | if auth_source: |
|
4067 | _xmlauthsrc = cmd.add_element("sources") |
|
4068 | _xmlauthsrc.add_element("source", auth_source.value) |
|
4069 | ||
4070 | if group_ids: |
|
4071 | _xmlgroups = cmd.add_element("groups") |
|
4072 | for group_id in group_ids: |
|
4073 | _xmlgroups.add_element("group", attrs={"id": group_id}) |
|
4074 | ||
4075 | return self._send_xml_command(cmd) |
|
4076 | ||
4077 | def restore(self, entity_id: str) -> Any: |
|
4078 | """Restore an entity from the trashcan |
|
4079 |