@@ -148,7 +148,7 @@ def _firestore_api_helper(self, transport, client_class, client_module) -> Any:
148
148
# We need this in order to set appropriate keepalive options.
149
149
150
150
if self ._emulator_host is not None :
151
- channel = self ._emulator_channel ()
151
+ channel = self ._emulator_channel (transport )
152
152
else :
153
153
channel = transport .create_channel (
154
154
self ._target ,
@@ -165,25 +165,30 @@ def _firestore_api_helper(self, transport, client_class, client_module) -> Any:
165
165
166
166
return self ._firestore_api_internal
167
167
168
- def _emulator_channel (self ):
168
+ def _emulator_channel (self , transport ):
169
169
"""
170
170
Creates a channel using self._credentials in a similar way to grpc.secure_channel but
171
171
using grpc.local_channel_credentials() rather than grpc.ssh_channel_credentials() to allow easy connection
172
172
to a local firestore emulator. This allows local testing of firestore rules if the credentials have been
173
173
created from a signed custom token.
174
174
175
- :return: grcp .Channel
175
+ :return: grpc.Channel or grpc.aio .Channel
176
176
"""
177
- return grpc ._channel .Channel (
178
- self ._emulator_host ,
179
- (),
180
- self ._local_composite_credentials ()._credentials ,
181
- None ,
182
- )
177
+ # TODO: Implement a special credentials type for emulator and use
178
+ # "transport.create_channel" to create gRPC channels once google-auth
179
+ # extends it's allowed credentials types.
180
+ if "GrpcAsyncIOTransport" in str (transport .__name__ ):
181
+ return grpc .aio .secure_channel (
182
+ self ._emulator_host , self ._local_composite_credentials ()
183
+ )
184
+ else :
185
+ return grpc .secure_channel (
186
+ self ._emulator_host , self ._local_composite_credentials ()
187
+ )
183
188
184
189
def _local_composite_credentials (self ):
185
190
"""
186
- Ceates the credentials for the local emulator channel
191
+ Creates the credentials for the local emulator channel
187
192
:return: grpc.ChannelCredentials
188
193
"""
189
194
credentials = google .auth .credentials .with_scopes_if_required (
0 commit comments