Skip to content

Commit

Permalink
Use default gRPC roots.pem if none provided
Browse files Browse the repository at this point in the history
  • Loading branch information
soltanmm committed Jan 11, 2016
1 parent ccc1610 commit 6d2ef17
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions PYTHON-MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 12 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

import os
import os.path
import shutil
import sys

from distutils import core as _core
Expand Down Expand Up @@ -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',
Expand All @@ -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 = (
Expand Down
1 change: 1 addition & 0 deletions src/python/grpcio/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ nosetests.xml
doc/
_grpcio_metadata.py
htmlcov/
grpc/_adapter/credentials
2 changes: 2 additions & 0 deletions src/python/grpcio/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions src/python/grpcio/grpc/_adapter/_low.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@
# (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
from grpc._cython import cygrpc
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
Expand All @@ -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)


Expand Down

0 comments on commit 6d2ef17

Please sign in to comment.