refactor(archivedlogs): move archivelog handler to endpoints

This commit is contained in:
EvB 2017-04-24 15:59:10 -04:00
parent 0d04fd8bd2
commit 5e995fae20
4 changed files with 54 additions and 22 deletions

View file

@ -12,19 +12,6 @@ JSON_MIMETYPE = 'application/json'
logger = logging.getLogger(__name__)
class LogArchiveHandlers(UserfilesHandlers):
methods = ['GET']
def get(self, file_id):
path = self._files.get_file_id_path(file_id)
try:
data_stream = self._storage.stream_read_file(self._locations, path)
return send_file(GzipInputStream(data_stream), mimetype=JSON_MIMETYPE)
except IOError:
logger.exception('Could not read archived logs')
abort(404)
class LogArchive(object):
def __init__(self, app=None, distributed_storage=None):
self.app = app
@ -41,13 +28,6 @@ class LogArchive(object):
log_archive = DelegateUserfiles(app, distributed_storage, location, path,
handler_name=handler_name)
app.add_url_rule('/logarchive/<file_id>',
view_func=LogArchiveHandlers.as_view(handler_name,
distributed_storage=distributed_storage,
location=location,
files=log_archive))
# register extension with app
app.extensions = getattr(app, 'extensions', {})
app.extensions['log_archive'] = log_archive