Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
75 lines (71 sloc) 2.67 KB
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..b65edd2
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,8 @@
+export PYTHONPATH=../../pkgs/lib64/python:../../pkgs/lib/python
+
+install:
+ ./setup.py install --home ../../pkgs
+
+clean:
+ git reset --hard
+ git clean -f
diff --git a/pymongo/connection.py b/pymongo/connection.py
index 59710d8..6a9f565 100644
--- a/pymongo/connection.py
+++ b/pymongo/connection.py
@@ -40,6 +40,7 @@ import os
import random
import socket
import struct
+import ssl
import sys
import threading
import warnings
@@ -59,6 +60,23 @@ from pymongo.son import SON
_CONNECT_TIMEOUT = 20.0
+try:
+ from pylons import config
+ _MONGODB_CA = config['mongodb.ca']
+ _MONGODB_CERT = config['mongodb.cert']
+ _MONGODB_KEY = config['mongodb.key']
+except ImportError:
+ _MONGODB_CA = os.environ['MONGODB_CA']
+ _MONGODB_CERT = os.environ['MONGODB_CERT']
+ _MONGODB_KEY = os.environ['MONGODB_KEY']
+
+if not os.path.exists(_MONGODB_CA):
+ print 'Warning: missing mongodb ca file %s' % _MONGODB_CA
+elif not os.path.exists(_MONGODB_CERT):
+ print 'Warning: missing mongodb cert file %s' % _MONGODB_CERT
+elif not os.path.exists(_MONGODB_KEY):
+ print 'Warning: missing mongodb key file %s' % _MONGODB_KEY
+
class Pool(threading.local):
"""A simple connection pool.
@@ -438,6 +456,11 @@ class Connection(object): # TODO support auth for pooling
sock = socket.socket()
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
sock.settimeout(_CONNECT_TIMEOUT)
+ sock = ssl.wrap_socket(sock,
+ ca_certs=_MONGODB_CA,
+ cert_reqs=ssl.CERT_REQUIRED,
+ certfile=_MONGODB_CERT,
+ keyfile=_MONGODB_KEY)
sock.connect((host, port))
sock.settimeout(self.__network_timeout)
master = self.__master(sock)
@@ -468,6 +491,11 @@ class Connection(object): # TODO support auth for pooling
sock = socket.socket()
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
sock.settimeout(_CONNECT_TIMEOUT)
+ sock = ssl.wrap_socket(sock,
+ ca_certs=_MONGODB_CA,
+ cert_reqs=ssl.CERT_REQUIRED,
+ certfile=_MONGODB_CERT,
+ keyfile=_MONGODB_KEY)
sock.connect((self.__host, self.__port))
sock.settimeout(self.__network_timeout)
return sock