Skip to content

Commit

Permalink
Merge pull request #4278 from yuvipanda/pagination
Browse files Browse the repository at this point in the history
scripts: Support pagination in rsync-active-users
  • Loading branch information
yuvipanda authored Jun 25, 2024
2 parents c03da1f + 1282ffa commit 9a2e739
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions extra-scripts/rsync-active-users.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,31 @@ def escape(to_escape, safe=SAFE, escape_char=ESCAPE_CHAR, allow_collisions=False


def get_all_users(hub_url, token):
url = f"{hub_url}/hub/api/users"
resp = requests.get(url, headers={"Authorization": f"token {token}"})
offset = 0
limit = 200 # The default max size for a page

while True:
url = f"{hub_url}/hub/api/users?offset={offset}&limit={limit}"
resp = requests.get(
url,
headers={
"Authorization": f"token {token}",
"Accept": "application/jupyterhub-pagination+json",
},
)

users = resp.json()
for user in users:
if user["last_activity"]:
user["last_activity"] = parse(user.get("last_activity"))
return users
paginated_resp = resp.json()
users = paginated_resp["items"]
pagination = paginated_resp.get("_pagination", {}).get("next", None)
if pagination is None:
break
else:
offset = pagination["offset"]
limit = pagination["limit"]
for user in users:
if user["last_activity"]:
user["last_activity"] = parse(user.get("last_activity"))
yield user


def rsync(user, src_basedir, dest_basedir, dry_run):
Expand Down

0 comments on commit 9a2e739

Please sign in to comment.