Bandaid over differences in the C API for Python credentials

pull/3765/head
Masood Malekghassemi 9 years ago
parent 36297accb6
commit 7fdfe1afd8
  1. 4
      src/python/grpcio/grpc/_adapter/_intermediary_low.py
  2. 3
      src/python/grpcio/grpc/_adapter/_low.py
  3. 10
      src/python/grpcio/grpc/_adapter/_types.py
  4. 5
      src/python/grpcio/grpc/beta/interfaces.py
  5. 12
      src/python/grpcio_test/grpc_test/beta/_beta_features_test.py

@ -253,10 +253,10 @@ class Server(object):
class ClientCredentials(object):
"""Adapter from old _low.ClientCredentials interface to new _low.ClientCredentials."""
"""Adapter from old _low.ClientCredentials interface to new _low.ChannelCredentials."""
def __init__(self, root_certificates, private_key, certificate_chain):
self._internal = _low.ClientCredentials.ssl(root_certificates, private_key, certificate_chain)
self._internal = _low.ChannelCredentials.ssl(root_certificates, private_key, certificate_chain)
class ServerCredentials(object):

@ -33,7 +33,8 @@ from grpc._adapter import _types
_USER_AGENT = 'Python-gRPC-{}'.format(_grpcio_metadata.__version__)
ClientCredentials = _c.ClientCredentials
ChannelCredentials = _c.ChannelCredentials
CallCredentials = _c.CallCredentials
ServerCredentials = _c.ServerCredentials

@ -323,6 +323,14 @@ class Call:
"""
return None
def set_credentials(self, creds):
"""Set per-call credentials.
Args:
creds (CallCredentials): Credentials to be set for this call.
"""
return None
class Channel:
__metaclass__ = abc.ABCMeta
@ -334,7 +342,7 @@ class Channel:
Args:
target (str): ...
args (sequence of 2-sequence of str, (str|integer)): ...
credentials (ClientCredentials): If None, create an insecure channel,
credentials (ChannelCredentials): If None, create an insecure channel,
else create a secure channel using the client credentials.
"""

@ -100,8 +100,11 @@ def grpc_call_options(disable_compression=False, credentials=None):
disable_compression: A boolean indicating whether or not compression should
be disabled for the request object of the RPC. Only valid for
request-unary RPCs.
credentials: A ClientCredentials object to use for the invoked RPC.
credentials: Reserved for gRPC per-call credentials. The type for this does
not exist yet at the Python level.
"""
if credentials is not None:
raise ValueError('`credentials` is a reserved argument')
return GRPCCallOptions(disable_compression, None, credentials)

@ -181,24 +181,21 @@ class BetaFeaturesTest(unittest.TestCase):
self._server.stop(test_constants.SHORT_TIMEOUT).wait()
def test_unary_unary(self):
call_options = interfaces.grpc_call_options(
disable_compression=True, credentials=self._client_credentials)
call_options = interfaces.grpc_call_options(disable_compression=True)
response = getattr(self._dynamic_stub, _UNARY_UNARY)(
_REQUEST, test_constants.LONG_TIMEOUT, protocol_options=call_options)
self.assertEqual(_RESPONSE, response)
self.assertIsNotNone(self._servicer.peer())
def test_unary_stream(self):
call_options = interfaces.grpc_call_options(
disable_compression=True, credentials=self._client_credentials)
call_options = interfaces.grpc_call_options(disable_compression=True)
response_iterator = getattr(self._dynamic_stub, _UNARY_STREAM)(
_REQUEST, test_constants.LONG_TIMEOUT, protocol_options=call_options)
self._servicer.block_until_serviced()
self.assertIsNotNone(self._servicer.peer())
def test_stream_unary(self):
call_options = interfaces.grpc_call_options(
credentials=self._client_credentials)
call_options = interfaces.grpc_call_options()
request_iterator = _BlockingIterator(iter((_REQUEST,)))
response_future = getattr(self._dynamic_stub, _STREAM_UNARY).future(
request_iterator, test_constants.LONG_TIMEOUT,
@ -212,8 +209,7 @@ class BetaFeaturesTest(unittest.TestCase):
self.assertEqual(_RESPONSE, response_future.result())
def test_stream_stream(self):
call_options = interfaces.grpc_call_options(
credentials=self._client_credentials)
call_options = interfaces.grpc_call_options()
request_iterator = _BlockingIterator(iter((_REQUEST,)))
response_iterator = getattr(self._dynamic_stub, _STREAM_STREAM)(
request_iterator, test_constants.SHORT_TIMEOUT,

Loading…
Cancel
Save