Merge lp:~gesha/linaro-license-protection/add-multiple-sites-support into lp:~linaro-automation/linaro-license-protection/trunk

Proposed by Georgy Redkozubov
Status: Superseded
Proposed branch: lp:~gesha/linaro-license-protection/add-multiple-sites-support
Merge into: lp:~linaro-automation/linaro-license-protection/trunk
Diff against target: 261 lines (+212/-0)
8 files modified
license_protected_downloads/wsgi_releases.py (+42/-0)
license_protected_downloads/wsgi_snapshots.py (+42/-0)
middleware.py (+19/-0)
releases_urls.py (+36/-0)
settings.py (+6/-0)
settings_releases.py (+16/-0)
settings_snapshots.py (+15/-0)
snapshots_urls.py (+36/-0)
To merge this branch: bzr merge lp:~gesha/linaro-license-protection/add-multiple-sites-support
Reviewer Review Type Date Requested Status
James Tunnicliffe (community) Approve
Review via email: mp+117659@code.launchpad.net

This proposal has been superseded by a proposal from 2012-08-06.

Description of the change

This branch adds support of multi-sites per single Django application. It is now configured to serve releases.linaro.org and snapshots.linaro.org. Both sites use the same database for licenses. License acceptance is site-dependent: for example if you have accepted the license on snapshots you will need to accept the same license on releases if asked.

To post a comment you must log in.
96. By Georgy Redkozubov

Moved templates addition to own branch

Revision history for this message
James Tunnicliffe (dooferlad) wrote :

Looks fine.

Since we have multiple settings and wsgi files it would be possible to use a separate database for each site and remove the site_id requirement. The databases build themselves up as they go, so unless the OpenID code stores data in them, we can just delete the existing database at a later date and start fresh.

Currently the set up uses sqlite3, which is fine for development but not for deployment, but I assume you and the sys-admins know that and will use a more traditional database when live!

review: Approve
97. By Georgy Redkozubov

Removed not used SITE_ID. Can be added later if there will be a real need.

98. By Georgy Redkozubov

