Skip to content

Commit

Permalink
eliminate unnecessary api calls for impersonation
Browse files Browse the repository at this point in the history
  • Loading branch information
mcg1969 committed Oct 5, 2024
1 parent b99621d commit 8181a94
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions ae5_tools/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2127,7 +2127,7 @@ def _post_user(self, users, include_login=False):
urec.setdefault("lastLogin", 0)
return users

def user_list(self, filter: str | None = None, format: str | None = None, include_login=True):
def user_list(self, filter: str | None = None, format: str | None = None, include_login=True, fast=False):
"""
Provides User details.
Expand All @@ -2139,6 +2139,8 @@ def user_list(self, filter: str | None = None, format: str | None = None, includ
CLI output type. If none is provided, `text` is the default.
include_login: bool = True
Used for `_post_user` post-processing of records.
fast: bool = False
Used for impersonation. Skips the group and role queries
Returns
-------
Expand All @@ -2149,6 +2151,11 @@ def user_list(self, filter: str | None = None, format: str | None = None, includ
# Get user list
users = self._get_paginated("users")

# Fast exit mode
if fast:
users = self._fix_records("user", users, filter)
return self._format_response(users, format=format)

# Get realm roles user map
role_maps: dict[str, list] = self._build_realm_role_user_map()

Expand Down Expand Up @@ -2395,12 +2402,12 @@ def _merge_users_with_realm_groups(self, users: list[dict], group_maps: dict[str
user["realm_groups"] = self._get_user_realm_groups(user=user, group_maps=group_maps)
return users

def user_info(self, ident, format=None, quiet=False, include_login=True):
response = self._ident_record("user", ident, quiet=False, include_login=include_login)
def user_info(self, ident, format=None, quiet=False, include_login=True, fast=False):
response = self._ident_record("user", ident, quiet=False, include_login=include_login, fast=fast)
return self._format_response(response, format)

def impersonate(self, user_or_id):
record = self.user_info(user_or_id, include_login=False)
record = self.user_info(user_or_id, fast=True)
old_headers = self.session.headers.copy()
try:
self._post(f'users/{record["id"]}/impersonation')
Expand Down

0 comments on commit 8181a94

Please sign in to comment.