Skip to content

Commit bcae0d5

Browse files
committed
fix: Support pagination for fetching users
When fetching users, pagination wasn't supported, and the naive approach required fetching page size greater than all users. Added fetching with pagination now.
1 parent 1999ece commit bcae0d5

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

main.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,22 @@ def auth():
8282
async def fetch() -> list[User]:
8383
async with httpx.AsyncClient(
8484
headers={"Authorization": f"Bearer {config.authentik_token}"},
85-
timeout=15.0,
85+
timeout=30.0,
8686
) as client:
87-
response = await client.get(
88-
"https://auth.apps.hskrk.pl/api/v3/core/users/"
89-
"?attributes={\"membershipExpirationTimestamp__gt\": 1734998400}&page_size=200",
87+
url = (
88+
"https://auth.apps.hskrk.pl/api/v3/core/users/?"
89+
"attributes={\"membershipExpirationTimestamp__gt\": 100}&page_size=50"
9090
)
91+
response = await client.get(url)
92+
parsed_response = response.json()
93+
results = parsed_response["results"]
94+
while parsed_response["pagination"]["next"]:
95+
response = await client.get(f"{url}&page={parsed_response["pagination"]["next"]}")
96+
parsed_response = response.json()
97+
results += parsed_response["results"]
9198
return [
9299
User(**u)
93-
for u in response.json()['results']
100+
for u in results
94101
]
95102

96103

0 commit comments

Comments
 (0)