Revision 5fb55fba api/helpers.py
b/api/helpers.py | ||
---|---|---|
4 | 4 |
# |
5 | 5 |
|
6 | 6 |
# XXX: most of the keys below are dummy |
7 |
from synnefo.api.errors import Unauthorized |
|
8 |
|
|
7 | 9 |
def instance_to_server(instance): |
8 | 10 |
server = { |
9 | 11 |
"id": instance["name"], |
... | ... | |
61 | 63 |
return { key: [] } |
62 | 64 |
|
63 | 65 |
return inner_func |
66 |
|
|
67 |
def authenticate(func): |
|
68 |
""" |
|
69 |
Custom authentication filter supporting the OpenStack API protocol. |
|
70 |
|
|
71 |
All API methods are required to go through this. Temporarily implemented as |
|
72 |
a decorator until we find a way to apply it to all incoming requests. |
|
73 |
""" |
|
74 |
def inner(self, request, *args, **kwargs): |
|
75 |
if 'X-Auth-Token' in request.META: |
|
76 |
return func(self, request, *args, **kwargs) |
|
77 |
|
|
78 |
#An authentication request |
|
79 |
if 'X-Auth-User' in request.META and 'X-Auth-Key' in request.META \ |
|
80 |
and '/v1.0' == request.path and 'GET' == request.method: |
|
81 |
#Do authenticate or redirect |
|
82 |
return |
|
83 |
|
|
84 |
raise Unauthorized |
|
85 |
|
|
86 |
return inner |
Also available in: Unified diff