From 1c4d1998086d89238ca5d961bc1c8eee5685345c Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 29 Apr 2021 04:04:06 -0700 Subject: [PATCH] fix: preventing accessing predefined discovery URLs when override is provided (#1324) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly: - [X] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/google-api-python-client/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [X] Ensure the tests and linter pass - [X] Code coverage does not decrease (if any source code was changed) - [X] Appropriate docs were updated (if necessary) Fixes #1322 🦕 --- googleapiclient/discovery.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/googleapiclient/discovery.py b/googleapiclient/discovery.py index 4281ebb290e..2ea74a63d2b 100644 --- a/googleapiclient/discovery.py +++ b/googleapiclient/discovery.py @@ -274,9 +274,6 @@ def build( else: static_discovery = False - if discoveryServiceUrl is None: - discoveryServiceUrl = DISCOVERY_URI - if http is None: discovery_http = build_http() else: @@ -343,14 +340,16 @@ def _discovery_service_uri_options(discoveryServiceUrl, version): A list of URIs to be tried for the Service Discovery, in order. """ - urls = [discoveryServiceUrl, V2_DISCOVERY_URI] - # V1 Discovery won't work if the requested version is None - if discoveryServiceUrl == V1_DISCOVERY_URI and version is None: + if discoveryServiceUrl is not None: + return [discoveryServiceUrl] + if version is None: + # V1 Discovery won't work if the requested version is None logger.warning( "Discovery V1 does not support empty versions. Defaulting to V2..." ) - urls.pop(0) - return list(OrderedDict.fromkeys(urls)) + return [V2_DISCOVERY_URI] + else: + return [DISCOVERY_URI, V2_DISCOVERY_URI] def _retrieve_discovery_doc(