Changeset View
Changeset View
Standalone View
Standalone View
swh/web/api/views/vault.py
Show All 25 Lines | def _dispatch_cook_progress(request, obj_type, obj_id): | ||||
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))) | ||||
@api_route(r'/vault/directory/(?P<dir_id>[a-fA-F0-9]+)/', | @api_route(r'/vault/directory/(?P<dir_id>[0-9a-f]+)/', | ||||
'api-vault-cook-directory', methods=['GET', 'POST'], | 'api-vault-cook-directory', methods=['GET', 'POST'], | ||||
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/') | ||||
def api_vault_cook_directory(request, dir_id): | def api_vault_cook_directory(request, dir_id): | ||||
""" | """ | ||||
.. http:get:: /api/1/vault/directory/(dir_id)/ | .. http:get:: /api/1/vault/directory/(dir_id)/ | ||||
.. http:post:: /api/1/vault/directory/(dir_id)/ | .. http:post:: /api/1/vault/directory/(dir_id)/ | ||||
Show All 38 Lines | _, 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 = _dispatch_cook_progress(request, 'directory', obj_id) | res = _dispatch_cook_progress(request, 'directory', obj_id) | ||||
res['fetch_url'] = reverse('api-vault-fetch-directory', | res['fetch_url'] = reverse('api-vault-fetch-directory', | ||||
url_args={'dir_id': dir_id}) | url_args={'dir_id': dir_id}) | ||||
return res | return res | ||||
@api_route(r'/vault/directory/(?P<dir_id>[a-fA-F0-9]+)/raw/', | @api_route(r'/vault/directory/(?P<dir_id>[0-9a-f]+)/raw/', | ||||
'api-vault-fetch-directory') | 'api-vault-fetch-directory', | ||||
checksum_args=['dir_id']) | |||||
@api_doc('/vault/directory/raw/', handle_response=True) | @api_doc('/vault/directory/raw/', handle_response=True) | ||||
def api_vault_fetch_directory(request, dir_id): | def api_vault_fetch_directory(request, dir_id): | ||||
""" | """ | ||||
.. http:get:: /api/1/vault/directory/(dir_id)/raw/ | .. http:get:: /api/1/vault/directory/(dir_id)/raw/ | ||||
Fetch the cooked archive for a directory. | Fetch the cooked archive for a directory. | ||||
See :http:get:`/api/1/vault/directory/(dir_id)/` to get more | See :http:get:`/api/1/vault/directory/(dir_id)/` to get more | ||||
Show All 15 Lines | 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)) | ||||
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>[a-fA-F0-9]+)/gitfast/', | @api_route(r'/vault/revision/(?P<rev_id>[0-9a-f]+)/gitfast/', | ||||
'api-vault-cook-revision_gitfast', methods=['GET', 'POST'], | 'api-vault-cook-revision_gitfast', methods=['GET', 'POST'], | ||||
checksum_args=['rev_id'], | |||||
throttle_scope='swh_vault_cooking') | throttle_scope='swh_vault_cooking') | ||||
@never_cache | @never_cache | ||||
@api_doc('/vault/revision/gitfast/') | @api_doc('/vault/revision/gitfast/') | ||||
def api_vault_cook_revision_gitfast(request, rev_id): | def api_vault_cook_revision_gitfast(request, rev_id): | ||||
""" | """ | ||||
.. http:get:: /api/1/vault/revision/(rev_id)/gitfast/ | .. http:get:: /api/1/vault/revision/(rev_id)/gitfast/ | ||||
.. http:post:: /api/1/vault/revision/(rev_id)/gitfast/ | .. http:post:: /api/1/vault/revision/(rev_id)/gitfast/ | ||||
Show All 39 Lines | _, 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 = _dispatch_cook_progress(request, 'revision_gitfast', obj_id) | res = _dispatch_cook_progress(request, 'revision_gitfast', obj_id) | ||||
res['fetch_url'] = reverse('api-vault-fetch-revision_gitfast', | res['fetch_url'] = reverse('api-vault-fetch-revision_gitfast', | ||||
url_args={'rev_id': rev_id}) | url_args={'rev_id': rev_id}) | ||||
return res | return res | ||||
@api_route(r'/vault/revision/(?P<rev_id>[a-fA-F0-9]+)/gitfast/raw/', | @api_route(r'/vault/revision/(?P<rev_id>[0-9a-f]+)/gitfast/raw/', | ||||
'api-vault-fetch-revision_gitfast') | 'api-vault-fetch-revision_gitfast', | ||||
checksum_args=['rev_id']) | |||||
@api_doc('/vault/revision/gitfast/raw/', handle_response=True) | @api_doc('/vault/revision/gitfast/raw/', handle_response=True) | ||||
def api_vault_fetch_revision_gitfast(request, rev_id): | def api_vault_fetch_revision_gitfast(request, rev_id): | ||||
""" | """ | ||||
.. http:get:: /api/1/vault/revision/(rev_id)/gitfast/raw/ | .. http:get:: /api/1/vault/revision/(rev_id)/gitfast/raw/ | ||||
Fetch the cooked gitfast archive for a revision. | Fetch the cooked gitfast archive for a revision. | ||||
See :http:get:`/api/1/vault/revision/(rev_id)/gitfast/` to get more | See :http:get:`/api/1/vault/revision/(rev_id)/gitfast/` to get more | ||||
Show All 21 Lines |