Explorar el Código

pyOpenSSL is optional

mher hace 14 años
padre
commit
9fd82f973d
Se han modificado 3 ficheros con 19 adiciones y 6 borrados
  1. 7 0
      celery/security/__init__.py
  2. 6 3
      celery/security/certificate.py
  3. 6 3
      celery/security/key.py

+ 7 - 0
celery/security/__init__.py

@@ -17,6 +17,13 @@ def setup_security():
     if conf.CELERY_TASK_SERIALIZER != 'auth':
     if conf.CELERY_TASK_SERIALIZER != 'auth':
         return
         return
 
 
+    try:
+        from OpenSSL import crypto
+    except ImportError:
+        raise ImproperlyConfigured(
+            "You need to install pyOpenSSL library to use "
+            "the auth serializer.")
+
     key = getattr(conf, 'CELERY_SECURITY_KEY', None)
     key = getattr(conf, 'CELERY_SECURITY_KEY', None)
     cert = getattr(conf, 'CELERY_SECURITY_CERTIFICATE', None)
     cert = getattr(conf, 'CELERY_SECURITY_CERTIFICATE', None)
     store = getattr(conf, 'CELERY_SECURITY_CERT_STORE', None)
     store = getattr(conf, 'CELERY_SECURITY_CERT_STORE', None)

+ 6 - 3
celery/security/certificate.py

@@ -1,16 +1,19 @@
 import os
 import os
 import glob
 import glob
 
 
-from OpenSSL import crypto
-from OpenSSL.crypto import FILETYPE_PEM
+try:
+    from OpenSSL import crypto
+except ImportError:
+    crypto = None
 
 
 from celery.security.exceptions import SecurityError
 from celery.security.exceptions import SecurityError
 
 
 class Certificate(object):
 class Certificate(object):
     """X.509 certificate"""
     """X.509 certificate"""
     def __init__(self, cert):
     def __init__(self, cert):
+        assert crypto is not None
         try:
         try:
-            self._cert = crypto.load_certificate(FILETYPE_PEM, cert)
+            self._cert = crypto.load_certificate(crypto.FILETYPE_PEM, cert)
         except crypto.Error, e:
         except crypto.Error, e:
             raise SecurityError("Invalid certificate", e)
             raise SecurityError("Invalid certificate", e)
 
 

+ 6 - 3
celery/security/key.py

@@ -1,12 +1,15 @@
-from OpenSSL import crypto
-from OpenSSL.crypto import FILETYPE_PEM
+try:
+    from OpenSSL import crypto
+except ImportError:
+    crypto = None
 
 
 from celery.security.exceptions import SecurityError
 from celery.security.exceptions import SecurityError
 
 
 class PrivateKey(object):
 class PrivateKey(object):
     def __init__(self, key):
     def __init__(self, key):
+        assert crypto is not None
         try:
         try:
-            self._key = crypto.load_privatekey(FILETYPE_PEM, key)
+            self._key = crypto.load_privatekey(crypto.FILETYPE_PEM, key)
         except crypto.Error, e:
         except crypto.Error, e:
             raise SecurityError("Invalid private key", e)
             raise SecurityError("Invalid private key", e)