def setUp(self): self._servicer = _Servicer() self._method_implementations = { (_GROUP, _UNARY_UNARY): utilities.unary_unary_inline(self._servicer.unary_unary), (_GROUP, _UNARY_STREAM): utilities.unary_stream_inline(self._servicer.unary_stream), (_GROUP, _STREAM_UNARY): utilities.stream_unary_inline(self._servicer.stream_unary), (_GROUP, _STREAM_STREAM): utilities.stream_stream_inline(self._servicer.stream_stream), } self._cardinalities = { _UNARY_UNARY: cardinality.Cardinality.UNARY_UNARY, _UNARY_STREAM: cardinality.Cardinality.UNARY_STREAM, _STREAM_UNARY: cardinality.Cardinality.STREAM_UNARY, _STREAM_STREAM: cardinality.Cardinality.STREAM_STREAM, } self._server_options = implementations.server_options( thread_pool_size=test_constants.POOL_SIZE) self._server_credentials = implementations.ssl_server_credentials( [(resources.private_key(), resources.certificate_chain(),),]) self._client_credentials = implementations.ssl_client_credentials( resources.test_root_certificates(), None, None) self._stub_options = implementations.stub_options( thread_pool_size=test_constants.POOL_SIZE)
def make_stub(client, stub_factory, host, port): """Makes a stub for an RPC service. Uses / depends on the beta implementation of gRPC. :type client: :class:`.client.Client` :param client: The client that owns the cluster. Provides authorization and user agent. :type stub_factory: callable :param stub_factory: A factory which will create a gRPC stub for a given service. :type host: str :param host: The host for the service. :type port: int :param port: The port for the service. :rtype: :class:`grpc.beta._stub._AutoIntermediary` :returns: The stub object used to make gRPC requests to a given API. """ root_certificates = get_certs() client_credentials = implementations.ssl_client_credentials( root_certificates, private_key=None, certificate_chain=None) channel = implementations.secure_channel(host, port, client_credentials) custom_metadata_transformer = MetadataTransformer(client) return stub_factory(channel, metadata_transformer=custom_metadata_transformer)
def make_stub(client, stub_factory, host, port): """Makes a stub for an RPC service. Uses / depends on the beta implementation of gRPC. :type client: :class:`.client.Client` :param client: The client that owns the cluster. Provides authorization and user agent. :type stub_factory: callable :param stub_factory: A factory which will create a gRPC stub for a given service. :type host: str :param host: The host for the service. :type port: int :param port: The port for the service. :rtype: :class:`grpc.beta._stub._AutoIntermediary` :returns: The stub object used to make gRPC requests to a given API. """ root_certificates = get_certs() client_credentials = implementations.ssl_client_credentials( root_certificates, private_key=None, certificate_chain=None) channel = implementations.secure_channel( host, port, client_credentials) custom_metadata_transformer = MetadataTransformer(client) return stub_factory(channel, metadata_transformer=custom_metadata_transformer)
def instantiate( self, methods, method_implementations, multi_method_implementation): serialization_behaviors = _serialization_behaviors_from_test_methods( methods) # TODO(nathaniel): Add a "groups" attribute to _digest.TestServiceDigest. service = next(iter(methods))[0] # TODO(nathaniel): Add a "cardinalities_by_group" attribute to # _digest.TestServiceDigest. cardinalities = { method: method_object.cardinality() for (group, method), method_object in methods.iteritems()} server_options = implementations.server_options( request_deserializers=serialization_behaviors.request_deserializers, response_serializers=serialization_behaviors.response_serializers, thread_pool_size=test_constants.POOL_SIZE) server = implementations.server( method_implementations, options=server_options) server_credentials = implementations.ssl_server_credentials( [(resources.private_key(), resources.certificate_chain(),),]) port = server.add_secure_port('[::]:0', server_credentials) server.start() client_credentials = implementations.ssl_client_credentials( resources.test_root_certificates(), None, None) channel = test_utilities.not_really_secure_channel( 'localhost', port, client_credentials, _SERVER_HOST_OVERRIDE) stub_options = implementations.stub_options( request_serializers=serialization_behaviors.request_serializers, response_deserializers=serialization_behaviors.response_deserializers, thread_pool_size=test_constants.POOL_SIZE) generic_stub = implementations.generic_stub(channel, options=stub_options) dynamic_stub = implementations.dynamic_stub( channel, service, cardinalities, options=stub_options) return generic_stub, {service: dynamic_stub}, server
def _stub(args): if args.oauth_scope: if args.test_case == 'oauth2_auth_token': # TODO(jtattermusch): This testcase sets the auth metadata key-value # manually, which also means that the user would need to do the same # thing every time he/she would like to use and out of band oauth token. # The transformer function that produces the metadata key-value from # the access token should be provided by gRPC auth library. access_token = _oauth_access_token(args) metadata_transformer = lambda x: [ ('authorization', 'Bearer %s' % access_token)] else: metadata_transformer = lambda x: [ ('authorization', 'Bearer %s' % _oauth_access_token(args))] else: metadata_transformer = lambda x: [] if args.use_tls: if args.use_test_ca: root_certificates = resources.test_root_certificates() else: root_certificates = resources.prod_root_certificates() channel = test_utilities.not_really_secure_channel( args.server_host, args.server_port, implementations.ssl_client_credentials(root_certificates, None, None), args.server_host_override) stub = test_pb2.beta_create_TestService_stub( channel, metadata_transformer=metadata_transformer) else: channel = implementations.insecure_channel( args.server_host, args.server_port) stub = test_pb2.beta_create_TestService_stub(channel) return stub
def _stub(args): if args.oauth_scope: if args.test_case == 'oauth2_auth_token': # TODO(jtattermusch): This testcase sets the auth metadata key-value # manually, which also means that the user would need to do the same # thing every time he/she would like to use and out of band oauth token. # The transformer function that produces the metadata key-value from # the access token should be provided by gRPC auth library. access_token = _oauth_access_token(args) metadata_transformer = lambda x: [('authorization', 'Bearer %s' % access_token)] else: metadata_transformer = lambda x: [('authorization', 'Bearer %s' % _oauth_access_token(args))] else: metadata_transformer = lambda x: [] if args.use_tls: if args.use_test_ca: root_certificates = resources.test_root_certificates() else: root_certificates = resources.prod_root_certificates() channel = test_utilities.not_really_secure_channel( args.server_host, args.server_port, implementations.ssl_client_credentials(root_certificates, None, None), args.server_host_override) stub = test_pb2.beta_create_TestService_stub( channel, metadata_transformer=metadata_transformer) else: channel = implementations.insecure_channel(args.server_host, args.server_port) stub = test_pb2.beta_create_TestService_stub(channel) return stub
def setUp(self): self.server = test_pb2.beta_create_TestService_server(methods.TestService()) port = self.server.add_secure_port( '[::]:0', implementations.ssl_server_credentials( [(resources.private_key(), resources.certificate_chain())])) self.server.start() self.stub = test_pb2.beta_create_TestService_stub( test_utilities.not_really_secure_channel( '[::]', port, implementations.ssl_client_credentials( resources.test_root_certificates(), None, None), _SERVER_HOST_OVERRIDE))
def instantiate(self, methods, method_implementations, multi_method_implementation): serialization_behaviors = _serialization_behaviors_from_test_methods( methods) # TODO(nathaniel): Add a "groups" attribute to _digest.TestServiceDigest. service = next(iter(methods))[0] # TODO(nathaniel): Add a "cardinalities_by_group" attribute to # _digest.TestServiceDigest. cardinalities = { method: method_object.cardinality() for (group, method), method_object in methods.iteritems() } server_options = implementations.server_options( request_deserializers=serialization_behaviors. request_deserializers, response_serializers=serialization_behaviors.response_serializers, thread_pool_size=test_constants.POOL_SIZE) server = implementations.server(method_implementations, options=server_options) server_credentials = implementations.ssl_server_credentials([ ( resources.private_key(), resources.certificate_chain(), ), ]) port = server.add_secure_port('[::]:0', server_credentials) server.start() client_credentials = implementations.ssl_client_credentials( resources.test_root_certificates(), None, None) channel = test_utilities.not_really_secure_channel( 'localhost', port, client_credentials, _SERVER_HOST_OVERRIDE) stub_options = implementations.stub_options( request_serializers=serialization_behaviors.request_serializers, response_deserializers=serialization_behaviors. response_deserializers, thread_pool_size=test_constants.POOL_SIZE) generic_stub = implementations.generic_stub(channel, options=stub_options) dynamic_stub = implementations.dynamic_stub(channel, service, cardinalities, options=stub_options) return generic_stub, {service: dynamic_stub}, server
def setUp(self): self._servicer = _Servicer() method_implementations = { (_GROUP, _UNARY_UNARY): utilities.unary_unary_inline(self._servicer.unary_unary), (_GROUP, _UNARY_STREAM): utilities.unary_stream_inline(self._servicer.unary_stream), (_GROUP, _STREAM_UNARY): utilities.stream_unary_inline(self._servicer.stream_unary), (_GROUP, _STREAM_STREAM): utilities.stream_stream_inline(self._servicer.stream_stream), } cardinalities = { _UNARY_UNARY: cardinality.Cardinality.UNARY_UNARY, _UNARY_STREAM: cardinality.Cardinality.UNARY_STREAM, _STREAM_UNARY: cardinality.Cardinality.STREAM_UNARY, _STREAM_STREAM: cardinality.Cardinality.STREAM_STREAM, } server_options = implementations.server_options( thread_pool_size=test_constants.POOL_SIZE) self._server = implementations.server(method_implementations, options=server_options) server_credentials = implementations.ssl_server_credentials([ ( resources.private_key(), resources.certificate_chain(), ), ]) port = self._server.add_secure_port('[::]:0', server_credentials) self._server.start() self._client_credentials = implementations.ssl_client_credentials( resources.test_root_certificates(), None, None) channel = test_utilities.not_really_secure_channel( 'localhost', port, self._client_credentials, _SERVER_HOST_OVERRIDE) stub_options = implementations.stub_options( thread_pool_size=test_constants.POOL_SIZE) self._dynamic_stub = implementations.dynamic_stub(channel, _GROUP, cardinalities, options=stub_options)
def setUp(self): self._servicer = _Servicer() method_implementations = { (_GROUP, _UNARY_UNARY): utilities.unary_unary_inline(self._servicer.unary_unary), (_GROUP, _UNARY_STREAM): utilities.unary_stream_inline(self._servicer.unary_stream), (_GROUP, _STREAM_UNARY): utilities.stream_unary_inline(self._servicer.stream_unary), (_GROUP, _STREAM_STREAM): utilities.stream_stream_inline(self._servicer.stream_stream), } cardinalities = { _UNARY_UNARY: cardinality.Cardinality.UNARY_UNARY, _UNARY_STREAM: cardinality.Cardinality.UNARY_STREAM, _STREAM_UNARY: cardinality.Cardinality.STREAM_UNARY, _STREAM_STREAM: cardinality.Cardinality.STREAM_STREAM, } server_options = implementations.server_options( thread_pool_size=test_constants.POOL_SIZE) self._server = implementations.server( method_implementations, options=server_options) server_credentials = implementations.ssl_server_credentials( [(resources.private_key(), resources.certificate_chain(),),]) port = self._server.add_secure_port('[::]:0', server_credentials) self._server.start() self._client_credentials = implementations.ssl_client_credentials( resources.test_root_certificates(), None, None) channel = test_utilities.not_really_secure_channel( 'localhost', port, self._client_credentials, _SERVER_HOST_OVERRIDE) stub_options = implementations.stub_options( thread_pool_size=test_constants.POOL_SIZE) self._dynamic_stub = implementations.dynamic_stub( channel, _GROUP, cardinalities, options=stub_options)