Merge remote-tracking branch 'origin/master' into waltermitty
Conflicts: app.py data/userfiles.py
This commit is contained in:
commit
2455c17f96
23 changed files with 232 additions and 241 deletions
|
@ -1,39 +1,31 @@
|
|||
from data.userfiles import LocalUserfiles, UserfilesHandlers, S3Userfiles, FakeUserfiles
|
||||
from data.userfiles import DelegateUserfiles, UserfilesHandlers
|
||||
|
||||
class LogArchive(object):
|
||||
def __init__(self, app=None):
|
||||
def __init__(self, app=None, distributed_storage=None):
|
||||
self.app = app
|
||||
if app is not None:
|
||||
self.state = self.init_app(app)
|
||||
self.state = self.init_app(app, distributed_storage)
|
||||
else:
|
||||
self.state = None
|
||||
|
||||
def init_app(self, app):
|
||||
storage_type = app.config.get('LOG_ARCHIVE_TYPE', 'LocalArchivedLogs')
|
||||
path = app.config.get('LOG_ARCHIVE_PATH', '')
|
||||
def init_app(self, app, distributed_storage):
|
||||
location = app.config.get('LOG_ARCHIVE_LOCATION')
|
||||
path = app.config.get('LOG_ARCHIVE_PATH', None)
|
||||
|
||||
if storage_type == 'LocalArchivedLogs':
|
||||
archive = LocalUserfiles(app, path)
|
||||
app.add_url_rule('/archivedlogs/<file_id>',
|
||||
view_func=UserfilesHandlers.as_view('log_archive_handlers',
|
||||
local_userfiles=archive))
|
||||
handler_name = 'logarchive_handlers'
|
||||
|
||||
elif storage_type == 'S3ArchivedLogs':
|
||||
access_key = app.config.get('LOG_ARCHIVE_AWS_ACCESS_KEY', '')
|
||||
secret_key = app.config.get('LOG_ARCHIVE_AWS_SECRET_KEY', '')
|
||||
bucket = app.config.get('LOG_ARCHIVE_S3_BUCKET', '')
|
||||
archive = S3Userfiles(path, access_key, secret_key, bucket)
|
||||
log_archive = DelegateUserfiles(app, distributed_storage, location, path, handler_name)
|
||||
|
||||
elif storage_type == 'FakeArchivedLogs':
|
||||
archive = FakeUserfiles()
|
||||
|
||||
else:
|
||||
raise RuntimeError('Unknown log archive type: %s' % storage_type)
|
||||
app.add_url_rule('/logarchive/<file_id>',
|
||||
view_func=UserfilesHandlers.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'] = archive
|
||||
return archive
|
||||
app.extensions['log_archive'] = log_archive
|
||||
return log_archive
|
||||
|
||||
def __getattr__(self, name):
|
||||
return getattr(self.state, name, None)
|
||||
|
|
Reference in a new issue