From 8a4827017ea171ef0dab49cb79785c997075bab6 Mon Sep 17 00:00:00 2001 From: Max Hora Date: Fri, 27 Mar 2020 22:04:45 +0200 Subject: [PATCH] gdrive: use default client and secret id; Debug message on retry of failed GDrive API call. (#3539) --- dvc/remote/gdrive.py | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/dvc/remote/gdrive.py b/dvc/remote/gdrive.py index a695dd09b..c3d30e3b4 100644 --- a/dvc/remote/gdrive.py +++ b/dvc/remote/gdrive.py @@ -46,7 +46,10 @@ def gdrive_retry(func): return False retry_codes = [403, 500, 502, 503, 504] - return exc.error.get("code", 0) in retry_codes + result = exc.error.get("code", 0) in retry_codes + if result: + logger.debug("Retry GDrive API call failed with {}.".format(exc)) + return result # 15 tries, start at 0.5s, multiply by golden ratio, cap at 20s return retry( @@ -96,6 +99,9 @@ class RemoteGDrive(RemoteBASE): GDRIVE_CREDENTIALS_DATA = "GDRIVE_CREDENTIALS_DATA" DEFAULT_USER_CREDENTIALS_FILE = "gdrive-user-credentials.json" + DEFAULT_GDRIVE_CLIENT_ID = "710796635688-iivsgbgsb6uv1fap6635dhvuei09o66c.apps.googleusercontent.com" # noqa: E501 + DEFAULT_GDRIVE_CLIENT_SECRET = "a1Fz59uTpVNeG_VGuSKDLJXv" + def __init__(self, repo, config): super().__init__(repo, config) self.path_info = self.path_cls(config["url"]) @@ -153,14 +159,15 @@ class RemoteGDrive(RemoteBASE): ) # Validate OAuth 2.0 Client ID configuration - if not self._use_service_account and ( - not self._client_id or not self._client_secret - ): - raise DvcException( - "Please specify Google Drive's client id and " - "secret in DVC config. Learn more at " - "{}.".format(format_link("https://man.dvc.org/remote/modify")) - ) + if not self._use_service_account: + if bool(self._client_id) != bool(self._client_secret): + raise DvcException( + "Please specify Google Drive's client id and secret in " + "DVC config or omit both to use defaults. Learn more at " + "{}.".format( + format_link("https://man.dvc.org/remote/modify") + ) + ) @wrap_prop(threading.RLock()) @cached_property @@ -186,8 +193,9 @@ class RemoteGDrive(RemoteBASE): } else: GoogleAuth.DEFAULT_SETTINGS["client_config"] = { - "client_id": self._client_id, - "client_secret": self._client_secret, + "client_id": self._client_id or self.DEFAULT_GDRIVE_CLIENT_ID, + "client_secret": self._client_secret + or self.DEFAULT_GDRIVE_CLIENT_SECRET, "auth_uri": "https://accounts.google.com/o/oauth2/auth", "token_uri": "https://oauth2.googleapis.com/token", "revoke_uri": "https://oauth2.googleapis.com/revoke",