From 2d3f17b721869f517bd3e632842516bfce873c3d Mon Sep 17 00:00:00 2001 From: Sijun Liu Date: Tue, 9 Jun 2020 20:20:05 -0700 Subject: [PATCH] fix: update GOOGLE_API_USE_MTLS values --- googleapiclient/discovery.py | 14 +++++++------- tests/test_discovery.py | 20 ++++++++++---------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/googleapiclient/discovery.py b/googleapiclient/discovery.py index 55367c0a491..f12b04f3ad7 100644 --- a/googleapiclient/discovery.py +++ b/googleapiclient/discovery.py @@ -471,17 +471,17 @@ def build_from_document( not client_options or not client_options.api_endpoint ): mtls_endpoint = urljoin(service["mtlsRootUrl"], service["servicePath"]) - use_mtls_env = os.getenv("GOOGLE_API_USE_MTLS", "Never") + use_mtls_env = os.getenv("GOOGLE_API_USE_MTLS", "never") - if not use_mtls_env in ("Never", "Auto", "Always"): + if not use_mtls_env in ("never", "auto", "always"): raise MutualTLSChannelError( - "Unsupported GOOGLE_API_USE_MTLS value. Accepted values: Never, Auto, Always" + "Unsupported GOOGLE_API_USE_MTLS value. Accepted values: never, auto, always" ) - # Switch to mTLS endpoint, if environment variable is "Always", or - # environment varibable is "Auto" and client cert exists. - if use_mtls_env == "Always" or ( - use_mtls_env == "Auto" and client_cert_to_use + # Switch to mTLS endpoint, if environment variable is "always", or + # environment varibable is "auto" and client cert exists. + if use_mtls_env == "always" or ( + use_mtls_env == "auto" and client_cert_to_use ): base = mtls_endpoint diff --git a/tests/test_discovery.py b/tests/test_discovery.py index 9015066006a..d6cd9e1d1f3 100644 --- a/tests/test_discovery.py +++ b/tests/test_discovery.py @@ -590,9 +590,9 @@ def test_exception_with_client_cert_source(self): @parameterized.expand( [ - ("Never", REGULAR_ENDPOINT), - ("Auto", MTLS_ENDPOINT), - ("Always", MTLS_ENDPOINT), + ("never", REGULAR_ENDPOINT), + ("auto", MTLS_ENDPOINT), + ("always", MTLS_ENDPOINT), ] ) def test_mtls_with_provided_client_cert(self, use_mtls_env, base_url): @@ -610,7 +610,7 @@ def test_mtls_with_provided_client_cert(self, use_mtls_env, base_url): self.check_http_client_cert(plus, has_client_cert=True) self.assertEqual(plus._baseUrl, base_url) - @parameterized.expand(["Never", "Auto", "Always"]) + @parameterized.expand(["never", "auto", "always"]) def test_endpoint_not_switch(self, use_mtls_env): # Test endpoint is not switched if user provided api endpoint discovery = open(datafile("plus.json")).read() @@ -630,9 +630,9 @@ def test_endpoint_not_switch(self, use_mtls_env): @parameterized.expand( [ - ("Never", REGULAR_ENDPOINT), - ("Auto", MTLS_ENDPOINT), - ("Always", MTLS_ENDPOINT), + ("never", REGULAR_ENDPOINT), + ("auto", MTLS_ENDPOINT), + ("always", MTLS_ENDPOINT), ] ) @mock.patch( @@ -667,9 +667,9 @@ def test_mtls_with_default_client_cert( @parameterized.expand( [ - ("Never", REGULAR_ENDPOINT), - ("Auto", REGULAR_ENDPOINT), - ("Always", MTLS_ENDPOINT), + ("never", REGULAR_ENDPOINT), + ("auto", REGULAR_ENDPOINT), + ("always", MTLS_ENDPOINT), ] ) @mock.patch(