refactor(archivedlogs): move archivelog handler to endpoints
This commit is contained in:
parent
0d04fd8bd2
commit
5e995fae20
4 changed files with 54 additions and 22 deletions
|
@ -37,7 +37,7 @@ from util.invoice import renderInvoiceToPdf
|
|||
from util.saas.useranalytics import build_error_callback
|
||||
from util.systemlogs import build_logs_archive
|
||||
from util.useremails import send_email_changed
|
||||
|
||||
from util.registry.gzipinputstream import GzipInputStream
|
||||
|
||||
PGP_KEY_MIMETYPE = 'application/pgp-keys'
|
||||
|
||||
|
@ -336,6 +336,29 @@ def buildlogs(build_uuid):
|
|||
return response
|
||||
|
||||
|
||||
@web.route('/logarchive/<file_id>', methods=['GET'])
|
||||
@route_show_if(features.BUILD_SUPPORT)
|
||||
@require_session_login
|
||||
def logarchive(file_id):
|
||||
JSON_MIMETYPE = 'application/json'
|
||||
try:
|
||||
found_build = model.build.get_repository_build(file_id)
|
||||
except model.InvalidRepositoryBuildException as ex:
|
||||
logger.exception(ex, extra={'build_uuid': file_id})
|
||||
abort(403)
|
||||
|
||||
repo = found_build.repository
|
||||
if not ModifyRepositoryPermission(repo.namespace_user.username, repo.name).can():
|
||||
abort(403)
|
||||
|
||||
try:
|
||||
path = log_archive.get_file_id_path(file_id)
|
||||
data_stream = log_archive._storage.stream_read_file(log_archive._locations, path)
|
||||
return send_file(GzipInputStream(data_stream), mimetype=JSON_MIMETYPE)
|
||||
except IOError:
|
||||
logger.exception('Could not read archived logs')
|
||||
abort(403)
|
||||
|
||||
@web.route('/receipt', methods=['GET'])
|
||||
@route_show_if(features.BILLING)
|
||||
@require_session_login
|
||||
|
|
Reference in a new issue