Port example Django app to Django 1.10
This commit is contained in:
		
							parent
							
								
									c267dc4f9d
								
							
						
					
					
						commit
						df37b84d6f
					
				| 
						 | 
					@ -1,14 +0,0 @@
 | 
				
			||||||
rabbitmq_auth_backend_django is a very very simple Django application
 | 
					 | 
				
			||||||
that rabbitmq-auth-backend-http can authenticate against. It's really
 | 
					 | 
				
			||||||
not designed to be anything other than an example.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
Run start.sh to launch it after installing Django somehow (e.g. sudo
 | 
					 | 
				
			||||||
apt-get install python-django). You may need to hack start.sh if you
 | 
					 | 
				
			||||||
are not running Debian / Ubuntu.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
The app will create a SQLite database in /tmp/. It uses the standard
 | 
					 | 
				
			||||||
Django authentication database. All users get access to all vhosts and
 | 
					 | 
				
			||||||
resources.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
If you're not familiar with Django, urls.py and auth/views.py may be
 | 
					 | 
				
			||||||
most illuminating.
 | 
					 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,19 @@
 | 
				
			||||||
 | 
					# RabbitMQ HTTP Authn/Authz Backend Example
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					`rabbitmq_auth_backend_django` is a very minimalistic [Django](https://www.djangoproject.com/) 1.10+ application
 | 
				
			||||||
 | 
					that rabbitmq-auth-backend-http can authenticate against. It's really
 | 
				
			||||||
 | 
					not designed to be anything other than an example.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## Running the Example
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Run `start.sh` to launch it after [installing Django](https://docs.djangoproject.com/en/1.10/topics/install/). You may need to
 | 
				
			||||||
 | 
					hack `start.sh` if you are not running Debian or Ubuntu.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					The app will use a local SQLite database. It uses the standard
 | 
				
			||||||
 | 
					Django authentication database. All users get access to all vhosts and
 | 
				
			||||||
 | 
					resources.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## HTTP Endpoint Examples
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					If you're not familiar with Django, urls.py and auth/views.py may be
 | 
				
			||||||
 | 
					most illuminating.
 | 
				
			||||||
							
								
								
									
										1
									
								
								deps/rabbitmq_auth_backend_http/examples/rabbitmq_auth_backend_django/.gitignore
								
								
								
									vendored
								
								
									Normal file
								
							
							
						
						
									
										1
									
								
								deps/rabbitmq_auth_backend_http/examples/rabbitmq_auth_backend_django/.gitignore
								
								
								
									vendored
								
								
									Normal file
								
							| 
						 | 
					@ -0,0 +1 @@
 | 
				
			||||||
 | 
					*.sqlite3
 | 
				
			||||||
							
								
								
									
										18
									
								
								deps/rabbitmq_auth_backend_http/examples/rabbitmq_auth_backend_django/manage.py
								
								
								
									vendored
								
								
									
									
									Normal file → Executable file
								
							
							
						
						
									
										18
									
								
								deps/rabbitmq_auth_backend_http/examples/rabbitmq_auth_backend_django/manage.py
								
								
								
									vendored
								
								
									
									
									Normal file → Executable file
								
							| 
						 | 
					@ -4,7 +4,19 @@ import sys
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if __name__ == "__main__":
 | 
					if __name__ == "__main__":
 | 
				
			||||||
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "rabbitmq_auth_backend_django.settings")
 | 
					    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "rabbitmq_auth_backend_django.settings")
 | 
				
			||||||
 | 
					    try:
 | 
				
			||||||
    from django.core.management import execute_from_command_line
 | 
					        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
 | 
				
			||||||
 | 
					        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
 | 
				
			||||||
    execute_from_command_line(sys.argv)
 | 
					    execute_from_command_line(sys.argv)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,59 +1,77 @@
 | 
				
			||||||
"""
 | 
					"""
 | 
				
			||||||
Django settings for rabbitmq_auth_backend_django project.
 | 
					Django settings for rabbitmq_auth_backend_django project.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Generated by 'django-admin startproject' using Django 1.10.5.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
For more information on this file, see
 | 
					For more information on this file, see
 | 
				
			||||||
https://docs.djangoproject.com/en/1.6/topics/settings/
 | 
					https://docs.djangoproject.com/en/1.10/topics/settings/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
For the full list of settings and their values, see
 | 
					For the full list of settings and their values, see
 | 
				
			||||||
https://docs.djangoproject.com/en/1.6/ref/settings/
 | 
					https://docs.djangoproject.com/en/1.10/ref/settings/
 | 
				
			||||||
