From b737ea09f004fbd0f160d641ec9f14a6c6c98715 Mon Sep 17 00:00:00 2001 From: arithmetic1728 <58957152+arithmetic1728@users.noreply.github.com> Date: Wed, 10 Jun 2020 10:48:26 -0700 Subject: [PATCH] fix: update GOOGLE_API_USE_MTLS values (#449) Go client uses lower case, so change the values to lower case. --- .../%sub/services/%service/client.py.j2 | 12 +++++------ .../%name_%version/%sub/test_%service.py.j2 | 20 +++++++++---------- .../%sub/services/%service/client.py.j2 | 12 +++++------ .../%name_%version/%sub/test_%service.py.j2 | 20 +++++++++---------- 4 files changed, 32 insertions(+), 32 deletions(-) diff --git a/gapic/ads-templates/%namespace/%name/%version/%sub/services/%service/client.py.j2 b/gapic/ads-templates/%namespace/%name/%version/%sub/services/%service/client.py.j2 index 6e001f3e2c..559fc72c16 100644 --- a/gapic/ads-templates/%namespace/%name/%version/%sub/services/%service/client.py.j2 +++ b/gapic/ads-templates/%namespace/%name/%version/%sub/services/%service/client.py.j2 @@ -152,9 +152,9 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): (1) The ``api_endpoint`` property can be used to override the default endpoint provided by the client. GOOGLE_API_USE_MTLS environment variable can also be used to override the endpoint: - "Always" (always use the default mTLS endpoint), "Never" (always + "always" (always use the default mTLS endpoint), "never" (always use the default regular endpoint, this is the default value for - the environment variable) and "Auto" (auto switch to the default + the environment variable) and "auto" (auto switch to the default mTLS endpoint if client SSL credentials is present). However, the ``api_endpoint`` property takes precedence if provided. (2) The ``client_cert_source`` property is used to provide client @@ -171,12 +171,12 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): client_options = ClientOptions.ClientOptions() if transport is None and client_options.api_endpoint is None: - use_mtls_env = os.getenv("GOOGLE_API_USE_MTLS", "Never") - if use_mtls_env == "Never": + use_mtls_env = os.getenv("GOOGLE_API_USE_MTLS", "never") + if use_mtls_env == "never": client_options.api_endpoint = self.DEFAULT_ENDPOINT - elif use_mtls_env == "Always": + elif use_mtls_env == "always": client_options.api_endpoint = self.DEFAULT_MTLS_ENDPOINT - elif use_mtls_env == "Auto": + elif use_mtls_env == "auto": has_client_cert_source = ( client_options.client_cert_source is not None or mtls.has_default_client_cert_source() diff --git a/gapic/ads-templates/tests/unit/%name_%version/%sub/test_%service.py.j2 b/gapic/ads-templates/tests/unit/%name_%version/%sub/test_%service.py.j2 index c5a9561bfc..79d420da82 100644 --- a/gapic/ads-templates/tests/unit/%name_%version/%sub/test_%service.py.j2 +++ b/gapic/ads-templates/tests/unit/%name_%version/%sub/test_%service.py.j2 @@ -100,8 +100,8 @@ def test_{{ service.client_name|snake_case }}_client_options(): ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS is - # "Never". - os.environ["GOOGLE_API_USE_MTLS"] = "Never" + # "never". + os.environ["GOOGLE_API_USE_MTLS"] = "never" with mock.patch('{{ (api.naming.module_namespace + (api.naming.versioned_module_name,) + service.meta.address.subpackage)|join(".") }}.services.{{ service.name|snake_case }}.transports.{{ service.name }}GrpcTransport.__init__') as grpc_transport: grpc_transport.return_value = None client = {{ service.client_name }}() @@ -113,8 +113,8 @@ def test_{{ service.client_name|snake_case }}_client_options(): ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS is - # "Always". - os.environ["GOOGLE_API_USE_MTLS"] = "Always" + # "always". + os.environ["GOOGLE_API_USE_MTLS"] = "always" with mock.patch('{{ (api.naming.module_namespace + (api.naming.versioned_module_name,) + service.meta.address.subpackage)|join(".") }}.services.{{ service.name|snake_case }}.transports.{{ service.name }}GrpcTransport.__init__') as grpc_transport: grpc_transport.return_value = None client = {{ service.client_name }}() @@ -126,8 +126,8 @@ def test_{{ service.client_name|snake_case }}_client_options(): ) # Check the case api_endpoint is not provided, GOOGLE_API_USE_MTLS is - # "Auto", and client_cert_source is provided. - os.environ["GOOGLE_API_USE_MTLS"] = "Auto" + # "auto", and client_cert_source is provided. + os.environ["GOOGLE_API_USE_MTLS"] = "auto" options = client_options.ClientOptions(client_cert_source=client_cert_source_callback) with mock.patch('{{ (api.naming.module_namespace + (api.naming.versioned_module_name,) + service.meta.address.subpackage)|join(".") }}.services.{{ service.name|snake_case }}.transports.{{ service.name }}GrpcTransport.__init__') as grpc_transport: grpc_transport.return_value = None @@ -140,8 +140,8 @@ def test_{{ service.client_name|snake_case }}_client_options(): ) # Check the case api_endpoint is not provided, GOOGLE_API_USE_MTLS is - # "Auto", and default_client_cert_source is provided. - os.environ["GOOGLE_API_USE_MTLS"] = "Auto" + # "auto", and default_client_cert_source is provided. + os.environ["GOOGLE_API_USE_MTLS"] = "auto" with mock.patch('{{ (api.naming.module_namespace + (api.naming.versioned_module_name,) + service.meta.address.subpackage)|join(".") }}.services.{{ service.name|snake_case }}.transports.{{ service.name }}GrpcTransport.__init__') as grpc_transport: with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=True): grpc_transport.return_value = None @@ -154,8 +154,8 @@ def test_{{ service.client_name|snake_case }}_client_options(): ) # Check the case api_endpoint is not provided, GOOGLE_API_USE_MTLS is - # "Auto", but client_cert_source and default_client_cert_source are None. - os.environ["GOOGLE_API_USE_MTLS"] = "Auto" + # "auto", but client_cert_source and default_client_cert_source are None. + os.environ["GOOGLE_API_USE_MTLS"] = "auto" with mock.patch('{{ (api.naming.module_namespace + (api.naming.versioned_module_name,) + service.meta.address.subpackage)|join(".") }}.services.{{ service.name|snake_case }}.transports.{{ service.name }}GrpcTransport.__init__') as grpc_transport: with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=False): grpc_transport.return_value = None diff --git a/gapic/templates/%namespace/%name_%version/%sub/services/%service/client.py.j2 b/gapic/templates/%namespace/%name_%version/%sub/services/%service/client.py.j2 index 0d765b5533..16c3359d00 100644 --- a/gapic/templates/%namespace/%name_%version/%sub/services/%service/client.py.j2 +++ b/gapic/templates/%namespace/%name_%version/%sub/services/%service/client.py.j2 @@ -152,9 +152,9 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): (1) The ``api_endpoint`` property can be used to override the default endpoint provided by the client. GOOGLE_API_USE_MTLS environment variable can also be used to override the endpoint: - "Always" (always use the default mTLS endpoint), "Never" (always + "always" (always use the default mTLS endpoint), "never" (always use the default regular endpoint, this is the default value for - the environment variable) and "Auto" (auto switch to the default + the environment variable) and "auto" (auto switch to the default mTLS endpoint if client SSL credentials is present). However, the ``api_endpoint`` property takes precedence if provided. (2) The ``client_cert_source`` property is used to provide client @@ -171,12 +171,12 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): client_options = ClientOptions.ClientOptions() if transport is None and client_options.api_endpoint is None: - use_mtls_env = os.getenv("GOOGLE_API_USE_MTLS", "Never") - if use_mtls_env == "Never": + use_mtls_env = os.getenv("GOOGLE_API_USE_MTLS", "never") + if use_mtls_env == "never": client_options.api_endpoint = self.DEFAULT_ENDPOINT - elif use_mtls_env == "Always": + elif use_mtls_env == "always": client_options.api_endpoint = self.DEFAULT_MTLS_ENDPOINT - elif use_mtls_env == "Auto": + elif use_mtls_env == "auto": has_client_cert_source = ( client_options.client_cert_source is not None or mtls.has_default_client_cert_source() diff --git a/gapic/templates/tests/unit/%name_%version/%sub/test_%service.py.j2 b/gapic/templates/tests/unit/%name_%version/%sub/test_%service.py.j2 index c5a9561bfc..79d420da82 100644 --- a/gapic/templates/tests/unit/%name_%version/%sub/test_%service.py.j2 +++ b/gapic/templates/tests/unit/%name_%version/%sub/test_%service.py.j2 @@ -100,8 +100,8 @@ def test_{{ service.client_name|snake_case }}_client_options(): ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS is - # "Never". - os.environ["GOOGLE_API_USE_MTLS"] = "Never" + # "never". + os.environ["GOOGLE_API_USE_MTLS"] = "never" with mock.patch('{{ (api.naming.module_namespace + (api.naming.versioned_module_name,) + service.meta.address.subpackage)|join(".") }}.services.{{ service.name|snake_case }}.transports.{{ service.name }}GrpcTransport.__init__') as grpc_transport: grpc_transport.return_value = None client = {{ service.client_name }}() @@ -113,8 +113,8 @@ def test_{{ service.client_name|snake_case }}_client_options(): ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS is - # "Always". - os.environ["GOOGLE_API_USE_MTLS"] = "Always" + # "always". + os.environ["GOOGLE_API_USE_MTLS"] = "always" with mock.patch('{{ (api.naming.module_namespace + (api.naming.versioned_module_name,) + service.meta.address.subpackage)|join(".") }}.services.{{ service.name|snake_case }}.transports.{{ service.name }}GrpcTransport.__init__') as grpc_transport: grpc_transport.return_value = None client = {{ service.client_name }}() @@ -126,8 +126,8 @@ def test_{{ service.client_name|snake_case }}_client_options(): ) # Check the case api_endpoint is not provided, GOOGLE_API_USE_MTLS is - # "Auto", and client_cert_source is provided. - os.environ["GOOGLE_API_USE_MTLS"] = "Auto" + # "auto", and client_cert_source is provided. + os.environ["GOOGLE_API_USE_MTLS"] = "auto" options = client_options.ClientOptions(client_cert_source=client_cert_source_callback) with mock.patch('{{ (api.naming.module_namespace + (api.naming.versioned_module_name,) + service.meta.address.subpackage)|join(".") }}.services.{{ service.name|snake_case }}.transports.{{ service.name }}GrpcTransport.__init__') as grpc_transport: grpc_transport.return_value = None @@ -140,8 +140,8 @@ def test_{{ service.client_name|snake_case }}_client_options(): ) # Check the case api_endpoint is not provided, GOOGLE_API_USE_MTLS is - # "Auto", and default_client_cert_source is provided. - os.environ["GOOGLE_API_USE_MTLS"] = "Auto" + # "auto", and default_client_cert_source is provided. + os.environ["GOOGLE_API_USE_MTLS"] = "auto" with mock.patch('{{ (api.naming.module_namespace + (api.naming.versioned_module_name,) + service.meta.address.subpackage)|join(".") }}.services.{{ service.name|snake_case }}.transports.{{ service.name }}GrpcTransport.__init__') as grpc_transport: with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=True): grpc_transport.return_value = None @@ -154,8 +154,8 @@ def test_{{ service.client_name|snake_case }}_client_options(): ) # Check the case api_endpoint is not provided, GOOGLE_API_USE_MTLS is - # "Auto", but client_cert_source and default_client_cert_source are None. - os.environ["GOOGLE_API_USE_MTLS"] = "Auto" + # "auto", but client_cert_source and default_client_cert_source are None. + os.environ["GOOGLE_API_USE_MTLS"] = "auto" with mock.patch('{{ (api.naming.module_namespace + (api.naming.versioned_module_name,) + service.meta.address.subpackage)|join(".") }}.services.{{ service.name|snake_case }}.transports.{{ service.name }}GrpcTransport.__init__') as grpc_transport: with mock.patch('google.auth.transport.mtls.has_default_client_cert_source', return_value=False): grpc_transport.return_value = None