Skip to content

Commit

Permalink
Reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
kabusag committed Apr 9, 2021
1 parent e2208af commit b75b01e
Showing 1 changed file with 32 additions and 27 deletions.
59 changes: 32 additions & 27 deletions githubapp/azuread.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,48 +79,53 @@ def get_group_members(self, token=None, group_name=None):
# print("Graph API call result: %s" % json.dumps(graph_data, indent=2))
try:
group_info = json.loads(json.dumps(graph_data, indent=2))["value"][0]
members = self.get_group_members_pages(token, f'{self.AZURE_API_ENDPOINT}/groups/{group_info["id"]}/members')
members = self.get_group_members_pages(
token, f'{self.AZURE_API_ENDPOINT}/groups/{group_info["id"]}/members'
)
except IndexError as e:
members = []
for member in members:
if member['@odata.type'] == '#microsoft.graph.group':
print("Nested group: ", member["displayName"])
if member["@odata.type"] == "#microsoft.graph.group":
print("Nested group: ", member["displayName"])
else:
user_info = self.get_user_info(token=token, user=member["id"])
if self.AZURE_USER_IS_UPN:
user = {
"username": user_info[self.USERNAME_ATTRIBUTE].split("@")[0],
"email": user_info["mail"],
}
else:
user = {
"username": user_info[self.USERNAME_ATTRIBUTE],
"email": user_info["mail"],
}
member_list.append(user)
user_info = self.get_user_info(token=token, user=member["id"])
if self.AZURE_USER_IS_UPN:
user = {
"username": user_info[self.USERNAME_ATTRIBUTE].split("@")[0],
"email": user_info["mail"],
}
else:
user = {
"username": user_info[self.USERNAME_ATTRIBUTE],
"email": user_info["mail"],
}
member_list.append(user)
return member_list

def get_group_members_pages(self, token=None, url=None):
"""
Get group members
:param token:
:param url:
:return members:
:rtype members: dict
"""
members_data = requests.get(
url,
headers={"Authorization": f"Bearer {token}"}
)
"""
members_data = requests.get(url, headers={"Authorization": f"Bearer {token}"})
if members_data.ok != True:
print(f"[GetMembers]: Error getting members data error code {members_data.status_code}")
return []

print(
f"[GetMembers]: Error getting members data error code {members_data.status_code}"
)
return []

members_data_content = members_data.json()
members = members_data_content["value"]
if "@odata.nextLink" in members_data_content:
members.extend(self.get_group_members_pages(token, members_data_content["@odata.nextLink"]))
return members
if "@odata.nextLink" in members_data_content:
members.extend(
self.get_group_members_pages(
token, members_data_content["@odata.nextLink"]
)
)
return members

def get_user_info(self, token=None, user=None):
"""
Expand Down

0 comments on commit b75b01e

Please sign in to comment.