11{% extends '_base.py.j2' %}
22
33{% block content %}
4- from typing import Callable, Dict, Tuple
4+ from typing import Callable, Dict, Tuple, Sequence
55
66from google.api_core import grpc_helpers # type: ignore
77{% - if service .has_lro %}
@@ -38,6 +38,8 @@ class {{ service.name }}GrpcTransport({{ service.name }}Transport):
3838 def __init__(self, *,
3939 host: str{% if service .host %} = '{{ service.host }}'{% endif %} ,
4040 credentials: credentials.Credentials = None,
41+ credentials_file: str = None,
42+ scopes: Sequence[str] = None,
4143 channel: grpc.Channel = None,
4244 api_mtls_endpoint: str = None,
4345 client_cert_source: Callable[[], Tuple[bytes, bytes]] = None) -> None:
@@ -52,6 +54,11 @@ class {{ service.name }}GrpcTransport({{ service.name }}Transport):
5254 are specified, the client will attempt to ascertain the
5355 credentials from the environment.
5456 This argument is ignored if ``channel`` is provided.
57+ credentials_file (Optional[str]): A file with credentials that can
58+ be loaded with :func:`google.auth.load_credentials_from_file`.
59+ This argument is ignored if ``channel`` is provided.
60+ scopes (Optional(Sequence[str])): A list of scopes. This argument is
61+ ignored if ``channel`` is provided.
5562 channel (Optional[grpc.Channel]): A ``Channel`` instance through
5663 which to make calls.
5764 api_mtls_endpoint (Optional[str]): The mutual TLS endpoint. If
@@ -66,6 +73,7 @@ class {{ service.name }}GrpcTransport({{ service.name }}Transport):
6673 Raises:
6774 google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
6875 creation failed for any reason.
76+ ValueError: If both ``credentials`` and ``credentials_file`` are passed.
6977 """
7078 if channel:
7179 # Sanity check: Ensure that channel and credentials are not both
@@ -94,19 +102,22 @@ class {{ service.name }}GrpcTransport({{ service.name }}Transport):
94102 self._grpc_channel = grpc_helpers.create_channel(
95103 host,
96104 credentials=credentials,
105+ credentials_file=credentials_file,
97106 ssl_credentials=ssl_credentials,
98- scopes=self.AUTH_SCOPES,
107+ scopes=scopes or self.AUTH_SCOPES,
99108 )
100109
101110 # Run the base constructor.
102- super().__init__(host=host, credentials=credentials)
111+ super().__init__(host=host, credentials=credentials, credentials_file=credentials_file, scopes=scopes )
103112 self._stubs = {} # type: Dict[str, Callable]
104113
105114
106115 @classmethod
107116 def create_channel(cls,
108117 host: str{% if service .host %} = '{{ service.host }}'{% endif %} ,
109118 credentials: credentials.Credentials = None,
119+ credentials_file: str = None,
120+ scopes: Sequence[str] = None,
110121 **kwargs) -> grpc.Channel:
111122 """Create and return a gRPC channel object.
112123 Args:
@@ -116,15 +127,23 @@ class {{ service.name }}GrpcTransport({{ service.name }}Transport):
116127 credentials identify this application to the service. If
117128 none are specified, the client will attempt to ascertain
118129 the credentials from the environment.
130+ credentials_file (Optional[str]): A file with credentials that can
131+ be loaded with :func:`google.auth.load_credentials_from_file`.
132+ This argument is mutually exclusive with credentials.
133+ scopes (Optional(Sequence[str])): A list of scopes.
119134 kwargs (Optional[dict]): Keyword arguments, which are passed to the
120135 channel creation.
121136 Returns:
122137 grpc.Channel: A gRPC channel object.
138+
139+ Raises:
140+ ValueError: If both ``credentials`` and ``credentials_file`` are passed.
123141 """
124142 return grpc_helpers.create_channel(
125143 host,
126144 credentials=credentials,
127- scopes=cls.AUTH_SCOPES,
145+ credentials_file=credentials_file,
146+ scopes=scopes or cls.AUTH_SCOPES,
128147 **kwargs
129148 )
130149
0 commit comments