membership API pagination
This commit is contained in:
parent
a4f3ffa2d8
commit
c71f3bfb5c
|
@ -150,32 +150,35 @@ 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()
|
||||||
membership_details = response["data"]
|
membership_details = response["data"]
|
||||||
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"]
|
||||||
current_app.logger.error(f"Response Code:{r.status_code} {r.text}")
|
else:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
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):
|
||||||
|
|
Loading…
Reference in New Issue