|
|
@ -40,9 +40,10 @@ def _create_get_token_callback(callback): |
|
|
|
class GoogleCallCredentials(grpc.AuthMetadataPlugin): |
|
|
|
class GoogleCallCredentials(grpc.AuthMetadataPlugin): |
|
|
|
"""Metadata wrapper for GoogleCredentials from the oauth2client library.""" |
|
|
|
"""Metadata wrapper for GoogleCredentials from the oauth2client library.""" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_THREAD_POOL = futures.ThreadPoolExecutor() |
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, credentials): |
|
|
|
def __init__(self, credentials): |
|
|
|
self._credentials = credentials |
|
|
|
self._credentials = credentials |
|
|
|
self._pool = futures.ThreadPoolExecutor(max_workers=1) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Hack to determine if these are JWT creds and we need to pass |
|
|
|
# Hack to determine if these are JWT creds and we need to pass |
|
|
|
# additional_claims when getting a token |
|
|
|
# additional_claims when getting a token |
|
|
@ -52,16 +53,14 @@ class GoogleCallCredentials(grpc.AuthMetadataPlugin): |
|
|
|
def __call__(self, context, callback): |
|
|
|
def __call__(self, context, callback): |
|
|
|
# MetadataPlugins cannot block (see grpc.beta.interfaces.py) |
|
|
|
# MetadataPlugins cannot block (see grpc.beta.interfaces.py) |
|
|
|
if self._is_jwt: |
|
|
|
if self._is_jwt: |
|
|
|
future = self._pool.submit( |
|
|
|
future = self._THREAD_POOL.submit( |
|
|
|
self._credentials.get_access_token, |
|
|
|
self._credentials.get_access_token, |
|
|
|
additional_claims={'aud': context.service_url}) |
|
|
|
additional_claims={'aud': context.service_url}) |
|
|
|
else: |
|
|
|
else: |
|
|
|
future = self._pool.submit(self._credentials.get_access_token) |
|
|
|
future = self._THREAD_POOL.submit( |
|
|
|
|
|
|
|
self._credentials.get_access_token) |
|
|
|
future.add_done_callback(_create_get_token_callback(callback)) |
|
|
|
future.add_done_callback(_create_get_token_callback(callback)) |
|
|
|
|
|
|
|
|
|
|
|
def __del__(self): |
|
|
|
|
|
|
|
self._pool.shutdown(wait=False) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AccessTokenAuthMetadataPlugin(grpc.AuthMetadataPlugin): |
|
|
|
class AccessTokenAuthMetadataPlugin(grpc.AuthMetadataPlugin): |
|
|
|
"""Metadata wrapper for raw access token credentials.""" |
|
|
|
"""Metadata wrapper for raw access token credentials.""" |
|
|
|