aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/python/grpcio/grpc/_adapter/_c/types.c3
-rw-r--r--src/python/grpcio/grpc/_adapter/_c/types.h34
-rw-r--r--src/python/grpcio/grpc/_adapter/_c/types/call.c4
-rw-r--r--src/python/grpcio/grpc/_adapter/_c/types/call_credentials.c (renamed from src/python/grpcio/grpc/_adapter/_c/types/client_credentials.c)116
-rw-r--r--src/python/grpcio/grpc/_adapter/_c/types/channel.c4
-rw-r--r--src/python/grpcio/grpc/_adapter/_c/types/channel_credentials.c165
-rw-r--r--src/python/grpcio/grpc/_adapter/_intermediary_low.py4
-rw-r--r--src/python/grpcio/grpc/_adapter/_low.py3
-rw-r--r--src/python/grpcio/grpc/_adapter/_types.py10
-rw-r--r--src/python/grpcio/grpc/_cython/_cygrpc/call.pyx6
-rw-r--r--src/python/grpcio/grpc/_cython/_cygrpc/channel.pyx8
-rw-r--r--src/python/grpcio/grpc/_cython/_cygrpc/credentials.pxd10
-rw-r--r--src/python/grpcio/grpc/_cython/_cygrpc/credentials.pyx67
-rw-r--r--src/python/grpcio/grpc/_cython/_cygrpc/grpc.pxd34
-rw-r--r--src/python/grpcio/grpc/_cython/cygrpc.pyx29
-rw-r--r--src/python/grpcio/grpc/beta/interfaces.py5
-rw-r--r--src/python/grpcio/setup.py3
-rw-r--r--src/python/grpcio_test/grpc_test/beta/_beta_features_test.py12
18 files changed, 354 insertions, 163 deletions
diff --git a/src/python/grpcio/grpc/_adapter/_c/types.c b/src/python/grpcio/grpc/_adapter/_c/types.c
index 8855c32ca6..8dedf5902b 100644
--- a/src/python/grpcio/grpc/_adapter/_c/types.c
+++ b/src/python/grpcio/grpc/_adapter/_c/types.c
@@ -40,7 +40,8 @@
int pygrpc_module_add_types(PyObject *module) {
int i;
PyTypeObject *types[] = {
- &pygrpc_ClientCredentials_type,
+ &pygrpc_CallCredentials_type,
+ &pygrpc_ChannelCredentials_type,
&pygrpc_ServerCredentials_type,
&pygrpc_CompletionQueue_type,
&pygrpc_Call_type,
diff --git a/src/python/grpcio/grpc/_adapter/_c/types.h b/src/python/grpcio/grpc/_adapter/_c/types.h
index 31fd470d36..9ab415d216 100644
--- a/src/python/grpcio/grpc/_adapter/_c/types.h
+++ b/src/python/grpcio/grpc/_adapter/_c/types.h
@@ -44,27 +44,35 @@
/* Client-side credentials */
/*=========================*/
-typedef struct ClientCredentials {
+typedef struct ChannelCredentials {
PyObject_HEAD
- grpc_credentials *c_creds;
-} ClientCredentials;
-void pygrpc_ClientCredentials_dealloc(ClientCredentials *self);
-ClientCredentials *pygrpc_ClientCredentials_google_default(
+ grpc_channel_credentials *c_creds;
+} ChannelCredentials;
+void pygrpc_ChannelCredentials_dealloc(ChannelCredentials *self);
+ChannelCredentials *pygrpc_ChannelCredentials_google_default(
PyTypeObject *type, PyObject *ignored);
-ClientCredentials *pygrpc_ClientCredentials_ssl(
+ChannelCredentials *pygrpc_ChannelCredentials_ssl(
PyTypeObject *type, PyObject *args, PyObject *kwargs);
-ClientCredentials *pygrpc_ClientCredentials_composite(
+ChannelCredentials *pygrpc_ChannelCredentials_composite(
PyTypeObject *type, PyObject *args, PyObject *kwargs);
-ClientCredentials *pygrpc_ClientCredentials_compute_engine(
+extern PyTypeObject pygrpc_ChannelCredentials_type;
+
+typedef struct CallCredentials {
+ PyObject_HEAD
+ grpc_call_credentials *c_creds;
+} CallCredentials;
+void pygrpc_CallCredentials_dealloc(CallCredentials *self);
+CallCredentials *pygrpc_CallCredentials_composite(
+ PyTypeObject *type, PyObject *args, PyObject *kwargs);
+CallCredentials *pygrpc_CallCredentials_compute_engine(
PyTypeObject *type, PyObject *ignored);
-ClientCredentials *pygrpc_ClientCredentials_jwt(
+CallCredentials *pygrpc_CallCredentials_jwt(
PyTypeObject *type, PyObject *args, PyObject *kwargs);
-ClientCredentials *pygrpc_ClientCredentials_refresh_token(
+CallCredentials *pygrpc_CallCredentials_refresh_token(
PyTypeObject *type, PyObject *args, PyObject *kwargs);
-ClientCredentials *pygrpc_ClientCredentials_iam(
+CallCredentials *pygrpc_CallCredentials_iam(
PyTypeObject *type, PyObject *args, PyObject *kwargs);
-extern PyTypeObject pygrpc_ClientCredentials_type;
-
+extern PyTypeObject pygrpc_CallCredentials_type;
/*=========================*/
/* Server-side credentials */
diff --git a/src/python/grpcio/grpc/_adapter/_c/types/call.c b/src/python/grpcio/grpc/_adapter/_c/types/call.c
index 5604aba39d..04ec871880 100644
--- a/src/python/grpcio/grpc/_adapter/_c/types/call.c
+++ b/src/python/grpcio/grpc/_adapter/_c/types/call.c
@@ -173,12 +173,12 @@ PyObject *pygrpc_Call_peer(Call *self) {
}
PyObject *pygrpc_Call_set_credentials(Call *self, PyObject *args,
PyObject *kwargs) {
- ClientCredentials *creds;
+ CallCredentials *creds;
grpc_call_error errcode;
static char *keywords[] = {"creds", NULL};
if (!PyArg_ParseTupleAndKeywords(
args, kwargs, "O!:set_credentials", keywords,
- &pygrpc_ClientCredentials_type, &creds)) {
+ &pygrpc_CallCredentials_type, &creds)) {
return NULL;
}
errcode = grpc_call_set_credentials(self->c_call, creds->c_creds);
diff --git a/src/python/grpcio/grpc/_adapter/_c/types/client_credentials.c b/src/python/grpcio/grpc/_adapter/_c/types/call_credentials.c
index 90652b7b47..5a15a6e17d 100644
--- a/src/python/grpcio/grpc/_adapter/_c/types/client_credentials.c
+++ b/src/python/grpcio/grpc/_adapter/_c/types/call_credentials.c
@@ -39,31 +39,28 @@
#include <grpc/grpc_security.h>
-PyMethodDef pygrpc_ClientCredentials_methods[] = {
- {"google_default", (PyCFunction)pygrpc_ClientCredentials_google_default,
- METH_CLASS|METH_NOARGS, ""},
- {"ssl", (PyCFunction)pygrpc_ClientCredentials_ssl,
- METH_CLASS|METH_KEYWORDS, ""},
- {"composite", (PyCFunction)pygrpc_ClientCredentials_composite,
+PyMethodDef pygrpc_CallCredentials_methods[] = {
+ {"composite", (PyCFunction)pygrpc_CallCredentials_composite,
METH_CLASS|METH_KEYWORDS, ""},
- {"compute_engine", (PyCFunction)pygrpc_ClientCredentials_compute_engine,
+ {"compute_engine", (PyCFunction)pygrpc_CallCredentials_compute_engine,
METH_CLASS|METH_NOARGS, ""},
- {"jwt", (PyCFunction)pygrpc_ClientCredentials_jwt,
+ {"jwt", (PyCFunction)pygrpc_CallCredentials_jwt,
METH_CLASS|METH_KEYWORDS, ""},
- {"refresh_token", (PyCFunction)pygrpc_ClientCredentials_refresh_token,
+ {"refresh_token", (PyCFunction)pygrpc_CallCredentials_refresh_token,
METH_CLASS|METH_KEYWORDS, ""},
- {"iam", (PyCFunction)pygrpc_ClientCredentials_iam,
+ {"iam", (PyCFunction)pygrpc_CallCredentials_iam,
METH_CLASS|METH_KEYWORDS, ""},
{NULL}
};
-const char pygrpc_ClientCredentials_doc[] = "";
-PyTypeObject pygrpc_ClientCredentials_type = {
+
+const char pygrpc_CallCredentials_doc[] = "";
+PyTypeObject pygrpc_CallCredentials_type = {
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
- "ClientCredentials", /* tp_name */
- sizeof(ClientCredentials), /* tp_basicsize */
+ "CallCredentials", /* tp_name */
+ sizeof(CallCredentials), /* tp_basicsize */
0, /* tp_itemsize */
- (destructor)pygrpc_ClientCredentials_dealloc, /* tp_dealloc */
+ (destructor)pygrpc_CallCredentials_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
@@ -79,14 +76,14 @@ PyTypeObject pygrpc_ClientCredentials_type = {
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
- pygrpc_ClientCredentials_doc, /* tp_doc */
+ pygrpc_CallCredentials_doc, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
- pygrpc_ClientCredentials_methods, /* tp_methods */
+ pygrpc_CallCredentials_methods, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
@@ -99,67 +96,26 @@ PyTypeObject pygrpc_ClientCredentials_type = {
0 /* tp_new */
};
-void pygrpc_ClientCredentials_dealloc(ClientCredentials *self) {
- grpc_credentials_release(self->c_creds);
+void pygrpc_CallCredentials_dealloc(CallCredentials *self) {
+ grpc_call_credentials_release(self->c_creds);
self->ob_type->tp_free((PyObject *)self);
}
-ClientCredentials *pygrpc_ClientCredentials_google_default(
- PyTypeObject *type, PyObject *ignored) {
- ClientCredentials *self = (ClientCredentials *)type->tp_alloc(type, 0);
- self->c_creds = grpc_google_default_credentials_create();
- if (!self->c_creds) {
- Py_DECREF(self);
- PyErr_SetString(PyExc_RuntimeError,
- "couldn't create Google default credentials");
- return NULL;
- }
- return self;
-}
-
-ClientCredentials *pygrpc_ClientCredentials_ssl(
- PyTypeObject *type, PyObject *args, PyObject *kwargs) {
- ClientCredentials *self;
- const char *root_certs;
- const char *private_key = NULL;
- const char *cert_chain = NULL;
- grpc_ssl_pem_key_cert_pair key_cert_pair;
- static char *keywords[] = {"root_certs", "private_key", "cert_chain", NULL};
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "z|zz:ssl", keywords,
- &root_certs, &private_key, &cert_chain)) {
- return NULL;
- }
- self = (ClientCredentials *)type->tp_alloc(type, 0);
- if (private_key && cert_chain) {
- key_cert_pair.private_key = private_key;
- key_cert_pair.cert_chain = cert_chain;
- self->c_creds =
- grpc_ssl_credentials_create(root_certs, &key_cert_pair, NULL);
- } else {
- self->c_creds = grpc_ssl_credentials_create(root_certs, NULL, NULL);
- }
- if (!self->c_creds) {
- Py_DECREF(self);
- PyErr_SetString(PyExc_RuntimeError, "couldn't create ssl credentials");
- return NULL;
- }
- return self;
-}
-
-ClientCredentials *pygrpc_ClientCredentials_composite(
+CallCredentials *pygrpc_CallCredentials_composite(
PyTypeObject *type, PyObject *args, PyObject *kwargs) {
- ClientCredentials *self;
- ClientCredentials *creds1;
- ClientCredentials *creds2;
+ CallCredentials *self;
+ CallCredentials *creds1;
+ CallCredentials *creds2;
static char *keywords[] = {"creds1", "creds2", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!O!:composite", keywords,
- &pygrpc_ClientCredentials_type, &creds1,
- &pygrpc_ClientCredentials_type, &creds2)) {
+ &pygrpc_CallCredentials_type, &creds1,
+ &pygrpc_CallCredentials_type, &creds2)) {
return NULL;
}
- self = (ClientCredentials *)type->tp_alloc(type, 0);
+ self = (CallCredentials *)type->tp_alloc(type, 0);
self->c_creds =
- grpc_composite_credentials_create(creds1->c_creds, creds2->c_creds, NULL);
+ grpc_composite_call_credentials_create(
+ creds1->c_creds, creds2->c_creds, NULL);
if (!self->c_creds) {
Py_DECREF(self);
PyErr_SetString(PyExc_RuntimeError, "couldn't create composite credentials");
@@ -168,9 +124,9 @@ ClientCredentials *pygrpc_ClientCredentials_composite(
return self;
}
-ClientCredentials *pygrpc_ClientCredentials_compute_engine(
+CallCredentials *pygrpc_CallCredentials_compute_engine(
PyTypeObject *type, PyObject *ignored) {
- ClientCredentials *self = (ClientCredentials *)type->tp_alloc(type, 0);
+ CallCredentials *self = (CallCredentials *)type->tp_alloc(type, 0);
self->c_creds = grpc_google_compute_engine_credentials_create(NULL);
if (!self->c_creds) {
Py_DECREF(self);
@@ -182,9 +138,9 @@ ClientCredentials *pygrpc_ClientCredentials_compute_engine(
}
/* TODO: Rename this credentials to something like service_account_jwt_access */
-ClientCredentials *pygrpc_ClientCredentials_jwt(
+CallCredentials *pygrpc_CallCredentials_jwt(
PyTypeObject *type, PyObject *args, PyObject *kwargs) {
- ClientCredentials *self;
+ CallCredentials *self;
const char *json_key;
double lifetime;
static char *keywords[] = {"json_key", "token_lifetime", NULL};
@@ -192,7 +148,7 @@ ClientCredentials *pygrpc_ClientCredentials_jwt(
&json_key, &lifetime)) {
return NULL;
}
- self = (ClientCredentials *)type->tp_alloc(type, 0);
+ self = (CallCredentials *)type->tp_alloc(type, 0);
self->c_creds = grpc_service_account_jwt_access_credentials_create(
json_key, pygrpc_cast_double_to_gpr_timespec(lifetime), NULL);
if (!self->c_creds) {
@@ -203,16 +159,16 @@ ClientCredentials *pygrpc_ClientCredentials_jwt(
return self;
}
-ClientCredentials *pygrpc_ClientCredentials_refresh_token(
+CallCredentials *pygrpc_CallCredentials_refresh_token(
PyTypeObject *type, PyObject *args, PyObject *kwargs) {
- ClientCredentials *self;
+ CallCredentials *self;
const char *json_refresh_token;
static char *keywords[] = {"json_refresh_token", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s:refresh_token", keywords,
&json_refresh_token)) {
return NULL;
}
- self = (ClientCredentials *)type->tp_alloc(type, 0);
+ self = (CallCredentials *)type->tp_alloc(type, 0);
self->c_creds =
grpc_google_refresh_token_credentials_create(json_refresh_token, NULL);
if (!self->c_creds) {
@@ -224,9 +180,9 @@ ClientCredentials *pygrpc_ClientCredentials_refresh_token(
return self;
}
-ClientCredentials *pygrpc_ClientCredentials_iam(
+CallCredentials *pygrpc_CallCredentials_iam(
PyTypeObject *type, PyObject *args, PyObject *kwargs) {
- ClientCredentials *self;
+ CallCredentials *self;
const char *authorization_token;
const char *authority_selector;
static char *keywords[] = {"authorization_token", "authority_selector", NULL};
@@ -234,7 +190,7 @@ ClientCredentials *pygrpc_ClientCredentials_iam(
&authorization_token, &authority_selector)) {
return NULL;
}
- self = (ClientCredentials *)type->tp_alloc(type, 0);
+ self = (CallCredentials *)type->tp_alloc(type, 0);
self->c_creds = grpc_google_iam_credentials_create(authorization_token,
authority_selector, NULL);
if (!self->c_creds) {
diff --git a/src/python/grpcio/grpc/_adapter/_c/types/channel.c b/src/python/grpcio/grpc/_adapter/_c/types/channel.c
index 79d39c4391..c4db2a0dfd 100644
--- a/src/python/grpcio/grpc/_adapter/_c/types/channel.c
+++ b/src/python/grpcio/grpc/_adapter/_c/types/channel.c
@@ -94,11 +94,11 @@ Channel *pygrpc_Channel_new(
Channel *self;
const char *target;
PyObject *py_args;
- ClientCredentials *creds = NULL;
+ ChannelCredentials *creds = NULL;
grpc_channel_args c_args;
char *keywords[] = {"target", "args", "creds", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sO|O!:Channel", keywords,
- &target, &py_args, &pygrpc_ClientCredentials_type, &creds)) {
+ &target, &py_args, &pygrpc_ChannelCredentials_type, &creds)) {
return NULL;
}
if (!pygrpc_produce_channel_args(py_args, &c_args)) {
diff --git a/src/python/grpcio/grpc/_adapter/_c/types/channel_credentials.c b/src/python/grpcio/grpc/_adapter/_c/types/channel_credentials.c
new file mode 100644
index 0000000000..83b1fc0406
--- /dev/null
+++ b/src/python/grpcio/grpc/_adapter/_c/types/channel_credentials.c
@@ -0,0 +1,165 @@
+/*
+ *
+ * Copyright 2015, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "grpc/_adapter/_c/types.h"
+
+#define PY_SSIZE_T_CLEAN
+#include <Python.h>
+#include <grpc/grpc.h>
+#include <grpc/grpc_security.h>
+
+
+PyMethodDef pygrpc_ChannelCredentials_methods[] = {
+ {"google_default", (PyCFunction)pygrpc_ChannelCredentials_google_default,
+ METH_CLASS|METH_NOARGS, ""},
+ {"ssl", (PyCFunction)pygrpc_ChannelCredentials_ssl,
+ METH_CLASS|METH_KEYWORDS, ""},
+ {"composite", (PyCFunction)pygrpc_ChannelCredentials_composite,
+ METH_CLASS|METH_KEYWORDS, ""},
+ {NULL}
+};
+
+const char pygrpc_ChannelCredentials_doc[] = "";
+PyTypeObject pygrpc_ChannelCredentials_type = {
+ PyObject_HEAD_INIT(NULL)
+ 0, /* ob_size */
+ "ChannelCredentials", /* tp_name */
+ sizeof(ChannelCredentials), /* tp_basicsize */
+ 0, /* tp_itemsize */
+ (destructor)pygrpc_ChannelCredentials_dealloc, /* tp_dealloc */
+ 0, /* tp_print */
+ 0, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_compare */
+ 0, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
+ 0, /* tp_str */
+ 0, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
+ pygrpc_ChannelCredentials_doc, /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ pygrpc_ChannelCredentials_methods, /* tp_methods */
+ 0, /* tp_members */
+ 0, /* tp_getset */
+ 0, /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ 0, /* tp_init */
+ 0, /* tp_alloc */
+ 0 /* tp_new */
+};
+
+void pygrpc_ChannelCredentials_dealloc(ChannelCredentials *self) {
+ grpc_channel_credentials_release(self->c_creds);
+ self->ob_type->tp_free((PyObject *)self);
+}
+
+ChannelCredentials *pygrpc_ChannelCredentials_google_default(
+ PyTypeObject *type, PyObject *ignored) {
+ ChannelCredentials *self = (ChannelCredentials *)type->tp_alloc(type, 0);
+ self->c_creds = grpc_google_default_credentials_create();
+ if (!self->c_creds) {
+ Py_DECREF(self);
+ PyErr_SetString(PyExc_RuntimeError,
+ "couldn't create Google default credentials");
+ return NULL;
+ }
+ return self;
+}
+
+ChannelCredentials *pygrpc_ChannelCredentials_ssl(
+ PyTypeObject *type, PyObject *args, PyObject *kwargs) {
+ ChannelCredentials *self;
+ const char *root_certs;
+ const char *private_key = NULL;
+ const char *cert_chain = NULL;
+ grpc_ssl_pem_key_cert_pair key_cert_pair;
+ static char *keywords[] = {"root_certs", "private_key", "cert_chain", NULL};
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "z|zz:ssl", keywords,
+ &root_certs, &private_key, &cert_chain)) {
+ return NULL;
+ }
+ self = (ChannelCredentials *)type->tp_alloc(type, 0);
+ if (private_key && cert_chain) {
+ key_cert_pair.private_key = private_key;
+ key_cert_pair.cert_chain = cert_chain;
+ self->c_creds =
+ grpc_ssl_credentials_create(root_certs, &key_cert_pair, NULL);
+ } else {
+ self->c_creds = grpc_ssl_credentials_create(root_certs, NULL, NULL);
+ }
+ if (!self->c_creds) {
+ Py_DECREF(self);
+ PyErr_SetString(PyExc_RuntimeError, "couldn't create ssl credentials");
+ return NULL;
+ }
+ return self;
+}
+
+ChannelCredentials *pygrpc_ChannelCredentials_composite(
+ PyTypeObject *type, PyObject *args, PyObject *kwargs) {
+ ChannelCredentials *self;
+ ChannelCredentials *creds1;
+ CallCredentials *creds2;
+ static char *keywords[] = {"creds1", "creds2", NULL};
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!O!:composite", keywords,
+ &pygrpc_ChannelCredentials_type, &creds1,
+ &pygrpc_CallCredentials_type, &creds2)) {
+ return NULL;
+ }
+ self = (ChannelCredentials *)type->tp_alloc(type, 0);
+ self->c_creds =
+ grpc_composite_channel_credentials_create(
+ creds1->c_creds, creds2->c_creds, NULL);
+ if (!self->c_creds) {
+ Py_DECREF(self);
+ PyErr_SetString(
+ PyExc_RuntimeError, "couldn't create composite credentials");
+ return NULL;
+ }
+ return self;
+}
+
diff --git a/src/python/grpcio/grpc/_adapter/_intermediary_low.py b/src/python/grpcio/grpc/_adapter/_intermediary_low.py
index e2feec6ffb..5634c2024d 100644
--- a/src/python/grpcio/grpc/_adapter/_intermediary_low.py
+++ b/src/python/grpcio/grpc/_adapter/_intermediary_low.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):
diff --git a/src/python/grpcio/grpc/_adapter/_low.py b/src/python/grpcio/grpc/_adapter/_low.py
index 70ceb2a911..57146aaefe 100644
--- a/src/python/grpcio/grpc/_adapter/_low.py
+++ b/src/python/grpcio/grpc/_adapter/_low.py
@@ -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
diff --git a/src/python/grpcio/grpc/_adapter/_types.py b/src/python/grpcio/grpc/_adapter/_types.py
index 5470d2de4a..ca0fa066bc 100644
--- a/src/python/grpcio/grpc/_adapter/_types.py
+++ b/src/python/grpcio/grpc/_adapter/_types.py
@@ -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.
"""
diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/call.pyx b/src/python/grpcio/grpc/_cython/_cygrpc/call.pyx
index ed037b660a..51c4668138 100644
--- a/src/python/grpcio/grpc/_cython/_cygrpc/call.pyx
+++ b/src/python/grpcio/grpc/_cython/_cygrpc/call.pyx
@@ -29,6 +29,7 @@
cimport cpython
+from grpc._cython._cygrpc cimport credentials
from grpc._cython._cygrpc cimport grpc
from grpc._cython._cygrpc cimport records
@@ -73,6 +74,11 @@ cdef class Call:
else:
return grpc.grpc_call_cancel(self.c_call, NULL)
+ def set_credentials(
+ self, credentials.CallCredentials call_credentials not None):
+ return grpc.grpc_call_set_credentials(
+ self.c_call, call_credentials.c_credentials)
+
def __dealloc__(self):
if self.c_call != NULL:
grpc.grpc_call_destroy(self.c_call)
diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/channel.pyx b/src/python/grpcio/grpc/_cython/_cygrpc/channel.pyx
index b52ddb6bcd..e25db3e2a4 100644
--- a/src/python/grpcio/grpc/_cython/_cygrpc/channel.pyx
+++ b/src/python/grpcio/grpc/_cython/_cygrpc/channel.pyx
@@ -37,7 +37,7 @@ from grpc._cython._cygrpc cimport records
cdef class Channel:
def __cinit__(self, target, records.ChannelArgs arguments=None,
- credentials.ClientCredentials client_credentials=None):
+ credentials.ChannelCredentials channel_credentials=None):
cdef grpc.grpc_channel_args *c_arguments = NULL
self.c_channel = NULL
self.references = []
@@ -49,13 +49,13 @@ cdef class Channel:
target = target.encode()
else:
raise TypeError("expected target to be str or bytes")
- if client_credentials is None:
+ if channel_credentials is None:
self.c_channel = grpc.grpc_insecure_channel_create(target, c_arguments,
NULL)
else:
self.c_channel = grpc.grpc_secure_channel_create(
- client_credentials.c_credentials, target, c_arguments, NULL)
- self.references.append(client_credentials)
+ channel_credentials.c_credentials, target, c_arguments, NULL)
+ self.references.append(channel_credentials)
self.references.append(target)
self.references.append(arguments)
diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/credentials.pxd b/src/python/grpcio/grpc/_cython/_cygrpc/credentials.pxd
index 6b74a267e0..7a9fa7b76d 100644
--- a/src/python/grpcio/grpc/_cython/_cygrpc/credentials.pxd
+++ b/src/python/grpcio/grpc/_cython/_cygrpc/credentials.pxd
@@ -30,13 +30,19 @@
from grpc._cython._cygrpc cimport grpc
-cdef class ClientCredentials:
+cdef class ChannelCredentials:
- cdef grpc.grpc_credentials *c_credentials
+ cdef grpc.grpc_channel_credentials *c_credentials
cdef grpc.grpc_ssl_pem_key_cert_pair c_ssl_pem_key_cert_pair
cdef list references
+cdef class CallCredentials:
+
+ cdef grpc.grpc_call_credentials *c_credentials
+ cdef list references
+
+
cdef class ServerCredentials:
cdef grpc.grpc_server_credentials *c_credentials
diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/credentials.pyx b/src/python/grpcio/grpc/_cython/_cygrpc/credentials.pyx
index 608207f0a2..e9836fec2c 100644
--- a/src/python/grpcio/grpc/_cython/_cygrpc/credentials.pyx
+++ b/src/python/grpcio/grpc/_cython/_cygrpc/credentials.pyx
@@ -31,7 +31,7 @@ from grpc._cython._cygrpc cimport grpc
from grpc._cython._cygrpc cimport records
-cdef class ClientCredentials:
+cdef class ChannelCredentials:
def __cinit__(self):
self.c_credentials = NULL
@@ -47,7 +47,24 @@ cdef class ClientCredentials:
def __dealloc__(self):
if self.c_credentials != NULL:
- grpc.grpc_credentials_release(self.c_credentials)
+ grpc.grpc_channel_credentials_release(self.c_credentials)
+
+
+cdef class CallCredentials:
+
+ def __cinit__(self):
+ self.c_credentials = NULL
+ self.references = []
+
+ # The object *can* be invalid in Python if we fail to make the credentials
+ # (and the core thus returns NULL credentials). Used primarily for debugging.
+ @property
+ def is_valid(self):
+ return self.c_credentials != NULL
+
+ def __dealloc__(self):
+ if self.c_credentials != NULL:
+ grpc.grpc_call_credentials_release(self.c_credentials)
cdef class ServerCredentials:
@@ -60,12 +77,12 @@ cdef class ServerCredentials:
grpc.grpc_server_credentials_release(self.c_credentials)
-def client_credentials_google_default():
- cdef ClientCredentials credentials = ClientCredentials();
+def channel_credentials_google_default():
+ cdef ChannelCredentials credentials = ChannelCredentials();
credentials.c_credentials = grpc.grpc_google_default_credentials_create()
return credentials
-def client_credentials_ssl(pem_root_certificates,
+def channel_credentials_ssl(pem_root_certificates,
records.SslPemKeyCertPair ssl_pem_key_cert_pair):
if pem_root_certificates is None:
pass
@@ -75,7 +92,7 @@ def client_credentials_ssl(pem_root_certificates,
pem_root_certificates = pem_root_certificates.encode()
else:
raise TypeError("expected str or bytes for pem_root_certificates")
- cdef ClientCredentials credentials = ClientCredentials()
+ cdef ChannelCredentials credentials = ChannelCredentials()
cdef const char *c_pem_root_certificates = NULL
if pem_root_certificates is not None:
c_pem_root_certificates = pem_root_certificates
@@ -88,26 +105,38 @@ def client_credentials_ssl(pem_root_certificates,
credentials.c_credentials = grpc.grpc_ssl_credentials_create(
c_pem_root_certificates, NULL, NULL)
-def client_credentials_composite_credentials(
- ClientCredentials credentials_1 not None,
- ClientCredentials credentials_2 not None):
+def channel_credentials_composite(
+ ChannelCredentials credentials_1 not None,
+ CallCredentials credentials_2 not None):
+ if not credentials_1.is_valid or not credentials_2.is_valid:
+ raise ValueError("passed credentials must both be valid")
+ cdef ChannelCredentials credentials = ChannelCredentials()
+ credentials.c_credentials = grpc.grpc_composite_channel_credentials_create(
+ credentials_1.c_credentials, credentials_2.c_credentials, NULL)
+ credentials.references.append(credentials_1)
+ credentials.references.append(credentials_2)
+ return credentials
+
+def call_credentials_composite(
+ CallCredentials credentials_1 not None,
+ CallCredentials credentials_2 not None):
if not credentials_1.is_valid or not credentials_2.is_valid:
raise ValueError("passed credentials must both be valid")
- cdef ClientCredentials credentials = ClientCredentials()
- credentials.c_credentials = grpc.grpc_composite_credentials_create(
+ cdef CallCredentials credentials = CallCredentials()
+ credentials.c_credentials = grpc.grpc_composite_call_credentials_create(
credentials_1.c_credentials, credentials_2.c_credentials, NULL)
credentials.references.append(credentials_1)
credentials.references.append(credentials_2)
return credentials
-def client_credentials_google_compute_engine():
- cdef ClientCredentials credentials = ClientCredentials()
+def call_credentials_google_compute_engine():
+ cdef CallCredentials credentials = CallCredentials()
credentials.c_credentials = (
grpc.grpc_google_compute_engine_credentials_create(NULL))
return credentials
#TODO rename to something like client_credentials_service_account_jwt_access.
-def client_credentials_service_account_jwt_access(
+def call_credentials_service_account_jwt_access(
json_key, records.Timespec token_lifetime not None):
if isinstance(json_key, bytes):
pass
@@ -115,27 +144,27 @@ def client_credentials_service_account_jwt_access(
json_key = json_key.encode()
else:
raise TypeError("expected json_key to be str or bytes")
- cdef ClientCredentials credentials = ClientCredentials()
+ cdef CallCredentials credentials = CallCredentials()
credentials.c_credentials = (
grpc.grpc_service_account_jwt_access_credentials_create(
json_key, token_lifetime.c_time, NULL))
credentials.references.append(json_key)
return credentials
-def client_credentials_google_refresh_token(json_refresh_token):
+def call_credentials_google_refresh_token(json_refresh_token):
if isinstance(json_refresh_token, bytes):
pass
elif isinstance(json_refresh_token, basestring):
json_refresh_token = json_refresh_token.encode()
else:
raise TypeError("expected json_refresh_token to be str or bytes")
- cdef ClientCredentials credentials = ClientCredentials()
+ cdef CallCredentials credentials = CallCredentials()
credentials.c_credentials = grpc.grpc_google_refresh_token_credentials_create(
json_refresh_token, NULL)
credentials.references.append(json_refresh_token)
return credentials
-def client_credentials_google_iam(authorization_token, authority_selector):
+def call_credentials_google_iam(authorization_token, authority_selector):
if isinstance(authorization_token, bytes):
pass
elif isinstance(authorization_token, basestring):
@@ -148,7 +177,7 @@ def client_credentials_google_iam(authorization_token, authority_selector):
authority_selector = authority_selector.encode()
else:
raise TypeError("expected authority_selector to be str or bytes")
- cdef ClientCredentials credentials = ClientCredentials()
+ cdef CallCredentials credentials = CallCredentials()
credentials.c_credentials = grpc.grpc_google_iam_credentials_create(
authorization_token, authority_selector, NULL)
credentials.references.append(authorization_token)
diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/grpc.pxd b/src/python/grpcio/grpc/_cython/_cygrpc/grpc.pxd
index 62d40e7a58..36aea81a6c 100644
--- a/src/python/grpcio/grpc/_cython/_cygrpc/grpc.pxd
+++ b/src/python/grpcio/grpc/_cython/_cygrpc/grpc.pxd
@@ -316,32 +316,40 @@ cdef extern from "grpc/grpc_security.h":
const char *private_key
const char *certificate_chain "cert_chain"
- ctypedef struct grpc_credentials:
+ ctypedef struct grpc_channel_credentials:
# We don't care about the internals (and in fact don't know them)
pass
- grpc_credentials *grpc_google_default_credentials_create()
- grpc_credentials *grpc_ssl_credentials_create(
+ ctypedef struct grpc_call_credentials:
+ # We don't care about the internals (and in fact don't know them)
+ pass
+
+ grpc_channel_credentials *grpc_google_default_credentials_create()
+ grpc_channel_credentials *grpc_ssl_credentials_create(
const char *pem_root_certs, grpc_ssl_pem_key_cert_pair *pem_key_cert_pair,
void *reserved)
+ grpc_channel_credentials *grpc_composite_channel_credentials_create(
+ grpc_channel_credentials *creds1, grpc_call_credentials *creds2,
+ void *reserved)
+ void grpc_channel_credentials_release(grpc_channel_credentials *creds)
- grpc_credentials *grpc_composite_credentials_create(grpc_credentials *creds1,
- grpc_credentials *creds2,
- void *reserved)
- grpc_credentials *grpc_google_compute_engine_credentials_create(
+ grpc_call_credentials *grpc_composite_call_credentials_create(
+ grpc_call_credentials *creds1, grpc_call_credentials *creds2,
+ void *reserved)
+ grpc_call_credentials *grpc_google_compute_engine_credentials_create(
void *reserved)
- grpc_credentials *grpc_service_account_jwt_access_credentials_create(
+ grpc_call_credentials *grpc_service_account_jwt_access_credentials_create(
const char *json_key,
gpr_timespec token_lifetime, void *reserved)
- grpc_credentials *grpc_google_refresh_token_credentials_create(
+ grpc_call_credentials *grpc_google_refresh_token_credentials_create(
const char *json_refresh_token, void *reserved)
- grpc_credentials *grpc_google_iam_credentials_create(
+ grpc_call_credentials *grpc_google_iam_credentials_create(
const char *authorization_token, const char *authority_selector,
void *reserved)
- void grpc_credentials_release(grpc_credentials *creds)
+ void grpc_call_credentials_release(grpc_call_credentials *creds)
grpc_channel *grpc_secure_channel_create(
- grpc_credentials *creds, const char *target,
+ grpc_channel_credentials *creds, const char *target,
const grpc_channel_args *args, void *reserved)
ctypedef struct grpc_server_credentials:
@@ -358,4 +366,4 @@ cdef extern from "grpc/grpc_security.h":
grpc_server_credentials *creds)
grpc_call_error grpc_call_set_credentials(grpc_call *call,
- grpc_credentials *creds)
+ grpc_call_credentials *creds)
diff --git a/src/python/grpcio/grpc/_cython/cygrpc.pyx b/src/python/grpcio/grpc/_cython/cygrpc.pyx
index 1ef2997db5..b20dda8a95 100644
--- a/src/python/grpcio/grpc/_cython/cygrpc.pyx
+++ b/src/python/grpcio/grpc/_cython/cygrpc.pyx
@@ -70,21 +70,24 @@ operation_receive_close_on_server = records.operation_receive_close_on_server
Operations = records.Operations
-ClientCredentials = credentials.ClientCredentials
+CallCredentials = credentials.CallCredentials
+ChannelCredentials = credentials.ChannelCredentials
ServerCredentials = credentials.ServerCredentials
-client_credentials_google_default = (
- credentials.client_credentials_google_default)
-client_credentials_ssl = credentials.client_credentials_ssl
-client_credentials_composite_credentials = (
- credentials.client_credentials_composite_credentials)
-client_credentials_google_compute_engine = (
- credentials.client_credentials_google_compute_engine)
-client_credentials_jwt_access = (
- credentials.client_credentials_service_account_jwt_access)
-client_credentials_refresh_token = (
- credentials.client_credentials_google_refresh_token)
-client_credentials_google_iam = credentials.client_credentials_google_iam
+channel_credentials_google_default = (
+ credentials.channel_credentials_google_default)
+channel_credentials_ssl = credentials.channel_credentials_ssl
+channel_credentials_composite = (
+ credentials.channel_credentials_composite)
+call_credentials_composite = (
+ credentials.call_credentials_composite)
+call_credentials_google_compute_engine = (
+ credentials.call_credentials_google_compute_engine)
+call_credentials_jwt_access = (
+ credentials.call_credentials_service_account_jwt_access)
+call_credentials_refresh_token = (
+ credentials.call_credentials_google_refresh_token)
+call_credentials_google_iam = credentials.call_credentials_google_iam
server_credentials_ssl = credentials.server_credentials_ssl
CompletionQueue = completion_queue.CompletionQueue
diff --git a/src/python/grpcio/grpc/beta/interfaces.py b/src/python/grpcio/grpc/beta/interfaces.py
index 07c8618f70..d4ca56500f 100644
--- a/src/python/grpcio/grpc/beta/interfaces.py
+++ b/src/python/grpcio/grpc/beta/interfaces.py
@@ -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)
diff --git a/src/python/grpcio/setup.py b/src/python/grpcio/setup.py
index 97fa4fe6b3..ec68eb6755 100644
--- a/src/python/grpcio/setup.py
+++ b/src/python/grpcio/setup.py
@@ -52,7 +52,8 @@ _C_EXTENSION_SOURCES = (
'grpc/_adapter/_c/module.c',
'grpc/_adapter/_c/types.c',
'grpc/_adapter/_c/utility.c',
- 'grpc/_adapter/_c/types/client_credentials.c',
+ 'grpc/_adapter/_c/types/call_credentials.c',
+ 'grpc/_adapter/_c/types/channel_credentials.c',
'grpc/_adapter/_c/types/server_credentials.c',
'grpc/_adapter/_c/types/completion_queue.c',
'grpc/_adapter/_c/types/call.c',
diff --git a/src/python/grpcio_test/grpc_test/beta/_beta_features_test.py b/src/python/grpcio_test/grpc_test/beta/_beta_features_test.py
index fad57da9d0..5916a9e3ea 100644
--- a/src/python/grpcio_test/grpc_test/beta/_beta_features_test.py
+++ b/src/python/grpcio_test/grpc_test/beta/_beta_features_test.py
@@ -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,