Skip to content
This repository was archived by the owner on Mar 26, 2026. It is now read-only.

Commit 3cb8e92

Browse files
committed
handle none case in _get_default_mtls_endpoint
1 parent e476732 commit 3cb8e92

3 files changed

Lines changed: 9 additions & 0 deletions

File tree

gapic/ads-templates/%namespace/%name/%version/%sub/services/%service/client.py.j2

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta):
118118
)
119119

120120
m = mtls_endpoint_re.match(api_endpoint)
121+
if m is None:
122+
# could not parse api_endpoint; return as-is
123+
return api_endpoint
121124
name, mtls, sandbox, googledomain = m.groups()
122125
if mtls or not googledomain:
123126
return api_endpoint

gapic/templates/%namespace/%name_%version/%sub/services/%service/client.py.j2

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta):
161161
)
162162

163163
m = mtls_endpoint_re.match(api_endpoint)
164+
if m is None:
165+
# could not parse api_endpoint; return as-is
166+
return api_endpoint
167+
164168
name, mtls, sandbox, googledomain = m.groups()
165169
if mtls or not googledomain:
166170
return api_endpoint

gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,15 @@ def test__get_default_mtls_endpoint():
146146
sandbox_endpoint = "example.sandbox.googleapis.com"
147147
sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com"
148148
non_googleapi = "api.example.com"
149+
custom_endpoint = ".custom"
149150

150151
assert {{ service.client_name }}._get_default_mtls_endpoint(None) is None
151152
assert {{ service.client_name }}._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint
152153
assert {{ service.client_name }}._get_default_mtls_endpoint(api_mtls_endpoint) == api_mtls_endpoint
153154
assert {{ service.client_name }}._get_default_mtls_endpoint(sandbox_endpoint) == sandbox_mtls_endpoint
154155
assert {{ service.client_name }}._get_default_mtls_endpoint(sandbox_mtls_endpoint) == sandbox_mtls_endpoint
155156
assert {{ service.client_name }}._get_default_mtls_endpoint(non_googleapi) == non_googleapi
157+
assert {{ service.client_name }}._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint
156158

157159
def test__read_environment_variables():
158160
assert {{ service.client_name }}._read_environment_variables() == (False, "auto", None)

0 commit comments

Comments
 (0)