Skip to content

Commit

Permalink
PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
tianjing-li committed Dec 14, 2023
1 parent 2ddd078 commit 4715ec3
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 11 deletions.
8 changes: 5 additions & 3 deletions sharepoint/provider/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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):
Expand All @@ -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]},
)

Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion sharepoint/provider/consts.py

This file was deleted.

6 changes: 0 additions & 6 deletions sharepoint/provider/enums.py

This file was deleted.

2 changes: 1 addition & 1 deletion sharepoint/provider/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 4715ec3

Please sign in to comment.