From 6d2ef17f30228e43223c7a10cff3228e943f2bf2 Mon Sep 17 00:00:00 2001 From: Masood Malekghassemi Date: Mon, 4 Jan 2016 15:33:17 -0800 Subject: [PATCH] Use default gRPC roots.pem if none provided --- PYTHON-MANIFEST.in | 1 + setup.py | 12 ++++++++++++ src/python/grpcio/.gitignore | 1 + src/python/grpcio/commands.py | 2 ++ src/python/grpcio/grpc/_adapter/_low.py | 5 +++++ 5 files changed, 21 insertions(+) diff --git a/PYTHON-MANIFEST.in b/PYTHON-MANIFEST.in index 5b4ab04207a72..0208a88ab14c0 100644 --- a/PYTHON-MANIFEST.in +++ b/PYTHON-MANIFEST.in @@ -6,3 +6,4 @@ include src/python/grpcio/commands.py include src/python/grpcio/grpc_core_dependencies.py include src/python/grpcio/README.rst include requirements.txt +include etc/roots.pem diff --git a/setup.py b/setup.py index 646c01342c6ce..436db7dd46520 100644 --- a/setup.py +++ b/setup.py @@ -31,6 +31,7 @@ import os import os.path +import shutil import sys from distutils import core as _core @@ -130,6 +131,14 @@ def cython_extensions(package_names, module_names, include_dirs, libraries, 'run_interop': commands.RunInterop, } +# Ensure that package data is copied over before any commands have been run: +credentials_dir = os.path.join(PYTHON_STEM, 'grpc/_adapter/credentials') +try: + os.mkdir(credentials_dir) +except OSError: + pass +shutil.copyfile('etc/roots.pem', os.path.join(credentials_dir, 'roots.pem')) + TEST_PACKAGE_DATA = { 'tests.interop': [ 'credentials/ca.pem', @@ -144,6 +153,9 @@ def cython_extensions(package_names, module_names, include_dirs, libraries, 'credentials/server1.key', 'credentials/server1.pem', ], + 'grpc._adapter': [ + 'credentials/roots.pem' + ], } TESTS_REQUIRE = ( diff --git a/src/python/grpcio/.gitignore b/src/python/grpcio/.gitignore index 95b96f7c1e9f7..1d804e1ffc8f5 100644 --- a/src/python/grpcio/.gitignore +++ b/src/python/grpcio/.gitignore @@ -14,3 +14,4 @@ nosetests.xml doc/ _grpcio_metadata.py htmlcov/ +grpc/_adapter/credentials diff --git a/src/python/grpcio/commands.py b/src/python/grpcio/commands.py index 4b172142b1e79..5497311405f5a 100644 --- a/src/python/grpcio/commands.py +++ b/src/python/grpcio/commands.py @@ -156,6 +156,8 @@ class BuildPy(build_py.build_py): """Custom project build command.""" def run(self): + # TODO(atash): make this warn if the proto modules couldn't be built rather + # than cause build failure self.run_command('build_proto_modules') self.run_command('build_project_metadata') build_py.build_py.run(self) diff --git a/src/python/grpcio/grpc/_adapter/_low.py b/src/python/grpcio/grpc/_adapter/_low.py index b13d8dd9dda1f..dd3669f66c9f6 100644 --- a/src/python/grpcio/grpc/_adapter/_low.py +++ b/src/python/grpcio/grpc/_adapter/_low.py @@ -27,6 +27,7 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +import pkg_resources import threading from grpc import _grpcio_metadata @@ -34,6 +35,7 @@ from grpc._adapter import _implementations from grpc._adapter import _types +_ROOT_CERTIFICATES_RESOURCE_PATH = 'credentials/roots.pem' _USER_AGENT = 'Python-gRPC-{}'.format(_grpcio_metadata.__version__) ChannelCredentials = cygrpc.ChannelCredentials @@ -54,6 +56,9 @@ def channel_credentials_ssl( pair = None if private_key is not None or certificate_chain is not None: pair = cygrpc.SslPemKeyCertPair(private_key, certificate_chain) + if root_certificates is None: + root_certificates = pkg_resources.resource_string( + __name__, _ROOT_CERTIFICATES_RESOURCE_PATH) return cygrpc.channel_credentials_ssl(root_certificates, pair)