Skip to content
Snippets Groups Projects
Commit 9dac4d1e authored by Renzo Frigato's avatar Renzo Frigato
Browse files

refactor routing table

parent ecb449f0
No related branches found
No related tags found
No related merge requests found
......@@ -15,59 +15,197 @@ from handlers import grouphandler
from handlers import containerhandler
from handlers import collectionshandler
#regexes used in routing table:
routing_regexes = {
'group_id_re': '[0-9a-z][0-9a-z.@_-]{0,30}[0-9a-z]',
'cid_re': '[0-9a-f]{24}',
'site_re': '[0-9a-z]{0,24}',
'user_id_re': '[0-9a-z.@_-]*',
'cont_name_re': 'projects|sessions|acquisitions|collections',
'tag_re': '[^/]{3,24}',
'filename_re': '[^/]{3,60}',
'note_id_re': '[0-9a-f]{24}'
}
def _format(route):
return route.format(**routing_regexes)
routes = [
webapp2.Route(r'/api', core.Core),
webapp2.Route(
r'/api',
core.Core
),
webapp2_extras.routes.PathPrefixRoute(r'/api', [
webapp2.Route(r'/download', core.Core, handler_method='download', methods=['GET', 'POST'], name='download'),
webapp2.Route(r'/reaper', core.Core, handler_method='reaper', methods=['POST']),
webapp2.Route(r'/sites', core.Core, handler_method='sites', methods=['GET'])
webapp2.Route(
r'/download',
core.Core, handler_method='download', methods=['GET', 'POST'], name='download'
),
webapp2.Route(
r'/reaper',
core.Core, handler_method='reaper', methods=['POST']
),
webapp2.Route(
r'/sites',
core.Core, handler_method='sites', methods=['GET']
)
]),
webapp2.Route(r'/api/users', userhandler.UserHandler, handler_method='get_all', methods=['GET']),
webapp2.Route(r'/api/users', userhandler.UserHandler, methods=['POST']),
webapp2.Route(
r'/api/users',
userhandler.UserHandler, handler_method='get_all', methods=['GET']
),
webapp2.Route(
r'/api/users',
userhandler.UserHandler, methods=['POST']
),
webapp2_extras.routes.PathPrefixRoute(r'/api/users', [
webapp2.Route(r'/self', userhandler.UserHandler, handler_method='self', methods=['GET']),
webapp2.Route(r'/roles', userhandler.UserHandler, handler_method='roles', methods=['GET']),
webapp2.Route(r'/<_id:[\w\@\-\.]{3,60}>', userhandler.UserHandler, name='user'),
webapp2.Route(r'/<uid:[\w\@\-\.]{3,60}>/groups', grouphandler.GroupHandler, handler_method='get_all', methods=['GET'], name='groups'),
]),
webapp2.Route(r'/api/groups', grouphandler.GroupHandler, handler_method='get_all', methods=['GET']),
webapp2.Route(r'/api/groups', grouphandler.GroupHandler, methods=['POST']),
webapp2_extras.routes.PathPrefixRoute(r'/api/groups', [
webapp2.Route(r'/<_id:[0-9a-z]{3,24}>', grouphandler.GroupHandler, name='group'),
webapp2.Route(r'/<cid:[0-9a-z]{3,24}>/roles', listhandler.ListHandler, methods=['POST'], defaults={'cont_name': 'groups', 'list_name': 'roles'}),
webapp2.Route(r'/<cid:[0-9a-z]{3,24}>/roles/<site:[0-9a-z]{3,24}>/<_id:[\w\@\-\.]{3,60}>',
listhandler.ListHandler, methods=['GET', 'PUT', 'DELETE'], defaults={'cont_name': 'groups', 'list_name': 'roles'}),
webapp2.Route(
r'/self',
userhandler.UserHandler, handler_method='self', methods=['GET']
),
webapp2.Route(
r'/roles',
userhandler.UserHandler, handler_method='roles', methods=['GET']
),
webapp2.Route(
_format(r'/<_id:{user_id_re}>'),
userhandler.UserHandler, name='user'
),
webapp2.Route(
_format(r'/<uid:{user_id_re}>/groups'),
grouphandler.GroupHandler, handler_method='get_all', methods=['GET'], name='groups'
),
]),
webapp2.Route(r'/api/jobs', jobs.Jobs),
webapp2.Route(
r'/api/jobs',
jobs.Jobs
),
webapp2_extras.routes.PathPrefixRoute(r'/api/jobs', [
webapp2.Route(r'/next', jobs.Jobs, handler_method='next', methods=['GET']),
webapp2.Route(r'/count', jobs.Jobs, handler_method='count', methods=['GET']),
webapp2.Route(r'/addTestJob', jobs.Jobs, handler_method='addTestJob', methods=['GET']),
webapp2.Route(r'/<:[^/]+>', jobs.Job, name='job'),
webapp2.Route(
r'/next',
jobs.Jobs, handler_method='next', methods=['GET']
),
webapp2.Route(
r'/count',
jobs.Jobs, handler_method='count', methods=['GET']
),
webapp2.Route(
r'/addTestJob',
jobs.Jobs, handler_method='addTestJob', methods=['GET']
),
webapp2.Route(
r'/<:[^/]+>',
jobs.Job, name='job'
),
]),
webapp2.Route(r'/api/<cont_name:[0-9a-z]{3,24}>/<cid:[0-9a-z]{3,24}>/tags', listhandler.ListHandler, methods=['POST'], name='tags_post', defaults={'list_name': 'tags'}),
webapp2.Route(r'/api/<cont_name:[0-9a-z]{3,24}>/<cid:[0-9a-z]{3,24}>/tags/<value:[^/]{3,24}>', listhandler.ListHandler, name='tags', defaults={'list_name': 'tags'}),
webapp2.Route(r'/api/<cont_name:[0-9a-z]{3,24}>/<cid:[0-9a-z]{3,24}>/files', listhandler.FileListHandler, name='files_post', methods=['POST'], defaults={'list_name': 'files'}),
webapp2.Route(r'/api/<cont_name:[0-9a-z]{3,24}>/<cid:[0-9a-z]{3,24}>/files/<filename:[^/]{3,60}>', listhandler.FileListHandler, name='files', defaults={'list_name': 'files'}),
webapp2.Route(r'/api/<cont_name:collections|projects>/<cid:[0-9a-z]{3,24}>/permissions', listhandler.PermissionsListHandler, name='perms_post', methods=['POST'], defaults={'list_name': 'permissions'}),
webapp2.Route(r'/api/<cont_name:collections|projects>/<cid:[0-9a-z]{3,24}>/permissions/<site:[0-9a-z]{3,24}>/<_id:[\w\@\-\.]{3,60}>',
listhandler.PermissionsListHandler, name='perms', defaults={ 'list_name': 'permissions'}),
webapp2.Route(r'/api/<cont_name:[0-9a-z]{3,24}>/<cid:[0-9a-z]{3,24}>/notes', listhandler.NotesListHandler, name='notes_post', methods=['POST'], defaults={'list_name': 'notes'}),
webapp2.Route(r'/api/<cont_name:[0-9a-z]{3,24}>/<cid:[0-9a-z]{3,24}>/notes/<_id:[0-9a-z]{3,24}>', listhandler.NotesListHandler, name='notes', defaults={'list_name': 'notes'}),
webapp2.Route(
r'/api/groups',
grouphandler.GroupHandler, handler_method='get_all', methods=['GET']
),
webapp2.Route(
r'/api/groups',
grouphandler.GroupHandler, methods=['POST']
),
webapp2.Route(
_format(r'/api/groups/<_id:{group_id_re}>'),
grouphandler.GroupHandler, name='group'
),
webapp2.Route(
_format(r'/api/<cont_name:groups>/<cid:{group_id_re}>/<list_name:roles>'),
listhandler.ListHandler, name='group'
),
webapp2.Route(
_format(r'/api/<cont_name:groups>/<cid:{group_id_re}>/<list_name:roles>/<site:{site_re}>/<_id:{user_id_re}>'),
listhandler.ListHandler, name='group', methods=['GET', 'PUT', 'DELETE']
),
webapp2.Route(
_format(r'/api/<cont_name:{cont_name_re}>/<cid:{cid_re}>/<list_name:tags>'),
listhandler.ListHandler, methods=['POST'], name='tags_post'
),
webapp2.Route(
_format(r'/api/<cont_name:{cont_name_re}>/<cid:{cid_re}>/<list_name:tags>/<value:{tag_re}>'),
listhandler.ListHandler, name='tags'
),
webapp2.Route(
_format(r'/api/<cont_name:{cont_name_re}>/<cid:{cid_re}>/<list_name:files>'),
listhandler.FileListHandler, name='files_post', methods=['POST']
),
webapp2.Route(
_format(r'/api/<cont_name:{cont_name_re}>/<cid:{cid_re}>/<list_name:files>/<filename:{filename_re}>'),
listhandler.FileListHandler, name='files'
),
webapp2.Route(
_format(r'/api/<cont_name:collections|projects>/<cid:{cid_re}>/<list_name:permissions>'),
listhandler.PermissionsListHandler, name='perms_post', methods=['POST']
),
webapp2.Route(
_format(
r'/api/<cont_name:collections|projects>/<cid:{cid_re}>' +
r'/<list_name:permissions>/<site:{site_re}>/<_id:{user_id_re}>'
),
listhandler.PermissionsListHandler, name='perms'
),
webapp2.Route(
_format(r'/api/<cont_name:{cont_name_re}>/<cid:{cid_re}>/<list_name:notes>'),
listhandler.NotesListHandler, name='notes_post', methods=['POST']
),
webapp2.Route(
_format(r'/api/<cont_name:{cont_name_re}>/<cid:{cid_re}>/<list_name:notes>/<_id:{note_id_re}>'),
listhandler.NotesListHandler, name='notes'
),
webapp2.Route(r'/api/collections/curators', collectionshandler.CollectionsHandler, handler_method='curators', methods=['GET']),
webapp2.Route(r'/api/<cont_name:collections>', collectionshandler.CollectionsHandler, name='colls', handler_method='get_all', methods=['GET']),
webapp2.Route(r'/api/<cont_name:collections>', collectionshandler.CollectionsHandler, methods=['POST']),
webapp2.Route(r'/api/<cont_name:collections>/<cid:[^/]+>', collectionshandler.CollectionsHandler, name='coll_details', methods=['GET', 'PUT', 'DELETE']),
webapp2.Route(r'/api/<cont_name:collections>/<cid:[0-9a-z]{3,24}>/sessions', collectionshandler.CollectionsHandler, name='coll_ses', handler_method='get_sessions', methods=['GET']),
webapp2.Route(r'/api/<cont_name:collections>/<cid:[0-9a-z]{3,24}>/acquisitions', collectionshandler.CollectionsHandler, name='coll_acq',handler_method='get_acquisitions', methods=['GET']),
webapp2.Route(
r'/api/collections/curators',
collectionshandler.CollectionsHandler, handler_method='curators', methods=['GET']
),
webapp2.Route(
r'/api/<cont_name:collections>',
collectionshandler.CollectionsHandler, name='colls', handler_method='get_all', methods=['GET']
),
webapp2.Route(
r'/api/<cont_name:collections>',
collectionshandler.CollectionsHandler, methods=['POST']
),
webapp2.Route(
_format(r'/api/<cont_name:collections>/<cid:{cid_re}>'),
collectionshandler.CollectionsHandler, name='coll_details', methods=['GET', 'PUT', 'DELETE']
),
webapp2.Route(
_format(r'/api/<cont_name:collections>/<cid:{cid_re}>/sessions'),
collectionshandler.CollectionsHandler, name='coll_ses', handler_method='get_sessions', methods=['GET']
),
webapp2.Route(
_format(r'/api/<cont_name:collections>/<cid:{cid_re}>/acquisitions'),
collectionshandler.CollectionsHandler, name='coll_acq', handler_method='get_acquisitions', methods=['GET']
),
webapp2.Route(r'/api/users/<uid:[0-9a-z\@\-\.]{3,60}>/<cont_name:[0-9a-z]{3,24}>', containerhandler.ContainerHandler, name='user_conts', handler_method='get_all_for_user', methods=['GET']),
webapp2.Route(r'/api/projects/groups', containerhandler.ContainerHandler, handler_method='get_groups_with_project', methods=['GET']),
webapp2.Route(r'/api/<par_cont_name:[0-9a-z]{3,24}>/<par_id:[0-9a-z]{3,24}>/<cont_name:[0-9a-z]{3,24}>', containerhandler.ContainerHandler, name='cont_sublist', handler_method='get_all', methods=['GET']),
webapp2.Route(r'/api/<cont_name:[0-9a-z]{3,24}>', containerhandler.ContainerHandler, name='cont_list', handler_method='get_all', methods=['GET']),
webapp2.Route(r'/api/<cont_name:[0-9a-z]{3,24}>', containerhandler.ContainerHandler, methods=['POST']),
webapp2.Route(r'/api/<cont_name:[0-9a-z]{3,24}>/<cid:[0-9a-z]{3,24}>', containerhandler.ContainerHandler, name='cont_details', methods=['GET','PUT','DELETE']),
webapp2.Route(
_format(r'/api/users/<uid:{user_id_re}>/<cont_name:{cont_name_re}>'),
containerhandler.ContainerHandler, name='user_conts', handler_method='get_all_for_user', methods=['GET']
),
webapp2.Route(
r'/api/projects/groups',
containerhandler.ContainerHandler, handler_method='get_groups_with_project', methods=['GET']
),
webapp2.Route(
_format(r'/api/<par_cont_name:groups>/<par_id:{group_id_re}>/<cont_name:projects>'),
containerhandler.ContainerHandler, name='cont_sublist', handler_method='get_all', methods=['GET']
),
webapp2.Route(
_format(r'/api/<par_cont_name:{cont_name_re}>/<par_id:{cid_re}>/<cont_name:{cont_name_re}>'),
containerhandler.ContainerHandler, name='cont_sublist', handler_method='get_all', methods=['GET']
),
webapp2.Route(
_format(r'/api/<cont_name:{cont_name_re}>'),
containerhandler.ContainerHandler, name='cont_list', handler_method='get_all', methods=['GET']
),
webapp2.Route(
_format(r'/api/<cont_name:{cont_name_re}>'),
containerhandler.ContainerHandler, methods=['POST']
),
webapp2.Route(
_format(r'/api/<cont_name:{cont_name_re}>/<cid:{cid_re}>'),
containerhandler.ContainerHandler, name='cont_details', methods=['GET','PUT','DELETE']
),
]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment