Initial attempt at modularizing CSP integration
This commit is contained in:
11
atst/domain/csp/__init__.py
Normal file
11
atst/domain/csp/__init__.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from .files import RackspaceFiles
|
||||
|
||||
|
||||
class MockCSP:
|
||||
|
||||
def __init__(self, file_provider):
|
||||
self.files = file_provider
|
||||
|
||||
|
||||
def make_csp_provider(app):
|
||||
app.csp = MockCSP(RackspaceFiles(app))
|
||||
30
atst/domain/csp/files.py
Normal file
30
atst/domain/csp/files.py
Normal file
@@ -0,0 +1,30 @@
|
||||
from atst.uploader import Uploader
|
||||
|
||||
|
||||
class Files:
|
||||
def upload(self, fyle): # pragma: no cover
|
||||
"""Store the file object `fyle` in the CSP. This method returns the
|
||||
object name that can be used to later look up the file."""
|
||||
raise NotImplementedError()
|
||||
|
||||
def download(self, object_name): # pragma: no cover
|
||||
"""Retrieve the stored file represented by `object_name`. Returns a
|
||||
file object.
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
|
||||
class RackspaceFiles(Files):
|
||||
def __init__(self, app):
|
||||
self.uploader = Uploader(
|
||||
provider=app.config.get("STORAGE_PROVIDER"),
|
||||
container=app.config.get("STORAGE_CONTAINER"),
|
||||
key=app.config.get("STORAGE_KEY"),
|
||||
secret=app.config.get("STORAGE_SECRET"),
|
||||
)
|
||||
|
||||
def upload(self, fyle):
|
||||
return self.uploader.upload(fyle)
|
||||
|
||||
def download(self, object_name):
|
||||
return self.uploader.download_stream(object_name)
|
||||
Reference in New Issue
Block a user