settings.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. """
  2. Django settings for desecapi project.
  3. For more information on this file, see
  4. https://docs.djangoproject.com/en/1.7/topics/settings/
  5. For the full list of settings and their values, see
  6. https://docs.djangoproject.com/en/1.7/ref/settings/
  7. """
  8. # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
  9. import os
  10. from datetime import timedelta
  11. BASE_DIR = os.path.dirname(os.path.dirname(__file__))
  12. # Quick-start development settings - unsuitable for production
  13. # See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/
  14. # SECURITY WARNING: keep the secret key used in production secret!
  15. SECRET_KEY = os.environ['DESECSTACK_API_SECRETKEY']
  16. # SECURITY WARNING: don't run with debug turned on in production!
  17. DEBUG = False
  18. if os.environ.get('DESECSTACK_API_DEBUG', "").upper() == "TRUE":
  19. DEBUG = True
  20. ALLOWED_HOSTS = [
  21. 'api',
  22. 'desec.%s' % os.environ['DESECSTACK_DOMAIN'],
  23. 'update.dedyn.%s' % os.environ['DESECSTACK_DOMAIN'],
  24. 'update6.dedyn.%s' % os.environ['DESECSTACK_DOMAIN'],
  25. ]
  26. # Application definition
  27. INSTALLED_APPS = (
  28. 'django.contrib.auth',
  29. 'django.contrib.contenttypes',
  30. 'rest_framework',
  31. 'desecapi',
  32. 'corsheaders',
  33. )
  34. MIDDLEWARE = (
  35. 'corsheaders.middleware.CorsMiddleware',
  36. 'django.middleware.common.CommonMiddleware',
  37. 'django.middleware.csrf.CsrfViewMiddleware',
  38. )
  39. ROOT_URLCONF = 'api.urls'
  40. WSGI_APPLICATION = 'desecapi.wsgi.application'
  41. DATABASES = {
  42. 'default': {
  43. 'ENGINE': 'django.db.backends.mysql',
  44. 'NAME': 'desec',
  45. 'USER': 'desec',
  46. 'PASSWORD': os.environ['DESECSTACK_DBAPI_PASSWORD_desec'],
  47. 'HOST': 'dbapi',
  48. 'OPTIONS': {
  49. 'charset': 'utf8mb4',
  50. 'init_command': "SET sql_mode='STRICT_TRANS_TABLES'",
  51. },
  52. 'TEST': {
  53. 'CHARSET': 'utf8mb4',
  54. 'COLLATION': 'utf8mb4_bin',
  55. },
  56. },
  57. }
  58. # This is necessary because the default is America/Chicago
  59. TIME_ZONE = 'UTC'
  60. USE_TZ = True
  61. REST_FRAMEWORK = {
  62. 'DEFAULT_RENDERER_CLASSES': (
  63. 'rest_framework.renderers.JSONRenderer',
  64. ),
  65. 'DEFAULT_PARSER_CLASSES': (
  66. 'rest_framework.parsers.JSONParser',
  67. ),
  68. 'DEFAULT_AUTHENTICATION_CLASSES': (
  69. 'desecapi.authentication.TokenAuthentication',
  70. ),
  71. 'TEST_REQUEST_DEFAULT_FORMAT': 'json',
  72. 'EXCEPTION_HANDLER': 'desecapi.exception_handlers.exception_handler',
  73. 'DEFAULT_VERSIONING_CLASS': 'rest_framework.versioning.NamespaceVersioning',
  74. 'ALLOWED_VERSIONS': ['v1', 'v2'],
  75. }
  76. # CORS
  77. # No need to add Authorization to CORS_ALLOW_HEADERS (included by default)
  78. CORS_ORIGIN_ALLOW_ALL = True
  79. TEMPLATES = [
  80. {
  81. 'BACKEND': 'django.template.backends.django.DjangoTemplates',
  82. 'DIRS': [],
  83. 'APP_DIRS': True,
  84. 'OPTIONS': {
  85. 'context_processors': [
  86. 'django.template.context_processors.debug',
  87. 'django.template.context_processors.request',
  88. 'django.contrib.auth.context_processors.auth',
  89. 'django.contrib.messages.context_processors.messages',
  90. ],
  91. },
  92. },
  93. ]
  94. # How and where to send mail
  95. EMAIL_HOST = os.environ['DESECSTACK_API_EMAIL_HOST']
  96. EMAIL_HOST_USER = os.environ['DESECSTACK_API_EMAIL_HOST_USER']
  97. EMAIL_HOST_PASSWORD = os.environ['DESECSTACK_API_EMAIL_HOST_PASSWORD']
  98. EMAIL_PORT = os.environ['DESECSTACK_API_EMAIL_PORT']
  99. EMAIL_USE_TLS = True
  100. DEFAULT_FROM_EMAIL = 'deSEC <support@desec.io>'
  101. ADMINS = [(address.split("@")[0], address) for address in os.environ['DESECSTACK_API_ADMIN'].split()]
  102. # default NS records
  103. DEFAULT_NS = [name + '.' for name in os.environ['DESECSTACK_NS'].strip().split()]
  104. DEFAULT_NS_TTL = os.environ['DESECSTACK_NSLORD_DEFAULT_TTL']
  105. # Public Suffix settings
  106. PSL_RESOLVER = os.environ.get('DESECSTACK_API_PSL_RESOLVER')
  107. LOCAL_PUBLIC_SUFFIXES = {'dedyn.%s' % os.environ['DESECSTACK_DOMAIN']}
  108. # PowerDNS API access
  109. NSLORD_PDNS_API = 'http://nslord:8081/api/v1/servers/localhost'
  110. NSLORD_PDNS_API_TOKEN = os.environ['DESECSTACK_NSLORD_APIKEY']
  111. NSMASTER_PDNS_API = 'http://nsmaster:8081/api/v1/servers/localhost'
  112. NSMASTER_PDNS_API_TOKEN = os.environ['DESECSTACK_NSMASTER_APIKEY']
  113. # pdns accepts request payloads of this size.
  114. # This will hopefully soon be configurable: https://github.com/PowerDNS/pdns/pull/7550
  115. PDNS_MAX_BODY_SIZE = 2 * 1024 * 1024
  116. # SEPA direct debit settings
  117. SEPA = {
  118. 'CREDITOR_ID': os.environ['DESECSTACK_API_SEPA_CREDITOR_ID'],
  119. 'CREDITOR_NAME': os.environ['DESECSTACK_API_SEPA_CREDITOR_NAME'],
  120. }
  121. # user management
  122. MINIMUM_TTL_DEFAULT = int(os.environ['DESECSTACK_MINIMUM_TTL_DEFAULT'])
  123. AUTH_USER_MODEL = 'desecapi.User'
  124. LIMIT_USER_DOMAIN_COUNT_DEFAULT = 5
  125. USER_ACTIVATION_REQUIRED = True
  126. VALIDITY_PERIOD_VERIFICATION_SIGNATURE = timedelta(hours=12)
  127. # CAPTCHA
  128. CAPTCHA_VALIDITY_PERIOD = timedelta(hours=24)
  129. if DEBUG and not EMAIL_HOST:
  130. EMAIL_BACKEND = 'django.core.mail.backends.dummy.EmailBackend'
  131. if os.environ.get('DESECSTACK_E2E_TEST', "").upper() == "TRUE":
  132. DEBUG = True
  133. LIMIT_USER_DOMAIN_COUNT_DEFAULT = 5000
  134. USER_ACTIVATION_REQUIRED = False
  135. EMAIL_BACKEND = 'django.core.mail.backends.dummy.EmailBackend'