"""
 | 
					"""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
 | 
					 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
 | 
					
 | 
				
			||||||
 | 
					# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
 | 
				
			||||||
 | 
					BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Quick-start development settings - unsuitable for production
 | 
					# Quick-start development settings - unsuitable for production
 | 
				
			||||||
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/
 | 
					# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# SECURITY WARNING: keep the secret key used in production secret!
 | 
					# SECURITY WARNING: keep the secret key used in production secret!
 | 
				
			||||||
SECRET_KEY = 'fv_vu$nf)h&lltdd)y=)x)^f23)k0s#01yo@^$06w4e29f813e'
 | 
					SECRET_KEY = '_wqlwxs-s(na_@1-@3=6uc2=-ka3f)))%-v#lgx4een8^#u92c'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# SECURITY WARNING: don't run with debug turned on in production!
 | 
					# SECURITY WARNING: don't run with debug turned on in production!
 | 
				
			||||||
DEBUG = True
 | 
					DEBUG = True
 | 
				
			||||||
 | 
					
 | 
				
			||||||
TEMPLATE_DEBUG = True
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
ALLOWED_HOSTS = []
 | 
					ALLOWED_HOSTS = []
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Application definition
 | 
					# Application definition
 | 
				
			||||||
 | 
					
 | 
				
			||||||
INSTALLED_APPS = (
 | 
					INSTALLED_APPS = [
 | 
				
			||||||
    'django.contrib.admin',
 | 
					    'django.contrib.admin',
 | 
				
			||||||
    'django.contrib.auth',
 | 
					    'django.contrib.auth',
 | 
				
			||||||
    'django.contrib.contenttypes',
 | 
					    'django.contrib.contenttypes',
 | 
				
			||||||
    'django.contrib.sessions',
 | 
					    'django.contrib.sessions',
 | 
				
			||||||
    'django.contrib.messages',
 | 
					    'django.contrib.messages',
 | 
				
			||||||
    'django.contrib.staticfiles',
 | 
					    'django.contrib.staticfiles',
 | 
				
			||||||
)
 | 
					]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
MIDDLEWARE_CLASSES = (
 | 
					MIDDLEWARE = [
 | 
				
			||||||
 | 
					    'django.middleware.security.SecurityMiddleware',
 | 
				
			||||||
    'django.contrib.sessions.middleware.SessionMiddleware',
 | 
					    'django.contrib.sessions.middleware.SessionMiddleware',
 | 
				
			||||||
    'django.middleware.common.CommonMiddleware',
 | 
					    'django.middleware.common.CommonMiddleware',
 | 
				
			||||||
    'django.middleware.csrf.CsrfViewMiddleware',
 | 
					    'django.middleware.csrf.CsrfViewMiddleware',
 | 
				
			||||||
    'django.contrib.auth.middleware.AuthenticationMiddleware',
 | 
					    'django.contrib.auth.middleware.AuthenticationMiddleware',
 | 
				
			||||||
    'django.contrib.messages.middleware.MessageMiddleware',
 | 
					    'django.contrib.messages.middleware.MessageMiddleware',
 | 
				
			||||||
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
 | 
					    'django.middleware.clickjacking.XFrameOptionsMiddleware',
 | 
				
			||||||
)
 | 
					]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ROOT_URLCONF = 'rabbitmq_auth_backend_django.urls'
 | 
					ROOT_URLCONF = 'rabbitmq_auth_backend_django.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 = 'rabbitmq_auth_backend_django.wsgi.application'
 | 
					WSGI_APPLICATION = 'rabbitmq_auth_backend_django.wsgi.application'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Database
 | 
					# Database
 | 
				
			||||||
# https://docs.djangoproject.com/en/1.6/ref/settings/#databases
 | 
					# https://docs.djangoproject.com/en/1.10/ref/settings/#databases
 | 
				
			||||||
 | 
					
 | 
				
			||||||
