@@ -40,6 +40,8 @@ class {{ service.name }}GrpcTransport({{ service.name }}Transport):
4040 def __init__(self, *,
4141 host: str{% if service .host %} = '{{ service.host }}'{% endif %} ,
4242 credentials: credentials.Credentials = None,
43+ credentials_file: str = None,
44+ scopes: Sequence[str] = None,
4345 channel: grpc.Channel = None,
4446 api_mtls_endpoint: str = None,
4547 client_cert_source: Callable[[], Tuple[bytes, bytes]] = None) -> None:
@@ -54,6 +56,11 @@ class {{ service.name }}GrpcTransport({{ service.name }}Transport):
5456 are specified, the client will attempt to ascertain the
5557 credentials from the environment.
5658 This argument is ignored if ``channel`` is provided.
59+ credentials_file (Optional[str]): A file with credentials that can
60+ be loaded with :func:`google.auth.load_credentials_from_file`.
61+ This argument is ignored if ``channel`` is provided.
62+ scopes (Optional(Sequence[str])): A list of scopes. This argument is
63+ ignored if ``channel`` is provided.
5764 channel (Optional[grpc.Channel]): A ``Channel`` instance through
5865 which to make calls.
5966 api_mtls_endpoint (Optional[str]): The mutual TLS endpoint. If
@@ -66,8 +73,9 @@ class {{ service.name }}GrpcTransport({{ service.name }}Transport):
6673 is None.
6774
6875 Raises:
69- google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
70- creation failed for any reason.
76+ google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
77+ creation failed for any reason.
78+ ValueError: If both ``credentials`` and ``credentials_file`` are passed.
7179 """
7280 if channel:
7381 # Sanity check: Ensure that channel and credentials are not both
@@ -96,18 +104,20 @@ class {{ service.name }}GrpcTransport({{ service.name }}Transport):
96104 self._grpc_channel = type(self).create_channel(
97105 host,
98106 credentials=credentials,
107+ credentials_file=credentials_file,
99108 ssl_credentials=ssl_credentials,
100- scopes=self.AUTH_SCOPES,
109+ scopes=scopes or self.AUTH_SCOPES,
101110 )
102111
103112 # Run the base constructor.
104- super().__init__(host=host, credentials=credentials)
113+ super().__init__(host=host, credentials=credentials, credentials_file=credentials_file, scopes=scopes )
105114 self._stubs = {} # type: Dict[str, Callable]
106115
107116 @classmethod
108117 def create_channel(cls,
109118 host: str{% if service .host %} = '{{ service.host }}'{% endif %} ,
110119 credentials: credentials.Credentials = None,
120+ credentials_file: str = None,
111121 scopes: Optional[Sequence[str]] = None,
112122 **kwargs) -> grpc.Channel:
113123 """Create and return a gRPC channel object.
@@ -118,18 +128,25 @@ class {{ service.name }}GrpcTransport({{ service.name }}Transport):
118128 credentials identify this application to the service. If
119129 none are specified, the client will attempt to ascertain
120130 the credentials from the environment.
131+ credentials_file (Optional[str]): A file with credentials that can
132+ be loaded with :func:`google.auth.load_credentials_from_file`.
133+ This argument is mutually exclusive with credentials.
121134 scopes (Optional[Sequence[str]]): A optional list of scopes needed for this
122135 service. These are only used when credentials are not specified and
123136 are passed to :func:`google.auth.default`.
124137 kwargs (Optional[dict]): Keyword arguments, which are passed to the
125138 channel creation.
126139 Returns:
127140 grpc.Channel: A gRPC channel object.
141+
142+ Raises:
143+ ValueError: If both ``credentials`` and ``credentials_file`` are passed.
128144 """
129145 scopes = scopes or cls.AUTH_SCOPES
130146 return grpc_helpers.create_channel(
131147 host,
132148 credentials=credentials,
149+ credentials_file=credentials_file,
133150 scopes=scopes,
134151 **kwargs
135152 )
0 commit comments