def spanner_api(self): """Helper for session-related API calls.""" if self._spanner_api is None: client_info = self._instance._client._client_info client_options = self._instance._client._client_options if self._instance.emulator_host is not None: transport = spanner_grpc_transport.SpannerGrpcTransport( channel=grpc.insecure_channel( self._instance.emulator_host)) self._spanner_api = SpannerClient( client_info=client_info, client_options=client_options, transport=transport, ) return self._spanner_api credentials = self._instance._client.credentials if isinstance(credentials, google.auth.credentials.Scoped): credentials = credentials.with_scopes((SPANNER_DATA_SCOPE, )) if (os.getenv("GOOGLE_CLOUD_SPANNER_ENABLE_RESOURCE_BASED_ROUTING") == "true"): endpoint_cache = self._instance._client._endpoint_cache if self._instance.name in endpoint_cache: client_options = ClientOptions( api_endpoint=endpoint_cache[self._instance.name]) else: try: api = self._instance._client.instance_admin_api resp = api.get_instance( self._instance.name, field_mask={"paths": ["endpoint_uris"]}, metadata=_metadata_with_prefix(self.name), ) endpoints = resp.endpoint_uris if endpoints: endpoint_cache[self._instance.name] = list( endpoints)[0] client_options = ClientOptions( api_endpoint=endpoint_cache[ self._instance.name]) # If there are no endpoints, use default endpoint. except PermissionDenied: warnings.warn( _RESOURCE_ROUTING_PERMISSIONS_WARNING, ResourceRoutingPermissionsWarning, stacklevel=2, ) self._spanner_api = SpannerClient( credentials=credentials, client_info=client_info, client_options=client_options, ) return self._spanner_api
def spanner_api(self): """Helper for session-related API calls.""" if self._spanner_api is None: credentials = self._instance._client.credentials if isinstance(credentials, google.auth.credentials.Scoped): credentials = credentials.with_scopes((SPANNER_DATA_SCOPE, )) self._spanner_api = SpannerClient(credentials=credentials, client_info=_CLIENT_INFO) return self._spanner_api
def spanner_api(self): """Helper for session-related API calls.""" if self._spanner_api is None: credentials = self._instance._client.credentials if isinstance(credentials, google.auth.credentials.Scoped): credentials = credentials.with_scopes((SPANNER_DATA_SCOPE, )) self._spanner_api = SpannerClient( lib_name='gccl', lib_version=__version__, credentials=credentials, ) return self._spanner_api
def spanner_api(self): """Helper for session-related API calls.""" if self._spanner_api is None: client_info = self._instance._client._client_info client_options = self._instance._client._client_options if self._instance.emulator_host is not None: transport = spanner_grpc_transport.SpannerGrpcTransport( channel=grpc.insecure_channel( self._instance.emulator_host)) self._spanner_api = SpannerClient(client_info=client_info, transport=transport) return self._spanner_api credentials = self._instance._client.credentials if isinstance(credentials, google.auth.credentials.Scoped): credentials = credentials.with_scopes((SPANNER_DATA_SCOPE, )) self._spanner_api = SpannerClient( credentials=credentials, client_info=client_info, client_options=client_options, ) return self._spanner_api