-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: closes #262, add support for ZIA convert admin to regular user …
…endpoint test: update test suite to add tests for converting admin to regular user Signed-off-by: mkelly <[email protected]>
- Loading branch information
Showing
2 changed files
with
53 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
from box import Box, BoxList | ||
from restfly.endpoint import APIEndpoint | ||
|
||
from pyzscaler.utils import Iterator, snake_to_camel | ||
from pyzscaler.utils import Iterator, convert_keys, snake_to_camel | ||
|
||
|
||
class AdminAndRoleManagementAPI(APIEndpoint): | ||
|
@@ -57,7 +57,7 @@ def add_user(self, name: str, login_name: str, email: str, password: str, **kwar | |
... name="Jane Bob", | ||
... login_name="[email protected]", | ||
... password="hunter3", | ||
... email="[email protected], | ||
... email="[email protected]", | ||
... admin_scope="department", | ||
... scope_ids = ['376542', '245688']) | ||
|
@@ -66,7 +66,7 @@ def add_user(self, name: str, login_name: str, email: str, password: str, **kwar | |
... name="Head Bob", | ||
... login_name="[email protected]", | ||
... password="hunter4", | ||
... email="[email protected], | ||
... email="[email protected]", | ||
... is_auditor=True) | ||
""" | ||
|
@@ -265,3 +265,31 @@ def update_user(self, user_id: str, **kwargs) -> dict: | |
payload[snake_to_camel(key)] = value | ||
|
||
return self._put(f"adminUsers/{user_id}", json=payload) | ||
|
||
def convert_admin_to_user(self, user_id: str, group_ids: list, **kwargs) -> Box: | ||
""" | ||
Convert an admin user to a standard user. | ||
Args: | ||
user_id (str): The unique id of the admin user to be converted. | ||
group_ids (list): A list of group ids to assign to the user. | ||
**kwargs: Optional keyword args. | ||
Returns: | ||
:obj:`Box`: The converted user resource record. | ||
Examples: | ||
Convert an admin user to a standard user: | ||
>>> user = zia.admin_and_role_management.convert_admin_to_user(user_id='99695301', | ||
... group_ids=['3846532', '3846541']) | ||
""" | ||
payload = {"groups": [{"id": group_id} for group_id in group_ids]} | ||
|
||
# Update the payload with keyword arguments | ||
payload.update({k: v for k, v in kwargs.items() if v is not None}) | ||
|
||
# Convert snake to camelcase if needed | ||
payload = convert_keys(payload) | ||
|
||
return self._post(f"adminUsers/{user_id}/convertToUser", json=payload) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters