|
2 | 2 |
|
3 | 3 | {% block content %}
|
4 | 4 | from collections import OrderedDict
|
5 |
| -import re |
6 |
| -from typing import Callable, Dict, {% if service.any_server_streaming %}Iterable, {% endif %}{% if service.any_client_streaming %}Iterator, {% endif %}Sequence, Tuple, Type, Union |
| 5 | +from typing import Dict, {% if service.any_server_streaming %}Iterable, {% endif %}{% if service.any_client_streaming %}Iterator, {% endif %}Sequence, Tuple, Type, Union |
7 | 6 | import pkg_resources
|
8 | 7 |
|
9 | 8 | import google.api_core.client_options as ClientOptions # type: ignore
|
@@ -58,40 +57,7 @@ class {{ service.client_name }}Meta(type):
|
58 | 57 | class {{ service.client_name }}(metaclass={{ service.client_name }}Meta):
|
59 | 58 | """{{ service.meta.doc|rst(width=72, indent=4) }}"""
|
60 | 59 |
|
61 |
| - @staticmethod |
62 |
| - def _get_default_mtls_endpoint(api_endpoint): |
63 |
| - """Convert api endpoint to mTLS endpoint. |
64 |
| - Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to |
65 |
| - "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. |
66 |
| - Args: |
67 |
| - api_endpoint (Optional[str]): the api endpoint to convert. |
68 |
| - Returns: |
69 |
| - str: converted mTLS api endpoint. |
70 |
| - """ |
71 |
| - if not api_endpoint: |
72 |
| - return api_endpoint |
73 |
| - |
74 |
| - mtls_endpoint_re = re.compile( |
75 |
| - r"(?P<name>[^.]+)(?P<mtls>\.mtls)?(?P<sandbox>\.sandbox)?(?P<googledomain>\.googleapis\.com)?" |
76 |
| - ) |
77 |
| - |
78 |
| - m = mtls_endpoint_re.match(api_endpoint) |
79 |
| - name, mtls, sandbox, googledomain = m.groups() |
80 |
| - if mtls or not googledomain: |
81 |
| - return api_endpoint |
82 |
| - |
83 |
| - if sandbox: |
84 |
| - return api_endpoint.replace( |
85 |
| - "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" |
86 |
| - ) |
87 |
| - |
88 |
| - return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") |
89 |
| - |
90 |
| - DEFAULT_ENDPOINT = {% if service.host %}'{{ service.host }}'{% else %}None{% endif %} |
91 |
| - DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore |
92 |
| - DEFAULT_ENDPOINT |
93 |
| - ) |
94 |
| - DEFAULT_OPTIONS = ClientOptions.ClientOptions(api_endpoint=DEFAULT_ENDPOINT) |
| 60 | + DEFAULT_OPTIONS = ClientOptions.ClientOptions({% if service.host %}api_endpoint='{{ service.host }}'{% endif %}) |
95 | 61 |
|
96 | 62 | @classmethod
|
97 | 63 | def from_service_account_file(cls, filename: str, *args, **kwargs):
|
@@ -140,56 +106,23 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta):
|
140 | 106 | transport to use. If set to None, a transport is chosen
|
141 | 107 | automatically.
|
142 | 108 | client_options (ClientOptions): Custom options for the client.
|
143 |
| - (1) The ``api_endpoint`` property can be used to override the |
144 |
| - default endpoint provided by the client. |
145 |
| - (2) If ``transport`` argument is None, ``client_options`` can be |
146 |
| - used to create a mutual TLS transport. If ``api_endpoint`` is |
147 |
| - provided and different from the default endpoint, or the |
148 |
| - ``client_cert_source`` property is provided, mutual TLS |
149 |
| - transport will be created if client SSL credentials are found. |
150 |
| - Client SSL credentials are obtained from ``client_cert_source`` |
151 |
| - or application default SSL credentials. |
152 |
| - |
153 |
| - Raises: |
154 |
| - google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport |
155 |
| - creation failed for any reason. |
156 | 109 | """
|
157 | 110 | if isinstance(client_options, dict):
|
158 | 111 | client_options = ClientOptions.from_dict(client_options)
|
159 | 112 |
|
160 |
| - # Set default api endpoint if not set. |
161 |
| - if client_options.api_endpoint is None: |
162 |
| - client_options.api_endpoint = self.DEFAULT_ENDPOINT |
163 |
| - |
164 | 113 | # Save or instantiate the transport.
|
165 | 114 | # Ordinarily, we provide the transport, but allowing a custom transport
|
166 | 115 | # instance provides an extensibility point for unusual situations.
|
167 | 116 | if isinstance(transport, {{ service.name }}Transport):
|
168 |
| - # transport is a {{ service.name }}Transport instance. |
169 | 117 | if credentials:
|
170 | 118 | raise ValueError('When providing a transport instance, '
|
171 | 119 | 'provide its credentials directly.')
|
172 | 120 | self._transport = transport
|
173 |
| - elif transport is not None or ( |
174 |
| - client_options.api_endpoint == self.DEFAULT_ENDPOINT |
175 |
| - and client_options.client_cert_source is None |
176 |
| - ): |
177 |
| - # Don't trigger mTLS. |
| 121 | + else: |
178 | 122 | Transport = type(self).get_transport_class(transport)
|
179 | 123 | self._transport = Transport(
|
180 |
| - credentials=credentials, host=client_options.api_endpoint |
181 |
| - ) |
182 |
| - else: |
183 |
| - # Trigger mTLS. If the user overrides endpoint, use it as the mTLS |
184 |
| - # endpoint, otherwise use the default mTLS endpoint. |
185 |
| - option_endpoint = client_options.api_endpoint |
186 |
| - api_mtls_endpoint = self.DEFAULT_MTLS_ENDPOINT if option_endpoint == self.DEFAULT_ENDPOINT else option_endpoint |
187 |
| - |
188 |
| - self._transport = {{ service.name }}GrpcTransport( |
189 | 124 | credentials=credentials,
|
190 |
| - host=client_options.api_endpoint, |
191 |
| - api_mtls_endpoint=api_mtls_endpoint, |
192 |
| - client_cert_source=client_options.client_cert_source, |
| 125 | + host=client_options.api_endpoint{% if service.host %} or '{{ service.host }}'{% endif %}, |
193 | 126 | )
|
194 | 127 |
|
195 | 128 | {% for method in service.methods.values() -%}
|
|
0 commit comments