Added deployment steps to README.

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'license_protected_downloads/wsgi_releases.py'
2--- license_protected_downloads/wsgi_releases.py 1970-01-01 00:00:00 +0000
3+++ license_protected_downloads/wsgi_releases.py 2012-08-06 11:55:23 +0000
4@@ -0,0 +1,42 @@
5+"""
6+WSGI config for license_protected_downloads project.
7+
8+This module contains the WSGI application used by Django's development server
9+and any production WSGI deployments. It should expose a module-level variable
10+named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover
11+this application via the ``WSGI_APPLICATION`` setting.
12+
13+Usually you will have the standard Django WSGI application here, but it also
14+might make sense to replace the whole Django WSGI application with a custom one
15+that later delegates to the Django one. For example, you could introduce WSGI
16+middleware here, or combine a Django application with an application of another
17+framework.
18+
19+"""
20+import os
21+import sys
22+sys.path.append("/usr/lib/python2.7/dist-packages")
23+sys.path.append("/usr/lib/pymodules/python2.7")
24+sys.path.append("/usr/lib/python2.7")
25+
26+# NOTE: Set actual path to directory containing linaro-license-protection app
27+sys.path.append("/srv/releases.linaro.org")
28+sys.path.append("/srv/releases.linaro.org/linaro-license-protection")
29+
30+os.environ.setdefault(
31+ "DJANGO_SETTINGS_MODULE",
32+ "linaro-license-protection.settings_releases"
33+)
34+
35+# This application object is used by any WSGI server configured to use this
36+# file. This includes Django's development server, if the WSGI_APPLICATION
37+# setting points here.
38+#from django.core.wsgi import get_wsgi_application
39+#application = get_wsgi_application()
40+
41+import django.core.handlers.wsgi
42+application = django.core.handlers.wsgi.WSGIHandler()
43+
44+# Apply WSGI middleware here.
45+# from helloworld.wsgi import HelloWorldApplication
46+# application = HelloWorldApplication(application)
47
48=== added file 'license_protected_downloads/wsgi_snapshots.py'
49--- license_protected_downloads/wsgi_snapshots.py 1970-01-01 00:00:00 +0000
50+++ license_protected_downloads/wsgi_snapshots.py 2012-08-06 11:55:23 +0000
51@@ -0,0 +1,42 @@
52+"""
53+WSGI config for license_protected_downloads project.
54+
55+This module contains the WSGI application used by Django's development server
56+and any production WSGI deployments. It should expose a module-level variable
57+named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover
58+this application via the ``WSGI_APPLICATION`` setting.
59+
60+Usually you will have the standard Django WSGI application here, but it also
61+might make sense to replace the whole Django WSGI application with a custom one
62+that later delegates to the Django one. For example, you could introduce WSGI
63+middleware here, or combine a Django application with an application of another
64+framework.
65+
66+"""
67+import os
68+import sys
69+sys.path.append("/usr/lib/python2.7/dist-packages")
70+sys.path.append("/usr/lib/pymodules/python2.7")
71+sys.path.append("/usr/lib/python2.7")
72+
73+# NOTE: Set actual path to directory containing linaro-license-protection app
74+sys.path.append("/srv/snapshots.linaro.org")
75+sys.path.append("/srv/snapshots.linaro.org/linaro-license-protection")
76+
77+os.environ.setdefault(
78+ "DJANGO_SETTINGS_MODULE",
79+ "linaro-license-protection.settings_snapshots"
80+)
81+
82+# This application object is used by any WSGI server configured to use this
83+# file. This includes Django's development server, if the WSGI_APPLICATION
84+# setting points here.
85+#from django.core.wsgi import get_wsgi_application
86+#application = get_wsgi_application()
87+
88+import django.core.handlers.wsgi
89+application = django.core.handlers.wsgi.WSGIHandler()
90+
91+# Apply WSGI middleware here.
92+# from helloworld.wsgi import HelloWorldApplication
93+# application = HelloWorldApplication(application)
94
95=== added file 'middleware.py'
96--- middleware.py 1970-01-01 00:00:00 +0000
97+++ middleware.py 2012-08-06 11:55:23 +0000
98@@ -0,0 +1,19 @@
99+from django.conf import settings
100+from django.utils.cache import patch_vary_headers
101+
102+
103+class MultiHostMiddleware:
104+
105+ def process_request(self, request):
106+ try:
107+ host = request.META["HTTP_HOST"]
108+ if host[-3:] == ":80":
109+ host = host[:-3] # ignore default port number, if present
110+ request.urlconf = settings.HOST_MIDDLEWARE_URLCONF_MAP[host]
111+ except KeyError:
112+ pass # use default urlconf (settings.ROOT_URLCONF)
113+
114+ def process_response(self, request, response):
115+ if getattr(request, "urlconf", None):
116+ patch_vary_headers(response, ('Host',))
117+ return response
118
119=== added file 'releases_urls.py'
120--- releases_urls.py 1970-01-01 00:00:00 +0000
121+++ releases_urls.py 2012-08-06 11:55:23 +0000
122@@ -0,0 +1,36 @@
123+from django.conf.urls.defaults import patterns, include, url
124+
125+# Uncomment the next two lines to enable the admin:
126+from django.contrib import admin
127+admin.autodiscover()
128+
129+
130+urlpatterns = patterns('',
131+ # Uncomment the admin/doc line below to enable admin documentation:
132+ url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
133+
134+ # Uncomment the next line to enable the admin:
135+ url(r'^admin/', include(admin.site.urls)),
136+
137+ url(r'^openid/', include('django_openid_auth.urls')),
138+ url(r'^logout/$', 'django.contrib.auth.views.logout'),
139+
140+ # The license page...
141+ url(r'^license$',
142+ 'license_protected_downloads.views.show_license',
143+ name='show_license'),
144+
145+ # Exceptions redirected to root...
146+ url(r'^license',
147+ 'license_protected_downloads.views.redirect_to_root',
148+ name='redirect_to_root'),
149+
150+ # Accept the license
151+ url(r'^accept-license',
152+ 'license_protected_downloads.views.accept_license',
153+ name='accept_license'),
154+
155+ # Catch-all. We always return a file (or try to) if it exists.
156+ # This handler does that.
157+ url(r'(?P<path>.*)', 'license_protected_downloads.views.file_server'),
158+)
159
160=== modified file 'settings.py'
161--- settings.py 2012-07-11 13:08:55 +0000
162+++ settings.py 2012-08-06 11:55:23 +0000
163@@ -86,6 +86,7 @@
164 )
165
166 MIDDLEWARE_CLASSES = (
167+ 'middleware.MultiHostMiddleware',
168 'django.middleware.common.CommonMiddleware',
169 'django.contrib.sessions.middleware.SessionMiddleware',
170 'django.middleware.csrf.CsrfViewMiddleware',
171@@ -154,3 +155,8 @@
172 'django.contrib.messages.context_processors.messages',
173 'django.contrib.auth.context_processors.auth',
174 )
175+
176+HOST_MIDDLEWARE_URLCONF_MAP = {
177+ "releases.linaro.org": ROOT_DIR + ".releases_urls",
178+ "snapshots.linaro.org": ROOT_DIR + ".snapshots_urls",
179+}
180
181=== added file 'settings_releases.py'
182--- settings_releases.py 1970-01-01 00:00:00 +0000
183+++ settings_releases.py 2012-08-06 11:55:23 +0000
184@@ -0,0 +1,16 @@
185+from settings import *
186+
187+
188+DATABASES = {
189+ 'default': {
190+ 'ENGINE': 'django.db.backends.sqlite3',
191+ 'NAME': '/srv/releases.linaro.org/db/licenses.db',
192+ 'USER': '',
193+ 'PASSWORD': '',
194+ 'HOST': '',
195+ 'PORT': '',
196+ }
197+}
198+
199+TEMPLATE_DIRS = (os.path.join(PROJECT_ROOT, "templates_releases" ),)
200+SERVED_PATHS = ['/srv/releases.linaro.org/www']
201
202=== added file 'settings_snapshots.py'
203--- settings_snapshots.py 1970-01-01 00:00:00 +0000
204+++ settings_snapshots.py 2012-08-06 11:55:23 +0000
205@@ -0,0 +1,15 @@
206+from settings import *
207+
208+DATABASES = {
209+ 'default': {
210+ 'ENGINE': 'django.db.backends.sqlite3',
211+ 'NAME': '/srv/snapshots.linaro.org/db/licenses.db',
212+ 'USER': '',
213+ 'PASSWORD': '',
214+ 'HOST': '',
215+ 'PORT': '',
216+ }
217+}
218+
219+TEMPLATE_DIRS = (os.path.join(PROJECT_ROOT, "templates_snapshots" ),)
220+SERVED_PATHS = ['/srv/snapshots.linaro.org/www']
221
222=== added file 'snapshots_urls.py'
223--- snapshots_urls.py 1970-01-01 00:00:00 +0000
224+++ snapshots_urls.py 2012-08-06 11:55:23 +0000
225@@ -0,0 +1,36 @@
226+from django.conf.urls.defaults import patterns, include, url
227+
228+# Uncomment the next two lines to enable the admin:
229+from django.contrib import admin
230+admin.autodiscover()
231+
232+
233+urlpatterns = patterns('',
234+ # Uncomment the admin/doc line below to enable admin documentation:
235+ url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
236+
237+ # Uncomment the next line to enable the admin:
238+ url(r'^admin/', include(admin.site.urls)),
239+
240+ url(r'^openid/', include('django_openid_auth.urls')),
241+ url(r'^logout/$', 'django.contrib.auth.views.logout'),
242+
243+ # The license page...
244+ url(r'^license$',
245+ 'license_protected_downloads.views.show_license',
246+ name='show_license'),
247+
248+ # Exceptions redirected to root...
249+ url(r'^license',
250+ 'license_protected_downloads.views.redirect_to_root',
251+ name='redirect_to_root'),
252+
253+ # Accept the license
254+ url(r'^accept-license',
255+ 'license_protected_downloads.views.accept_license',
256+ name='accept_license'),
257+
258+ # Catch-all. We always return a file (or try to) if it exists.
259+ # This handler does that.
260+ url(r'(?P<path>.*)', 'license_protected_downloads.views.file_server'),
261+)

Subscribers

People subscribed via source and target branches