DATABASES = {
 | 
					DATABASES = {
 | 
				
			||||||
    'default': {
 | 
					    'default': {
 | 
				
			||||||
| 
						 | 
					@ -62,8 +80,28 @@ DATABASES = {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Password validation
 | 
				
			||||||
 | 
					# https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					AUTH_PASSWORD_VALIDATORS = [
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Internationalization
 | 
					# Internationalization
 | 
				
			||||||
# https://docs.djangoproject.com/en/1.6/topics/i18n/
 | 
					# https://docs.djangoproject.com/en/1.10/topics/i18n/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
LANGUAGE_CODE = 'en-us'
 | 
					LANGUAGE_CODE = 'en-us'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -77,6 +115,6 @@ USE_TZ = True
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Static files (CSS, JavaScript, Images)
 | 
					# Static files (CSS, JavaScript, Images)
 | 
				
			||||||
# https://docs.djangoproject.com/en/1.6/howto/static-files/
 | 
					# https://docs.djangoproject.com/en/1.10/howto/static-files/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
STATIC_URL = '/static/'
 | 
					STATIC_URL = '/static/'
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,15 +1,26 @@
 | 
				
			||||||
from django.conf.urls import patterns, include, url
 | 
					"""rabbitmq_auth_backend_django URL Configuration
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Uncomment the next two lines to enable the admin:
 | 
					The `urlpatterns` list routes URLs to views. For more information please see:
 | 
				
			||||||
 | 
					    https://docs.djangoproject.com/en/1.10/topics/http/urls/
 | 
				
			||||||
 | 
					Examples:
 | 
				
			||||||
 | 
					Function views
 | 
				
			||||||
 | 
					    1. Add an import:  from my_app import views
 | 
				
			||||||
 | 
					    2. Add a URL to urlpatterns:  url(r'^$', views.home, name='home')
 | 
				
			||||||
 | 
					Class-based views
 | 
				
			||||||
 | 
					    1. Add an import:  from other_app.views import Home
 | 
				
			||||||
 | 
					    2. Add a URL to urlpatterns:  url(r'^$', Home.as_view(), name='home')
 | 
				
			||||||
 | 
					Including another URLconf
 | 
				
			||||||
 | 
					    1. Import the include() function: from django.conf.urls import url, include
 | 
				
			||||||
 | 
					    2. Add a URL to urlpatterns:  url(r'^blog/', include('blog.urls'))
 | 
				
			||||||
 | 
					"""
 | 
				
			||||||
 | 
					from django.conf.urls import url
 | 
				
			||||||
from django.contrib import admin
 | 
					from django.contrib import admin
 | 
				
			||||||
admin.autodiscover()
 | 
					import rabbitmq_auth_backend_django.auth.views as views
 | 
				
			||||||
 | 
					
 | 
				
			||||||
urlpatterns = patterns('',
 | 
					urlpatterns = [
 | 
				
			||||||
    # Example:
 | 
					    url(r'^auth/user',     views.user),
 | 
				
			||||||
    (r'^auth/user',     'rabbitmq_auth_backend_django.auth.views.user'),
 | 
					    url(r'^auth/vhost',    views.vhost),
 | 
				
			||||||
    (r'^auth/vhost',    'rabbitmq_auth_backend_django.auth.views.vhost'),
 | 
					    url(r'^auth/resource', views.resource),
 | 
				
			||||||
    (r'^auth/resource', 'rabbitmq_auth_backend_django.auth.views.resource'),
 | 
					    url(r'^auth/topic',    views.topic),
 | 
				
			||||||
    (r'^auth/topic',    'rabbitmq_auth_backend_django.auth.views.topic'),
 | 
					    url(r'^admin/', admin.site.urls),
 | 
				
			||||||
    (r'^admin/doc/', include('django.contrib.admindocs.urls')),
 | 
					]
 | 
				
			||||||
    (r'^admin/', include(admin.site.urls)),
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,11 +4,13 @@ WSGI config for rabbitmq_auth_backend_django project.
 | 
				
			||||||
It exposes the WSGI callable as a module-level variable named ``application``.
 | 
					It exposes the WSGI callable as a module-level variable named ``application``.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
For more information on this file, see
 | 
					For more information on this file, see
 | 
				
			||||||
https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/
 | 
					https://docs.djangoproject.com/en/1.10/howto/deployment/wsgi/
 | 
				
			||||||
"""
 | 
					"""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "rabbitmq_auth_backend_django.settings")
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
from django.core.wsgi import get_wsgi_application
 | 
					from django.core.wsgi import get_wsgi_application
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					os.environ.setdefault("DJANGO_SETTINGS_MODULE", "rabbitmq_auth_backend_django.settings")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
application = get_wsgi_application()
 | 
					application = get_wsgi_application()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,3 +1,3 @@
 | 
				
			||||||
#!/bin/sh
 | 
					#!/bin/sh
 | 
				
			||||||
python manage.py syncdb
 | 
					python manage.py migrate
 | 
				
			||||||
python manage.py runserver
 | 
					python manage.py runserver
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue