4848from google .cloud .spanner_v1 import __version__
4949from google .cloud .spanner_v1 import ExecuteSqlRequest
5050from google .cloud .spanner_v1 import DefaultTransactionOptions
51- from google .cloud .spanner_v1 ._helpers import _merge_query_options
51+ from google .cloud .spanner_v1 ._helpers import (
52+ _create_experimental_host_transport ,
53+ _merge_query_options ,
54+ )
5255from google .cloud .spanner_v1 ._helpers import _metadata_with_prefix
5356from google .cloud .spanner_v1 .instance import Instance
5457from google .cloud .spanner_v1 .metrics .constants import (
@@ -186,6 +189,30 @@ class Client(ClientWithProject):
186189
187190 :raises: :class:`ValueError <exceptions.ValueError>` if both ``read_only``
188191 and ``admin`` are :data:`True`
192+
193+ :type use_plain_text: bool
194+ :param use_plain_text: (Optional) Whether to use plain text for the connection.
195+ This is intended only for experimental host spanner endpoints.
196+ If set, this will override the `api_endpoint` in `client_options`.
197+ If not set, the default behavior is to use TLS.
198+
199+ :type ca_certificate: str
200+ :param ca_certificate: (Optional) The path to the CA certificate file used for TLS connection.
201+ This is intended only for experimental host spanner endpoints.
202+ If set, this will override the `api_endpoint` in `client_options`.
203+ This is mandatory if the experimental_host requires a TLS connection.
204+
205+ :type client_certificate: str
206+ :param client_certificate: (Optional) The path to the client certificate file used for mTLS connection.
207+ This is intended only for experimental host spanner endpoints.
208+ If set, this will override the `api_endpoint` in `client_options`.
209+ This is mandatory if the experimental_host requires a mTLS connection.
210+
211+ :type client_key: str
212+ :param client_key: (Optional) The path to the client key file used for mTLS connection.
213+ This is intended only for experimental host spanner endpoints.
214+ If set, this will override the `api_endpoint` in `client_options`.
215+ This is mandatory if the experimental_host requires a mTLS connection.
189216 """
190217
191218 _instance_admin_api = None
@@ -210,6 +237,10 @@ def __init__(
210237 default_transaction_options : Optional [DefaultTransactionOptions ] = None ,
211238 experimental_host = None ,
212239 disable_builtin_metrics = False ,
240+ use_plain_text = False ,
241+ ca_certificate = None ,
242+ client_certificate = None ,
243+ client_key = None ,
213244 ):
214245 self ._emulator_host = _get_spanner_emulator_host ()
215246 self ._experimental_host = experimental_host
@@ -224,6 +255,12 @@ def __init__(
224255 if self ._emulator_host :
225256 credentials = AnonymousCredentials ()
226257 elif self ._experimental_host :
258+ # For all experimental host endpoints project is default
259+ project = "default"
260+ self ._use_plain_text = use_plain_text
261+ self ._ca_certificate = ca_certificate
262+ self ._client_certificate = client_certificate
263+ self ._client_key = client_key
227264 credentials = AnonymousCredentials ()
228265 elif isinstance (credentials , AnonymousCredentials ):
229266 self ._emulator_host = self ._client_options .api_endpoint
@@ -259,7 +296,7 @@ def __init__(
259296 ):
260297 meter_provider = metrics .NoOpMeterProvider ()
261298 try :
262- if not _get_spanner_emulator_host ():
299+ if not _get_spanner_emulator_host () and not self . _experimental_host :
263300 meter_provider = MeterProvider (
264301 metric_readers = [
265302 PeriodicExportingMetricReader (
@@ -339,8 +376,13 @@ def instance_admin_api(self):
339376 transport = transport ,
340377 )
341378 elif self ._experimental_host :
342- transport = InstanceAdminGrpcTransport (
343- channel = grpc .insecure_channel (target = self ._experimental_host )
379+ transport = _create_experimental_host_transport (
380+ InstanceAdminGrpcTransport ,
381+ self ._experimental_host ,
382+ self ._use_plain_text ,
383+ self ._ca_certificate ,
384+ self ._client_certificate ,
385+ self ._client_key ,
344386 )
345387 self ._instance_admin_api = InstanceAdminClient (
346388 client_info = self ._client_info ,
@@ -369,8 +411,13 @@ def database_admin_api(self):
369411 transport = transport ,
370412 )
371413 elif self ._experimental_host :
372- transport = DatabaseAdminGrpcTransport (
373- channel = grpc .insecure_channel (target = self ._experimental_host )
414+ transport = _create_experimental_host_transport (
415+ DatabaseAdminGrpcTransport ,
416+ self ._experimental_host ,
417+ self ._use_plain_text ,
418+ self ._ca_certificate ,
419+ self ._client_certificate ,
420+ self ._client_key ,
374421 )
375422 self ._database_admin_api = DatabaseAdminClient (
376423 client_info = self ._client_info ,
@@ -517,7 +564,6 @@ def instance(
517564 self ._emulator_host ,
518565 labels ,
519566 processing_units ,
520- self ._experimental_host ,
521567 )
522568
523569 def list_instances (self , filter_ = "" , page_size = None ):
0 commit comments