Commit 94aa7602 authored by Sofia Papagiannaki's avatar Sofia Papagiannaki
Browse files

astakos: remove get_endpoints keystone api call

parent 03a9f436
......@@ -20,6 +20,7 @@ Document Revisions
========================= ================================
Revision Description
========================= ================================
0.14 (June 03, 2013) Remove endpoint listing
0.14 (May 28, 2013) Extend token api with authenticate call
0.14 (May 23, 2013) Extend api to list endpoints
0.14 (May 14, 2013) Do not serve user quotas in :ref:`authenticate-api-label`
......@@ -474,88 +475,3 @@ Return Code Description
401 (Unauthorized) Invalid token or invalid creadentials or tenantName does not comply with the provided token
500 (Internal Server Error) The request cannot be completed because of an internal error
=========================== =====================
Get endpoints
^^^^^^^^^^^^^
Return a json (or xml) formatted dictionary containing information about registered endpoints
========================================= ========= ==================
Uri Method Description
========================================= ========= ==================
``/astakos/api/tokens/<token>/endpoints`` GET Returns a list registered endpoints
========================================= ========= ==================
|
==================== ============================
Request Header Name Value
==================== ============================
X-Auth-Token User authentication token
==================== ============================
|
====================== ============================
Request Parameter Name Value
====================== ============================
belongsTo Check that the token belongs to a supplied user
marker Return endpoints (ordered by ID) whose ID is higher than the marker
limit Maximum number of endpoints to return
====================== ============================
|
Example json reply:
::
{"endpoints": [
{"name": "cyclades",
"region": "cyclades",
"internalURL": "https://node1.example.com/v1",
"adminURL": "https://node1.example.com/v1",
"type": null,
"id": 5,
"publicURL": "https://node1.example.com/vi/"},
{"name": "pithos",
"region": "pithos",
"internalURL": "https://node2.example.com/vi/",
"adminURL": "https://node2.example.com/v1",
"type": null,
"id": 6,
"publicURL": "https://node2.example.com/vi/"},
],
"endpoint_links": [{
"href": "/astakos/api/tokens/0000/endpoints?marker=6&limit=10000",
"rel": "next"}]}
Example xml reply:
::
<?xml version="1.0" encoding="UTF-8"?>
<endpoints xmlns="http://docs.openstack.org/identity/api/v2.0">
<endpoint "name"="cyclades" "region"="cyclades" "internalURL"="https://node1.example.com/ui/" "adminURL"="https://node1.example.com/ui/" "id"="5" "publicURL"="https://node1.example.com/ui/" />
<endpoint "name"="pithos" "region"="pithos" "internalURL"="https://node2.example.com/ui/" "adminURL"="https://node2.example.com/v1" "id"="6" "publicURL"="https://node2.example.com/ui/" />
</endpoints>
<endpoint_links>
<endpoint_link "href"="/astakos/api/tokens/0000/endpoints?marker=6&amp;limit=10000" "rel"="next" />
</endpoint_links>
|
=========================== =====================
Return Code Description
=========================== =====================
200 (OK) The request succeeded
400 (Bad Request) Method not allowed or token does not belong to the specific user
401 (Unauthorized) Missing or expired or invalid service token
403 (Forbidden) Path token does not comply with X-Auth-Token
500 (Internal Server Error) The request cannot be completed because of an internal error
=========================== =====================
......@@ -36,5 +36,4 @@ from django.conf.urls.defaults import patterns, url
urlpatterns = patterns(
'astakos.api.tokens',
url(r'tokens/?$', 'authenticate'),
url(r'tokens/(?P<token>.+?)/endpoints', 'get_endpoints'),
)
......@@ -31,60 +31,19 @@
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.
from urlparse import urlunsplit, urlsplit
from collections import defaultdict
from django.http import urlencode
from django.views.decorators.csrf import csrf_exempt
from snf_django.lib.api import faults, utils, api_method
from astakos.im.models import Service, AstakosUser
from .util import user_from_token, json_response, xml_response, validate_user
from .util import json_response, xml_response, validate_user
import logging
logger = logging.getLogger(__name__)
@api_method(http_method="GET", token_required=True, user_required=False,
logger=logger)
@user_from_token # Authenticate user!!
def get_endpoints(request, token):
if token != request.user.auth_token:
raise faults.Forbidden()
belongsTo = request.GET.get('belongsTo')
if belongsTo and belongsTo != request.user.uuid:
raise faults.BadRequest()
marker = request.GET.get('marker', 0)
limit = request.GET.get('limit', 10000)
endpoints = list(Service.objects.all().order_by('id').
filter(id__gt=marker)[:limit].
values('name', 'url', 'api_url', 'id', 'type'))
for e in endpoints:
e['publicURL'] = e['admiURL'] = e['internalURL'] = e['api_url']
e['SNF:uiURL'] = e['url']
e['region'] = e['name']
e.pop('api_url')
if endpoints:
parts = list(urlsplit(request.path))
params = {'marker': endpoints[-1]['id'], 'limit': limit}
parts[3] = urlencode(params)
next_page_url = urlunsplit(parts)
endpoint_links = [{'href': next_page_url, 'rel': 'next'}]
else:
endpoint_links = []
result = {'endpoints': endpoints, 'endpoint_links': endpoint_links}
if request.serialization == 'xml':
return xml_response(result, 'api/endpoints.xml')
else:
return json_response(result)
@csrf_exempt
@api_method(http_method="POST", token_required=False, user_required=False,
logger=logger)
......
......@@ -36,9 +36,6 @@ from astakos.im.tests.common import *
from django.test import TestCase
from django.core.urlresolvers import reverse
from urllib import quote
from urlparse import urlparse, parse_qs
#from xml.dom import minidom
import json
......@@ -553,96 +550,3 @@ class TokensApiTest(TestCase):
# body = minidom.parseString(r.content)
# except Exception, e:
# self.fail(e)
def test_get_endpoints(self):
client = Client()
# Check in active user token
inactive_user = AstakosUser.objects.create(email='test3')
url = '/astakos/api/tokens/%s/endpoints' % quote(
inactive_user.auth_token)
r = client.get(url)
self.assertEqual(r.status_code, 401)
# Check invalid user token in path
url = '/astakos/api/tokens/nouser/endpoints'
r = client.get(url)
self.assertEqual(r.status_code, 401)
# Check forbidden
url = '/astakos/api/tokens/%s/endpoints' % quote(self.user1.auth_token)
headers = {'HTTP_X_AUTH_TOKEN': AstakosUser.objects.create(
email='test4').auth_token}
r = client.get(url, **headers)
self.assertEqual(r.status_code, 401)
# Check bad request method
url = '/astakos/api/tokens/%s/endpoints' % quote(self.user1.auth_token)
r = client.post(url)
self.assertEqual(r.status_code, 400)
# Check forbidden
url = '/astakos/api/tokens/%s/endpoints' % quote(self.user1.auth_token)
headers = {'HTTP_X_AUTH_TOKEN': self.user2.auth_token}
r = client.get(url, **headers)
self.assertEqual(r.status_code, 403)
# Check belongsTo BadRequest
url = '/astakos/api/tokens/%s/endpoints?belongsTo=%s' % (
quote(self.user1.auth_token), quote(self.user2.uuid))
headers = {'HTTP_X_AUTH_TOKEN': self.user1.auth_token}
r = client.get(url, **headers)
self.assertEqual(r.status_code, 400)
# Check successful request
url = '/astakos/api/tokens/%s/endpoints' % quote(self.user1.auth_token)
headers = {'HTTP_X_AUTH_TOKEN': self.user1.auth_token}
r = client.get(url, **headers)
self.assertEqual(r.status_code, 200)
self.assertEqual(r['Content-Type'], 'application/json; charset=UTF-8')
try:
body = json.loads(r.content)
except:
self.fail('json format expected')
endpoints = body.get('endpoints')
self.assertEqual(len(endpoints), 3)
# Check xml serialization
url = '/astakos/api/tokens/%s/endpoints?format=xml' %\
quote(self.user1.auth_token)
headers = {'HTTP_X_AUTH_TOKEN': self.user1.auth_token}
r = client.get(url, **headers)
self.assertEqual(r.status_code, 200)
self.assertEqual(r['Content-Type'], 'application/xml; charset=UTF-8')
# try:
# body = minidom.parseString(r.content)
# except Exception, e:
# self.fail('xml format expected')
endpoints = body.get('endpoints')
self.assertEqual(len(endpoints), 3)
# Check limit
url = '/astakos/api/tokens/%s/endpoints?limit=2' %\
quote(self.user1.auth_token)
headers = {'HTTP_X_AUTH_TOKEN': self.user1.auth_token}
r = client.get(url, **headers)
self.assertEqual(r.status_code, 200)
body = json.loads(r.content)
endpoints = body.get('endpoints')
self.assertEqual(len(endpoints), 2)
endpoint_link = body.get('endpoint_links', [])[0]
next = endpoint_link.get('href')
p = urlparse(next)
params = parse_qs(p.query)
self.assertTrue('limit' in params)
self.assertTrue('marker' in params)
self.assertEqual(params['marker'][0], '2')
# Check marker
headers = {'HTTP_X_AUTH_TOKEN': self.user1.auth_token}
r = client.get(next, **headers)
self.assertEqual(r.status_code, 200)
body = json.loads(r.content)
endpoints = body.get('endpoints')
self.assertEqual(len(endpoints), 1)
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