membership API pagination

This commit is contained in:
sayali 2021-02-10 13:14:31 -08:00
parent a4f3ffa2d8
commit c71f3bfb5c
1 changed files with 18 additions and 15 deletions

View File

@ -150,22 +150,20 @@ def retrieve_user_memberships(user_api_url, user_membership_api_url, access_toke
code across the community, current implementation is config driven. Without user_membership_api_url code across the community, current implementation is config driven. Without user_membership_api_url
configured, it is backward compatible. configured, it is backward compatible.
""" """
tls_provider = plugins.get(current_app.config.get("PING_USER_MEMBERSHIP_TLS_PROVIDER"))
# put user id in url # put user id in url
user_membership_api_url = user_membership_api_url.replace("%user_id%", profile["userId"]) user_membership_api_url = user_membership_api_url.replace("%user_id%", profile["userId"])
session = tls_provider.session(current_app.config.get("PING_USER_MEMBERSHIP_SERVICE"))
headers = {"Content-Type": "application/json"} headers = {"Content-Type": "application/json"}
data = {"relation": "DIRECT_ONLY", "groupFilter": {"type": "GOOGLE"}, "size": 500} data = {"relation": "DIRECT_ONLY", "groupFilter": {"type": "GOOGLE"}, "size": 500}
tls_provider = plugins.get(current_app.config.get("PING_USER_MEMBERSHIP_TLS_PROVIDER"))
# retrieve information about the current user
session = tls_provider.session(current_app.config.get("PING_USER_MEMBERSHIP_SERVICE"))
r = session.post(user_membership_api_url, data=json.dumps(data), headers=headers)
user_membership = {"email": profile["email"], user_membership = {"email": profile["email"],
"thumbnailPhotoUrl": profile["thumbnailPhotoUrl"], "thumbnailPhotoUrl": profile["thumbnailPhotoUrl"],
"googleGroups": []} "googleGroups": []}
while True:
# retrieve information about the current user memberships
r = session.post(user_membership_api_url, data=json.dumps(data), headers=headers)
if r.status_code == 200: if r.status_code == 200:
response = r.json() response = r.json()
@ -173,9 +171,14 @@ def retrieve_user_memberships(user_api_url, user_membership_api_url, access_toke
for membership in membership_details: for membership in membership_details:
user_membership["googleGroups"].append(membership["membership"]["name"]) user_membership["googleGroups"].append(membership["membership"]["name"])
return user, user_membership if "nextPageToken" in response and response["nextPageToken"]:
data["nextPageToken"] = response["nextPageToken"]
else:
break
else:
current_app.logger.error(f"Response Code:{r.status_code} {r.text}") current_app.logger.error(f"Response Code:{r.status_code} {r.text}")
break
return user, user_membership
def create_user_roles(profile): def create_user_roles(profile):