Skip to content
Snippets Groups Projects
Commit a55c0949 authored by Nathaniel Manista's avatar Nathaniel Manista
Browse files

Python secure server API changes

parent e7460e87
No related branches found
No related tags found
No related merge requests found
......@@ -92,7 +92,7 @@ class _CTest(unittest.TestCase):
_c.init()
completion_queue = _c.CompletionQueue()
server = _c.Server(completion_queue, None)
server = _c.Server(completion_queue)
server.add_http2_addr('[::]:0')
server.start()
server.stop()
......@@ -102,7 +102,7 @@ class _CTest(unittest.TestCase):
service_tag = object()
completion_queue = _c.CompletionQueue()
server = _c.Server(completion_queue, None)
server = _c.Server(completion_queue)
server.add_http2_addr('[::]:0')
server.start()
server.service(service_tag)
......@@ -119,7 +119,7 @@ class _CTest(unittest.TestCase):
del completion_queue
completion_queue = _c.CompletionQueue()
server = _c.Server(completion_queue, None)
server = _c.Server(completion_queue)
server.add_http2_addr('[::]:0')
server.start()
thread = threading.Thread(target=completion_queue.get, args=(_FUTURE,))
......
......@@ -82,7 +82,7 @@ class EchoTest(unittest.TestCase):
self.host = 'localhost'
self.server_completion_queue = _low.CompletionQueue()
self.server = _low.Server(self.server_completion_queue, None)
self.server = _low.Server(self.server_completion_queue)
port = self.server.add_http2_addr('[::]:0')
self.server.start()
......@@ -260,7 +260,7 @@ class CancellationTest(unittest.TestCase):
self.host = 'localhost'
self.server_completion_queue = _low.CompletionQueue()
self.server = _low.Server(self.server_completion_queue, None)
self.server = _low.Server(self.server_completion_queue)
port = self.server.add_http2_addr('[::]:0')
self.server.start()
......
......@@ -42,30 +42,16 @@
static int pygrpc_server_init(Server *self, PyObject *args, PyObject *kwds) {
const PyObject *completion_queue;
PyObject *server_credentials;
static char *kwlist[] = {"completion_queue", "server_credentials", NULL};
static char *kwlist[] = {"completion_queue", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!O:Server", kwlist,
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!:Server", kwlist,
&pygrpc_CompletionQueueType,
&completion_queue, &server_credentials)) {
return -1;
}
if (server_credentials == Py_None) {
self->c_server = grpc_server_create(
((CompletionQueue *)completion_queue)->c_completion_queue, NULL);
return 0;
} else if (PyObject_TypeCheck(server_credentials,
&pygrpc_ServerCredentialsType)) {
self->c_server = grpc_secure_server_create(
((ServerCredentials *)server_credentials)->c_server_credentials,
((CompletionQueue *)completion_queue)->c_completion_queue, NULL);
return 0;
} else {
PyErr_Format(PyExc_TypeError,
"server_credentials must be _grpc.ServerCredentials, not %s",
Py_TYPE(server_credentials)->tp_name);
&completion_queue)) {
return -1;
}
self->c_server = grpc_server_create(
((CompletionQueue *)completion_queue)->c_completion_queue, NULL);
return 0;
}
static void pygrpc_server_dealloc(Server *self) {
......@@ -92,13 +78,21 @@ static PyObject *pygrpc_server_add_http2_addr(Server *self, PyObject *args) {
}
static PyObject *pygrpc_server_add_secure_http2_addr(Server *self,
PyObject *args) {
PyObject *args,
PyObject *kwargs) {
const char *addr;
PyObject *server_credentials;
static char *kwlist[] = {"addr", "server_credentials", NULL};
int port;
if (!PyArg_ParseTuple(args, "s:add_secure_http2_addr", &addr)) {
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sO!:add_secure_http2_addr",
kwlist, &addr, &pygrpc_ServerCredentialsType,
&server_credentials)) {
return NULL;
}
port = grpc_server_add_secure_http2_port(self->c_server, addr);
port = grpc_server_add_secure_http2_port(
self->c_server, addr,
((ServerCredentials *)server_credentials)->c_server_credentials);
if (port == 0) {
PyErr_SetString(PyExc_RuntimeError, "Couldn't add port to server!");
return NULL;
......@@ -138,8 +132,7 @@ static PyMethodDef methods[] = {
METH_VARARGS, "Add a secure HTTP2 address."},
{"start", (PyCFunction)pygrpc_server_start, METH_NOARGS,
"Starts the server."},
{"service", (PyCFunction)pygrpc_server_service, METH_O,
"Services a call."},
{"service", (PyCFunction)pygrpc_server_service, METH_O, "Services a call."},
{"stop", (PyCFunction)pygrpc_server_stop, METH_NOARGS, "Stops the server."},
{NULL}};
......
......@@ -280,13 +280,14 @@ class ForeLink(ticket_interfaces.ForeLink, activated.Activated):
0 if self._requested_port is None else self._requested_port)
self._completion_queue = _low.CompletionQueue()
if self._root_certificates is None and not self._key_chain_pairs:
self._server = _low.Server(self._completion_queue, None)
self._server = _low.Server(self._completion_queue)
self._port = self._server.add_http2_addr(address)
else:
server_credentials = _low.ServerCredentials(
self._root_certificates, self._key_chain_pairs)
self._server = _low.Server(self._completion_queue, server_credentials)
self._port = self._server.add_secure_http2_addr(address)
self._server = _low.Server(self._completion_queue)
self._port = self._server.add_secure_http2_addr(
address, server_credentials)
self._server.start()
self._server.service(None)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment