Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

__init__.py 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # -*- coding: utf-8 -*-
  2. """
  3. celery.security
  4. ~~~~~~~~~~~~~~~
  5. Module implementing the signing message serializer.
  6. """
  7. from __future__ import absolute_import
  8. from kombu.serialization import (
  9. registry, disable_insecure_serializers as _disable_insecure_serializers,
  10. )
  11. from celery.exceptions import ImproperlyConfigured
  12. from .serialization import register_auth
  13. SSL_NOT_INSTALLED = """\
  14. You need to install the pyOpenSSL library to use the auth serializer.
  15. Please install by:
  16. $ pip install pyOpenSSL
  17. """
  18. SETTING_MISSING = """\
  19. Sorry, but you have to configure the
  20. * CELERY_SECURITY_KEY
  21. * CELERY_SECURITY_CERTIFICATE, and the
  22. * CELERY_SECURITY_CERT_STORE
  23. configuration settings to use the auth serializer.
  24. Please see the configuration reference for more information.
  25. """
  26. __all__ = ['setup_security']
  27. def setup_security(allowed_serializers=None, key=None, cert=None, store=None,
  28. digest='sha1', serializer='json', app=None):
  29. """See :meth:`@Celery.setup_security`."""
  30. if app is None:
  31. from celery import current_app
  32. app = current_app._get_current_object()
  33. _disable_insecure_serializers(allowed_serializers)
  34. conf = app.conf
  35. if conf.CELERY_TASK_SERIALIZER != 'auth':
  36. return
  37. try:
  38. from OpenSSL import crypto # noqa
  39. except ImportError:
  40. raise ImproperlyConfigured(SSL_NOT_INSTALLED)
  41. key = key or conf.CELERY_SECURITY_KEY
  42. cert = cert or conf.CELERY_SECURITY_CERTIFICATE
  43. store = store or conf.CELERY_SECURITY_CERT_STORE
  44. if not (key and cert and store):
  45. raise ImproperlyConfigured(SETTING_MISSING)
  46. with open(key) as kf:
  47. with open(cert) as cf:
  48. register_auth(kf.read(), cf.read(), store, digest, serializer)
  49. registry._set_default_serializer('auth')
  50. def disable_untrusted_serializers(whitelist=None):
  51. _disable_insecure_serializers(allowed=whitelist)