diff --git a/swh/web/manage.py b/swh/web/manage.py old mode 100644 new mode 100755 index 5450cc49..20f896ed --- a/swh/web/manage.py +++ b/swh/web/manage.py @@ -1,36 +1,37 @@ #!/usr/bin/env python # Copyright (C) 2017 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information import os import sys from swh.web import config if __name__ == "__main__": - os.environ.setdefault("DJANGO_SETTINGS_MODULE", "swh.web.settings") + os.environ.setdefault("DJANGO_SETTINGS_MODULE", + "swh.web.settings.development") try: from django.core.management.commands.runserver import ( Command as runserver ) from django.core.management import execute_from_command_line except ImportError: # The above import may fail for some other reason. Ensure that the # issue is really that Django is missing to avoid masking other # exceptions on Python 2. try: import django # noqa except ImportError: raise ImportError( "Couldn't import Django. Are you sure it's installed and " "available on your PYTHONPATH environment variable? Did you " "forget to activate a virtual environment?" ) raise swh_web_config = config.get_config() runserver.default_port = swh_web_config['port'] runserver.default_addr = swh_web_config['host'] execute_from_command_line(sys.argv) diff --git a/swh/web/settings.py b/swh/web/settings/common.py similarity index 99% rename from swh/web/settings.py rename to swh/web/settings/common.py index ec0df993..de0c58ff 100644 --- a/swh/web/settings.py +++ b/swh/web/settings/common.py @@ -1,185 +1,185 @@ # Copyright (C) 2017 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information """ Django settings for swhweb project. Generated by 'django-admin startproject' using Django 1.11.3. For more information on this file, see https://docs.djangoproject.com/en/1.11/topics/settings/ For the full list of settings and their values, see https://docs.djangoproject.com/en/1.11/ref/settings/ """ import os from swh.web.config import get_config swh_web_config = get_config() # Build paths inside the project like this: os.path.join(BASE_DIR, ...) PROJECT_DIR = os.path.dirname(os.path.abspath(__file__)) # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = swh_web_config['secret_key'] # SECURITY WARNING: don't run with debug turned on in production! DEBUG = swh_web_config['debug'] ALLOWED_HOSTS = ['127.0.0.1', 'localhost', 'testserver'] # Application definition INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'rest_framework', 'swh.web.api' ] MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', ] ROOT_URLCONF = 'swh.web.urls' TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', ], }, }, ] WSGI_APPLICATION = 'swh.web.wsgi.application' # Database # https://docs.djangoproject.com/en/1.11/ref/settings/#databases DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(PROJECT_DIR, 'db.sqlite3'), } } # Password validation # https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators AUTH_PASSWORD_VALIDATORS = [ { 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', # noqa }, { 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', # noqa }, { 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', # noqa }, { 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', # noqa }, ] # Internationalization # https://docs.djangoproject.com/en/1.11/topics/i18n/ LANGUAGE_CODE = 'en-us' TIME_ZONE = 'UTC' USE_I18N = True USE_L10N = True USE_TZ = True # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/1.11/howto/static-files/ STATIC_URL = '/static/' STATICFILES_DIRS = [ - os.path.join(PROJECT_DIR, "static") + os.path.join(PROJECT_DIR, "../static") ] INTERNAL_IPS = ['127.0.0.1'] throttle_rates = {} for limiter_scope, limiter_conf in swh_web_config['limiters'].items(): throttle_rates[limiter_scope] = None if DEBUG else limiter_conf['limiter_rate'] # noqa REST_FRAMEWORK = { 'DEFAULT_RENDERER_CLASSES': ( 'rest_framework.renderers.JSONRenderer', 'swh.web.api.renderers.YAMLRenderer', 'rest_framework.renderers.TemplateHTMLRenderer' ), 'DEFAULT_THROTTLE_CLASSES': ( 'swh.web.common.throttling.SwhWebRateThrottle', ), 'DEFAULT_THROTTLE_RATES': throttle_rates } LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'filters': { 'require_debug_false': { '()': 'django.utils.log.RequireDebugFalse', }, 'require_debug_true': { '()': 'django.utils.log.RequireDebugTrue', }, }, 'handlers': { 'console': { 'level': 'INFO', 'filters': ['require_debug_true'], 'class': 'logging.StreamHandler', }, 'file': { 'level': 'DEBUG', 'filters': ['require_debug_false'], 'class': 'logging.FileHandler', 'filename': os.path.join(swh_web_config['log_dir'], 'swh-web.log'), }, }, 'loggers': { 'django': { 'handlers': ['console', 'file'], 'level': 'DEBUG', 'propagate': True, }, }, } SILENCED_SYSTEM_CHECKS = ['1_7.W001'] diff --git a/swh/web/settings/development.py b/swh/web/settings/development.py new file mode 100644 index 00000000..eb931812 --- /dev/null +++ b/swh/web/settings/development.py @@ -0,0 +1,7 @@ +# Copyright (C) 2017 The Software Heritage developers +# See the AUTHORS file at the top-level directory of this distribution +# License: GNU General Public License version 3, or any later version +# See top-level LICENSE file for more information + + +from .common import * # noqa diff --git a/swh/web/settings/production.py b/swh/web/settings/production.py new file mode 100644 index 00000000..0db60fc1 --- /dev/null +++ b/swh/web/settings/production.py @@ -0,0 +1,14 @@ +# Copyright (C) 2017 The Software Heritage developers +# See the AUTHORS file at the top-level directory of this distribution +# License: GNU General Public License version 3, or any later version +# See top-level LICENSE file for more information + + +from .common import * # noqa + +CACHES = { + 'default': { + 'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache', + 'LOCATION': '127.0.0.1:11211', + } +} diff --git a/swh/web/tests/__init__.py b/swh/web/tests/__init__.py index 192d02d7..419b42ff 100644 --- a/swh/web/tests/__init__.py +++ b/swh/web/tests/__init__.py @@ -1,33 +1,34 @@ # Copyright (C) 2017 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information import os import django from swh.web.config import get_config swh_web_config = get_config() swh_web_config['debug'] = False +swh_web_config['secret_key'] = 'test' swh_web_config['limiters'] = { 'swh_api': { 'limiter_rate': '60/min', 'exempted_networks': ['127.0.0.0/8'] }, 'scope1': { 'limiter_rate': '3/min' }, 'scope2': { 'limiter_rate': '5/min', 'exempted_networks': ['127.0.0.0/8'] } } -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "swh.web.settings") +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "swh.web.settings.development") django.setup() scope1_limiter_rate = 3 scope2_limiter_rate = 5 diff --git a/swh/web/wsgi.py b/swh/web/wsgi.py index 14abb39c..5177b9ac 100644 --- a/swh/web/wsgi.py +++ b/swh/web/wsgi.py @@ -1,21 +1,21 @@ # Copyright (C) 2017 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information """ WSGI config for swhweb project. It exposes the WSGI callable as a module-level variable named ``application``. For more information on this file, see https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/ """ import os from django.core.wsgi import get_wsgi_application -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "swh.web.settings") +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "swh.web.settings.production") application = get_wsgi_application()