Changeset View
Changeset View
Standalone View
Standalone View
swh/web/api/views/vault.py
Show All 17 Lines | |||||
# XXX: a bit spaghetti. Would be better with class-based views. | # XXX: a bit spaghetti. Would be better with class-based views. | ||||
def _dispatch_cook_progress(request, obj_type, obj_id): | def _dispatch_cook_progress(request, obj_type, obj_id): | ||||
hex_id = hashutil.hash_to_hex(obj_id) | hex_id = hashutil.hash_to_hex(obj_id) | ||||
object_name = obj_type.split('_')[0].title() | object_name = obj_type.split('_')[0].title() | ||||
if request.method == 'GET': | if request.method == 'GET': | ||||
return api_lookup( | return api_lookup( | ||||
service.vault_progress, obj_type, obj_id, | service.vault_progress, obj_type, obj_id, | ||||
notfound_msg=("{} '{}' was never requested." | notfound_msg=("{} '{}' was never requested." | ||||
.format(object_name, hex_id))) | .format(object_name, hex_id)), | ||||
request=request) | |||||
elif request.method == 'POST': | elif request.method == 'POST': | ||||
email = request.POST.get('email', request.GET.get('email', None)) | email = request.POST.get('email', request.GET.get('email', None)) | ||||
return api_lookup( | return api_lookup( | ||||
service.vault_cook, obj_type, obj_id, email, | service.vault_cook, obj_type, obj_id, email, | ||||
notfound_msg=("{} '{}' not found." | notfound_msg=("{} '{}' not found." | ||||
.format(object_name, hex_id))) | .format(object_name, hex_id)), | ||||
request=request) | |||||
@api_route(r'/vault/directory/(?P<dir_id>[0-9a-f]+)/', | @api_route(r'/vault/directory/(?P<dir_id>[0-9a-f]+)/', | ||||
'api-1-vault-cook-directory', methods=['GET', 'POST'], | 'api-1-vault-cook-directory', methods=['GET', 'POST'], | ||||
checksum_args=['dir_id'], | checksum_args=['dir_id'], | ||||
throttle_scope='swh_vault_cooking') | throttle_scope='swh_vault_cooking') | ||||
@never_cache | @never_cache | ||||
@api_doc('/vault/directory/') | @api_doc('/vault/directory/') | ||||
▲ Show 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | .. http:get:: /api/1/vault/directory/(dir_id)/raw/ | ||||
:statuscode 404: requested directory did not receive any cooking | :statuscode 404: requested directory did not receive any cooking | ||||
request yet (in case of GET) or can not be found in the archive | request yet (in case of GET) or can not be found in the archive | ||||
(in case of POST) | (in case of POST) | ||||
""" | """ | ||||
_, obj_id = query.parse_hash_with_algorithms_or_throws( | _, obj_id = query.parse_hash_with_algorithms_or_throws( | ||||
dir_id, ['sha1'], 'Only sha1_git is supported.') | dir_id, ['sha1'], 'Only sha1_git is supported.') | ||||
res = api_lookup( | res = api_lookup( | ||||
service.vault_fetch, 'directory', obj_id, | service.vault_fetch, 'directory', obj_id, | ||||
notfound_msg="Directory with ID '{}' not found.".format(dir_id)) | notfound_msg="Directory with ID '{}' not found.".format(dir_id), | ||||
request=request) | |||||
fname = '{}.tar.gz'.format(dir_id) | fname = '{}.tar.gz'.format(dir_id) | ||||
response = HttpResponse(res, content_type='application/gzip') | response = HttpResponse(res, content_type='application/gzip') | ||||
response['Content-disposition'] = 'attachment; filename={}'.format(fname) | response['Content-disposition'] = 'attachment; filename={}'.format(fname) | ||||
return response | return response | ||||
@api_route(r'/vault/revision/(?P<rev_id>[0-9a-f]+)/gitfast/', | @api_route(r'/vault/revision/(?P<rev_id>[0-9a-f]+)/gitfast/', | ||||
'api-1-vault-cook-revision_gitfast', methods=['GET', 'POST'], | 'api-1-vault-cook-revision_gitfast', methods=['GET', 'POST'], | ||||
▲ Show 20 Lines • Show All 84 Lines • ▼ Show 20 Lines | .. http:get:: /api/1/vault/revision/(rev_id)/gitfast/raw/ | ||||
:statuscode 404: requested directory did not receive any cooking | :statuscode 404: requested directory did not receive any cooking | ||||
request yet (in case of GET) or can not be found in the archive | request yet (in case of GET) or can not be found in the archive | ||||
(in case of POST) | (in case of POST) | ||||
""" | """ | ||||
_, obj_id = query.parse_hash_with_algorithms_or_throws( | _, obj_id = query.parse_hash_with_algorithms_or_throws( | ||||
rev_id, ['sha1'], 'Only sha1_git is supported.') | rev_id, ['sha1'], 'Only sha1_git is supported.') | ||||
res = api_lookup( | res = api_lookup( | ||||
service.vault_fetch, 'revision_gitfast', obj_id, | service.vault_fetch, 'revision_gitfast', obj_id, | ||||
notfound_msg="Revision with ID '{}' not found.".format(rev_id)) | notfound_msg="Revision with ID '{}' not found.".format(rev_id), | ||||
request=request) | |||||
fname = '{}.gitfast.gz'.format(rev_id) | fname = '{}.gitfast.gz'.format(rev_id) | ||||
response = HttpResponse(res, content_type='application/gzip') | response = HttpResponse(res, content_type='application/gzip') | ||||
response['Content-disposition'] = 'attachment; filename={}'.format(fname) | response['Content-disposition'] = 'attachment; filename={}'.format(fname) | ||||
return response | return response | ||||
@api_route(r'/vault/revision_gitfast/(?P<rev_id>[0-9a-f]+)/raw/', | @api_route(r'/vault/revision_gitfast/(?P<rev_id>[0-9a-f]+)/raw/', | ||||
'api-1-vault-revision_gitfast-raw', | 'api-1-vault-revision_gitfast-raw', | ||||
Show All 11 Lines |