Skip to content

Commit

Permalink
Merge pull request #34 from minds-ai/fix_google_drive
Browse files Browse the repository at this point in the history
Switch to updated Google Drive API dependencies
  • Loading branch information
jbedorf committed Jun 29, 2021
2 parents 8855b09 + 9b90bc2 commit 7bbcfef
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ VOLUME /conf
# Copy wheel from build container into current container and install.
WORKDIR /dist
COPY --from=build /build/dist /dist
RUN python -m pip install zoom_drive_connector-1.2.0-py3-none-any.whl
RUN python -m pip install zoom_drive_connector-*-py3-none-any.whl

# Create runuser and switch to it.
RUN useradd -ms /bin/false runuser
Expand Down
7 changes: 3 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ pyjwt==1.5.3
pyyaml>=5.1
slackclient==1.2.1
schedule==0.5.0
google-api-python-client==1.6.7
oauth2client==4.1.2
httplib2shim==0.0.3
httplib2==0.15.0
google-api-python-client==2.10.0
google-auth-httplib2==0.1.0
google-auth-oauthlib==0.4.4
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

setup(
name='zoom-drive-connector',
version='1.3.1',
version='1.4',
packages=find_packages(exclude=['tests']),
url='https://github.com/minds-ai/zoom-drive-connector',
license='Apache 2.0',
Expand All @@ -24,9 +24,9 @@
'pyyaml>=5.1',
'slackclient==1.2.1',
'schedule==0.5.0',
'google-api-python-client==1.6.7',
'oauth2client==4.1.2',
'httplib2shim==0.0.3'
'google-api-python-client==2.10.0',
'google-auth-httplib2==0.1.0',
'google-auth-oauthlib==0.4.4',
],
python_requires='>=3.5, <4',
# Development requirements.
Expand Down
37 changes: 23 additions & 14 deletions zoom_drive_connector/drive/drive_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
import logging
from typing import TypeVar, cast

import httplib2shim
import apiclient
from oauth2client import file, client, tools
from google.oauth2.credentials import Credentials
from google.auth.transport.requests import Request
from google_auth_oauthlib.flow import InstalledAppFlow
from googleapiclient.discovery import build
from googleapiclient.http import MediaFileUpload

from zoom_drive_connector.configuration import DriveConfig, SystemConfig, APIConfigBase

Expand Down Expand Up @@ -48,16 +50,23 @@ def setup(self):
"""Triggers the OAuth2 setup flow for Google API endpoints. Requires the ability to open
a link within a web browser in order to work.
"""
store = file.Storage(self.drive_config.credentials_json)
creds = store.get()

if not creds or creds.invalid:
flow = client.flow_from_clientsecrets(self.drive_config.client_secret_json, self._scopes)
creds = tools.run_flow(flow, store)

self._service = apiclient.discovery.build('drive',
'v3',
http=creds.authorize(httplib2shim.Http()))
creds = None
if os.path.exists(self.drive_config.credentials_json):
creds = Credentials.from_authorized_user_file(
self.drive_config.credentials_json, self._scopes
)
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(
self.drive_config.client_secret_json, self._scopes
)
creds = flow.run_local_server(port=0)
with open(self.drive_config.credentials_json, 'w') as token:
token.write(creds.to_json())

self._service = build('drive', 'v3', credentials=creds)

log.log(logging.INFO, 'Drive connection established.')

Expand All @@ -83,7 +92,7 @@ def upload_file(self, file_path: str, name: str, folder_id: str) -> str:
metadata = {'name': name, 'parents': [folder_id]}

# Create a new upload of the recording and execute it.
media = apiclient.http.MediaFileUpload(file_path,
media = MediaFileUpload(file_path,
mimetype='video/mp4',
chunksize=1024*1024,
resumable=True
Expand Down

0 comments on commit 7bbcfef

Please sign in to comment.