userfiles: make handler optional
This commit is contained in:
parent
c7c52e6c74
commit
3d190b786f
3 changed files with 22 additions and 7 deletions
|
@ -38,7 +38,8 @@ class LogArchive(object):
|
||||||
|
|
||||||
handler_name = 'logarchive_handlers'
|
handler_name = 'logarchive_handlers'
|
||||||
|
|
||||||
log_archive = DelegateUserfiles(app, distributed_storage, location, path, handler_name)
|
log_archive = DelegateUserfiles(app, distributed_storage, location, path,
|
||||||
|
handler_name=handler_name)
|
||||||
|
|
||||||
app.add_url_rule('/logarchive/<file_id>',
|
app.add_url_rule('/logarchive/<file_id>',
|
||||||
view_func=LogArchiveHandlers.as_view(handler_name,
|
view_func=LogArchiveHandlers.as_view(handler_name,
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
import magic
|
|
||||||
import urlparse
|
import urlparse
|
||||||
|
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
from _pyio import BufferedReader
|
||||||
|
|
||||||
|
import magic
|
||||||
|
|
||||||
from flask import url_for, request, send_file, make_response, abort
|
from flask import url_for, request, send_file, make_response, abort
|
||||||
from flask.views import View
|
from flask.views import View
|
||||||
from _pyio import BufferedReader
|
|
||||||
from util import get_app_url
|
from util import get_app_url
|
||||||
|
|
||||||
|
|
||||||
|
@ -53,8 +55,12 @@ class UserfilesHandlers(View):
|
||||||
return self.put(file_id)
|
return self.put(file_id)
|
||||||
|
|
||||||
|
|
||||||
|
class MissingHandlerException(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class DelegateUserfiles(object):
|
class DelegateUserfiles(object):
|
||||||
def __init__(self, app, distributed_storage, location, path, handler_name):
|
def __init__(self, app, distributed_storage, location, path, handler_name=None):
|
||||||
self._app = app
|
self._app = app
|
||||||
self._storage = distributed_storage
|
self._storage = distributed_storage
|
||||||
self._locations = {location}
|
self._locations = {location}
|
||||||
|
@ -77,6 +83,9 @@ class DelegateUserfiles(object):
|
||||||
url = self._storage.get_direct_upload_url(self._locations, path, mime_type, requires_cors)
|
url = self._storage.get_direct_upload_url(self._locations, path, mime_type, requires_cors)
|
||||||
|
|
||||||
if url is None:
|
if url is None:
|
||||||
|
if self._handler_name is None:
|
||||||
|
raise MissingHandlerException()
|
||||||
|
|
||||||
with self._app.app_context() as ctx:
|
with self._app.app_context() as ctx:
|
||||||
ctx.url_adapter = self._build_url_adapter()
|
ctx.url_adapter = self._build_url_adapter()
|
||||||
file_relative_url = url_for(self._handler_name, file_id=file_id)
|
file_relative_url = url_for(self._handler_name, file_id=file_id)
|
||||||
|
@ -99,6 +108,9 @@ class DelegateUserfiles(object):
|
||||||
url = self._storage.get_direct_download_url(self._locations, path, expires_in, requires_cors)
|
url = self._storage.get_direct_download_url(self._locations, path, expires_in, requires_cors)
|
||||||
|
|
||||||
if url is None:
|
if url is None:
|
||||||
|
if self._handler_name is None:
|
||||||
|
raise MissingHandlerException()
|
||||||
|
|
||||||
with self._app.app_context() as ctx:
|
with self._app.app_context() as ctx:
|
||||||
ctx.url_adapter = self._build_url_adapter()
|
ctx.url_adapter = self._build_url_adapter()
|
||||||
file_relative_url = url_for(self._handler_name, file_id=file_id)
|
file_relative_url = url_for(self._handler_name, file_id=file_id)
|
||||||
|
@ -125,7 +137,8 @@ class Userfiles(object):
|
||||||
|
|
||||||
handler_name = 'userfiles_handlers'
|
handler_name = 'userfiles_handlers'
|
||||||
|
|
||||||
userfiles = DelegateUserfiles(app, distributed_storage, location, path, handler_name)
|
userfiles = DelegateUserfiles(app, distributed_storage, location, path,
|
||||||
|
handler_name=handler_name)
|
||||||
|
|
||||||
app.add_url_rule('/userfiles/<file_id>',
|
app.add_url_rule('/userfiles/<file_id>',
|
||||||
view_func=UserfilesHandlers.as_view(handler_name,
|
view_func=UserfilesHandlers.as_view(handler_name,
|
||||||
|
|
|
@ -36,8 +36,9 @@ class LogRotateWorker(Worker):
|
||||||
|
|
||||||
def _archive_logs(self):
|
def _archive_logs(self):
|
||||||
logger.debug('Attempting to rotate log entries')
|
logger.debug('Attempting to rotate log entries')
|
||||||
log_archive = DelegateUserfiles(app, storage, SAVE_LOCATION, SAVE_PATH,
|
|
||||||
'action_log_archive_handlers')
|
log_archive = DelegateUserfiles(app, storage, SAVE_LOCATION, SAVE_PATH)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
with GlobalLock('ACTION_LOG_ROTATION') as gl:
|
with GlobalLock('ACTION_LOG_ROTATION') as gl:
|
||||||
if not gl:
|
if not gl:
|
||||||
|
|
Reference in a new issue