2929
3030from pkg_resources import get_distribution
3131
32- from grpc . beta import implementations
32+ from gcloud . _helpers import make_stub
3333
3434from gcloud .bigtable ._generated import (
3535 bigtable_instance_admin_pb2 as instance_admin_v2_pb2 )
@@ -284,17 +284,19 @@ def _make_data_stub(self):
284284 :rtype: :class:`grpc.beta._stub._AutoIntermediary`
285285 :returns: A gRPC stub object.
286286 """
287- return _make_stub (self , DATA_STUB_FACTORY_V2 ,
288- DATA_API_HOST_V2 , DATA_API_PORT_V2 )
287+ return make_stub (self .credentials , self .user_agent ,
288+ DATA_STUB_FACTORY_V2 , DATA_API_HOST_V2 ,
289+ DATA_API_PORT_V2 )
289290
290291 def _make_instance_stub (self ):
291292 """Creates gRPC stub to make requests to the Instance Admin API.
292293
293294 :rtype: :class:`grpc.beta._stub._AutoIntermediary`
294295 :returns: A gRPC stub object.
295296 """
296- return _make_stub (self , INSTANCE_STUB_FACTORY_V2 ,
297- INSTANCE_ADMIN_HOST_V2 , INSTANCE_ADMIN_PORT_V2 )
297+ return make_stub (self .credentials , self .user_agent ,
298+ INSTANCE_STUB_FACTORY_V2 , INSTANCE_ADMIN_HOST_V2 ,
299+ INSTANCE_ADMIN_PORT_V2 )
298300
299301 def _make_operations_stub (self ):
300302 """Creates gRPC stub to make requests to the Operations API.
@@ -305,17 +307,19 @@ def _make_operations_stub(self):
305307 :rtype: :class:`grpc.beta._stub._AutoIntermediary`
306308 :returns: A gRPC stub object.
307309 """
308- return _make_stub (self , OPERATIONS_STUB_FACTORY_V2 ,
309- OPERATIONS_API_HOST_V2 , OPERATIONS_API_PORT_V2 )
310+ return make_stub (self .credentials , self .user_agent ,
311+ OPERATIONS_STUB_FACTORY_V2 , OPERATIONS_API_HOST_V2 ,
312+ OPERATIONS_API_PORT_V2 )
310313
311314 def _make_table_stub (self ):
312315 """Creates gRPC stub to make requests to the Table Admin API.
313316
314317 :rtype: :class:`grpc.beta._stub._AutoIntermediary`
315318 :returns: A gRPC stub object.
316319 """
317- return _make_stub (self , TABLE_STUB_FACTORY_V2 ,
318- TABLE_ADMIN_HOST_V2 , TABLE_ADMIN_PORT_V2 )
320+ return make_stub (self .credentials , self .user_agent ,
321+ TABLE_STUB_FACTORY_V2 , TABLE_ADMIN_HOST_V2 ,
322+ TABLE_ADMIN_PORT_V2 )
319323
320324 def is_started (self ):
321325 """Check if the client has been started.
@@ -422,59 +426,3 @@ def list_instances(self):
422426 instances = [Instance .from_pb (instance_pb , self )
423427 for instance_pb in response .instances ]
424428 return instances , response .failed_locations
425-
426-
427- class _MetadataPlugin (object ):
428- """Callable class to transform metadata for gRPC requests.
429-
430- :type client: :class:`.client.Client`
431- :param client: The client that owns the instance.
432- Provides authorization and user agent.
433- """
434-
435- def __init__ (self , client ):
436- self ._credentials = client .credentials
437- self ._user_agent = client .user_agent
438-
439- def __call__ (self , unused_context , callback ):
440- """Adds authorization header to request metadata."""
441- access_token = self ._credentials .get_access_token ().access_token
442- headers = [
443- ('Authorization' , 'Bearer ' + access_token ),
444- ('User-agent' , self ._user_agent ),
445- ]
446- callback (headers , None )
447-
448-
449- def _make_stub (client , stub_factory , host , port ):
450- """Makes a stub for an RPC service.
451-
452- Uses / depends on the beta implementation of gRPC.
453-
454- :type client: :class:`.client.Client`
455- :param client: The client that owns the instance.
456- Provides authorization and user agent.
457-
458- :type stub_factory: callable
459- :param stub_factory: A factory which will create a gRPC stub for
460- a given service.
461-
462- :type host: str
463- :param host: The host for the service.
464-
465- :type port: int
466- :param port: The port for the service.
467-
468- :rtype: :class:`grpc.beta._stub._AutoIntermediary`
469- :returns: The stub object used to make gRPC requests to a given API.
470- """
471- # Leaving the first argument to ssl_channel_credentials() as None
472- # loads root certificates from `grpc/_adapter/credentials/roots.pem`.
473- transport_creds = implementations .ssl_channel_credentials (None , None , None )
474- custom_metadata_plugin = _MetadataPlugin (client )
475- auth_creds = implementations .metadata_call_credentials (
476- custom_metadata_plugin , name = 'google_creds' )
477- channel_creds = implementations .composite_channel_credentials (
478- transport_creds , auth_creds )
479- channel = implementations .secure_channel (host , port , channel_creds )
480- return stub_factory (channel )
0 commit comments