Revision 3758cc42

b/auth/handlers.py
1
# vim: ts=4 sts=4 et ai sw=4 fileencoding=utf-8
2
#
3
# Copyright © 2010 Greek Research and Technology Network
4
#
5

  
6
from piston.handler import AnonymousBaseHandler
7
from django.http import HttpResponse
8
from django.core.urlresolvers import reverse
9

  
10
CURRENT_SERVER_VERSION = 'v1.0'
11

  
12
class AuthHandler(AnonymousBaseHandler):
13
    allowed_methods = ('GET',)
14

  
15
    def read(self, request):
16
        user = request.META.get('HTTP_X_AUTH_USER', None)
17
        key = request.META.get('HTTP_X_AUTH_KEY', None)
18
        if user is None or key is None:
19
            return HttpResponse(status=401)
20

  
21
        response = HttpResponse(status=204)
22

  
23
        # dummy auth
24
        response['X-Auth-Token'] = 'dummy-token'
25

  
26
        # return X-Server-Management's URL
27
        url = reverse('synnefo.api.urls.version_handler',
28
                kwargs={'number': CURRENT_SERVER_VERSION})
29
        url = request.build_absolute_uri(url)
30

  
31
        response['X-Server-Management-Url'] = url
32

  
33
        return response
b/auth/urls.py
1
# vim: ts=4 sts=4 et ai sw=4 fileencoding=utf-8
2
#
3
# Copyright © 2010 Greek Research and Technology Network
4
#
5

  
6
from django.conf.urls.defaults import *
7
from piston.resource import Resource
8
from synnefo.auth.handlers import *
9

  
10
auth_handler = Resource(AuthHandler)
11

  
12
urlpatterns = patterns('',
13
    (r'^v1.0', auth_handler),
14
)
b/middleware/__init__.py
1
# vim: ts=4 sts=4 et ai sw=4 fileencoding=utf-8
2
#
3
# Copyright © 2010 Greek Research and Technology Network
4
#
5

  
6
import re
7

  
8
_strip_url_re = re.compile(r'^https?://[^/]+')
9

  
10
class StripURLMiddleware(object):
11
    """
12
    At least some Cloud Servers API clients tend to use full URLs as request
13
    paths, contrary to all RFCs.
14

  
15
    This is a) wrong, b) incompatible with Django's urlconf.
16

  
17
    This middleware attempts to strip such URLs so that the URL dispatcher can
18
    process it normally.
19

  
20
    It should be inserted as early as possible in MIDDLEWARE_CLASSES
21
    """
22

  
23
    def process_request(self, request):
24
        request.path = re.sub(_strip_url_re, '', request.path)
25
        request.path_info = re.sub(_strip_url_re, '', request.path_info)
26
        print request.path_info
b/settings.py.dist
71 71
)
72 72

  
73 73
MIDDLEWARE_CLASSES = (
74
    'synnefo.middleware.StripURLMiddleware',
74 75
    'django.middleware.common.CommonMiddleware',
75 76
    'django.contrib.sessions.middleware.SessionMiddleware',
76 77
#    'django.middleware.csrf.CsrfViewMiddleware',
......
94 95
    'django.contrib.messages',
95 96
    # 'django.contrib.admin',
96 97
    # 'django.contrib.admindocs',
98
    'synnefo.auth',
97 99
    'synnefo.api',
98 100
)
b/urls.py
6 6
from django.conf.urls.defaults import *
7 7

  
8 8
urlpatterns = patterns('',
9
    (r'^auth/api/', include('synnefo.auth.urls')),
9 10
    (r'^api/', include('synnefo.api.urls')),
10 11
)

Also available in: Unified diff