Commit 3758cc42 authored by Faidon Liambotis's avatar Faidon Liambotis

Add Auth-API application, plus the StripURLMiddleware

parent 04accb0f
# vim: ts=4 sts=4 et ai sw=4 fileencoding=utf-8
#
# Copyright © 2010 Greek Research and Technology Network
#
from piston.handler import AnonymousBaseHandler
from django.http import HttpResponse
from django.core.urlresolvers import reverse
CURRENT_SERVER_VERSION = 'v1.0'
class AuthHandler(AnonymousBaseHandler):
allowed_methods = ('GET',)
def read(self, request):
user = request.META.get('HTTP_X_AUTH_USER', None)
key = request.META.get('HTTP_X_AUTH_KEY', None)
if user is None or key is None:
return HttpResponse(status=401)
response = HttpResponse(status=204)
# dummy auth
response['X-Auth-Token'] = 'dummy-token'
# return X-Server-Management's URL
url = reverse('synnefo.api.urls.version_handler',
kwargs={'number': CURRENT_SERVER_VERSION})
url = request.build_absolute_uri(url)
response['X-Server-Management-Url'] = url
return response
# vim: ts=4 sts=4 et ai sw=4 fileencoding=utf-8
#
# Copyright © 2010 Greek Research and Technology Network
#
from django.conf.urls.defaults import *
from piston.resource import Resource
from synnefo.auth.handlers import *
auth_handler = Resource(AuthHandler)
urlpatterns = patterns('',
(r'^v1.0', auth_handler),
)
# vim: ts=4 sts=4 et ai sw=4 fileencoding=utf-8
#
# Copyright © 2010 Greek Research and Technology Network
#
import re
_strip_url_re = re.compile(r'^https?://[^/]+')
class StripURLMiddleware(object):
"""
At least some Cloud Servers API clients tend to use full URLs as request
paths, contrary to all RFCs.
This is a) wrong, b) incompatible with Django's urlconf.
This middleware attempts to strip such URLs so that the URL dispatcher can
process it normally.
It should be inserted as early as possible in MIDDLEWARE_CLASSES
"""
def process_request(self, request):
request.path = re.sub(_strip_url_re, '', request.path)
request.path_info = re.sub(_strip_url_re, '', request.path_info)
print request.path_info
......@@ -71,6 +71,7 @@ TEMPLATE_LOADERS = (
)
MIDDLEWARE_CLASSES = (
'synnefo.middleware.StripURLMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
# 'django.middleware.csrf.CsrfViewMiddleware',
......@@ -94,5 +95,6 @@ INSTALLED_APPS = (
'django.contrib.messages',
# 'django.contrib.admin',
# 'django.contrib.admindocs',
'synnefo.auth',
'synnefo.api',
)
......@@ -6,5 +6,6 @@
from django.conf.urls.defaults import *
urlpatterns = patterns('',
(r'^auth/api/', include('synnefo.auth.urls')),
(r'^api/', include('synnefo.api.urls')),
)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment