Override the auth plugin behavior

pull/22343/head
Lidi Zheng 5 years ago
parent 030b1b6a84
commit 46bb3769a9
  1. 11
      src/python/grpcio/grpc/_cython/_cygrpc/aio/iomgr/iomgr.pyx.pxi
  2. 14
      src/python/grpcio/grpc/_cython/_cygrpc/credentials.pyx.pxi
  3. 2
      src/python/grpcio_tests/tests_aio/unit/secure_call_test.py

@ -212,7 +212,18 @@ cdef void asyncio_run_loop(size_t timeout_ms) with gil:
pass pass
def _auth_plugin_callback_wrapper(object cb,
str service_url,
str method_name,
object callback):
asyncio.get_event_loop().call_soon(cb, service_url, method_name, callback)
def install_asyncio_iomgr(): def install_asyncio_iomgr():
# Auth plugins invoke user provided logic in another thread by default. We
# need to override that behavior by registering the call to the event loop.
set_async_callback_func(_auth_plugin_callback_wrapper)
asyncio_resolver_vtable.resolve = asyncio_resolve asyncio_resolver_vtable.resolve = asyncio_resolve
asyncio_resolver_vtable.resolve_async = asyncio_resolve_async asyncio_resolver_vtable.resolve_async = asyncio_resolve_async

@ -34,12 +34,14 @@ cdef class CallCredentials:
raise NotImplementedError() raise NotImplementedError()
cdef int _get_metadata( cdef int _get_metadata(void *state,
void *state, grpc_auth_metadata_context context, grpc_auth_metadata_context context,
grpc_credentials_plugin_metadata_cb cb, void *user_data, grpc_credentials_plugin_metadata_cb cb,
grpc_metadata creds_md[GRPC_METADATA_CREDENTIALS_PLUGIN_SYNC_MAX], void *user_data,
size_t *num_creds_md, grpc_status_code *status, grpc_metadata creds_md[GRPC_METADATA_CREDENTIALS_PLUGIN_SYNC_MAX],
const char **error_details) except * with gil: size_t *num_creds_md,
grpc_status_code *status,
const char **error_details) except * with gil:
cdef size_t metadata_count cdef size_t metadata_count
cdef grpc_metadata *c_metadata cdef grpc_metadata *c_metadata
def callback(metadata, grpc_status_code status, bytes error_details): def callback(metadata, grpc_status_code status, bytes error_details):

@ -126,5 +126,5 @@ class TestStreamStreamSecureCall(_SecureCallMixin, AioTestBase):
if __name__ == '__main__': if __name__ == '__main__':
logging.basicConfig() logging.basicConfig(level=logging.DEBUG)
unittest.main(verbosity=2) unittest.main(verbosity=2)

Loading…
Cancel
Save