From 4715ec376684e7bafefc094ddde1bd3d3830aa30 Mon Sep 17 00:00:00 2001 From: Tianjing Li Date: Thu, 14 Dec 2023 12:32:03 -0500 Subject: [PATCH] PR comments --- sharepoint/provider/client.py | 8 +++++--- sharepoint/provider/consts.py | 1 - sharepoint/provider/enums.py | 6 ------ sharepoint/provider/provider.py | 2 +- 4 files changed, 6 insertions(+), 11 deletions(-) delete mode 100644 sharepoint/provider/consts.py delete mode 100644 sharepoint/provider/enums.py diff --git a/sharepoint/provider/client.py b/sharepoint/provider/client.py index 080aef1b4..18a92255b 100644 --- a/sharepoint/provider/client.py +++ b/sharepoint/provider/client.py @@ -14,6 +14,7 @@ class SharepointClient: DEFAULT_REGION = "NAM" BASE_URL = "https://graph.microsoft.com/v1.0" SEARCH_ENTITY_TYPES = ["driveItem"] + DRIVE_ITEM_DATA_TYPE = "#microsoft.graph.driveItem" APPLICATION_AUTH = "application" DELEGATED_AUTH = "user" @@ -42,9 +43,10 @@ def set_app_access_token(self, tenant_id, client_id, client_secret): "Error while retrieving access token from Microsoft Graph API" ) self.access_token = token_response["access_token"] + self.headers = {"Authorization": f"Bearer {self.access_token}"} except Exception as e: raise UpstreamProviderError( - f"Error while initializing Teams client: {str(e)}" + f"Error while initializing Sharepoint client: {str(e)}" ) def set_user_access_token(self, token): @@ -65,7 +67,7 @@ def search(self, query): response = requests.post( f"{self.BASE_URL}/search/query", - headers={"Authorization": f"Bearer {self.access_token}"}, + headers=self.headers, json={"requests": [request]}, ) @@ -79,7 +81,7 @@ def search(self, query): def get_drive_item_content(self, parent_drive_id, resource_id): response = requests.get( f"{self.BASE_URL}/drives/{parent_drive_id}/items/{resource_id}/content", - headers={"Authorization": f"Bearer {self.access_token}"}, + headers=self.headers, ) # Fail gracefully when retrieving content diff --git a/sharepoint/provider/consts.py b/sharepoint/provider/consts.py deleted file mode 100644 index 107b11979..000000000 --- a/sharepoint/provider/consts.py +++ /dev/null @@ -1 +0,0 @@ -CACHE_SIZE = 256 diff --git a/sharepoint/provider/enums.py b/sharepoint/provider/enums.py deleted file mode 100644 index 004368177..000000000 --- a/sharepoint/provider/enums.py +++ /dev/null @@ -1,6 +0,0 @@ -from enum import Enum - - -class MicrosoftDataType(Enum): - DRIVE_ITEM = "#microsoft.graph.driveItem" - LIST_ITEM = "#microsoft.graph.listItem" diff --git a/sharepoint/provider/provider.py b/sharepoint/provider/provider.py index e7b3e42f7..6b30acc8b 100644 --- a/sharepoint/provider/provider.py +++ b/sharepoint/provider/provider.py @@ -57,7 +57,7 @@ def collect_items(sharepoint_client, hits): # Gather data drive_items = [] for hit in hits: - if hit["resource"]["@odata.type"] == "#microsoft.graph.driveItem": + if hit["resource"]["@odata.type"] == sharepoint_client.DRIVE_ITEM_DATA_TYPE: parent_drive_id = hit["resource"]["parentReference"]["driveId"] resource_id = hit["resource"]["id"] drive_item = sharepoint_client.get_drive_item_content(