From b75b01e9bafac5b65799c7b30e7f0ac121534c3e Mon Sep 17 00:00:00 2001 From: Buhleva Date: Fri, 9 Apr 2021 16:20:42 +0300 Subject: [PATCH] Reformat --- githubapp/azuread.py | 59 ++++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/githubapp/azuread.py b/githubapp/azuread.py index 313c172..4f00b70 100644 --- a/githubapp/azuread.py +++ b/githubapp/azuread.py @@ -79,27 +79,29 @@ 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 @@ -107,20 +109,23 @@ def get_group_members_pages(self, token=None, url=None): :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): """