Initial attempt at modularizing CSP integration
This commit is contained in:
parent
442e136a4b
commit
d6ff3406ef
14
atst/app.py
14
atst/app.py
@ -21,9 +21,9 @@ from atst.routes.errors import make_error_pages
|
|||||||
from atst.domain.authnid.crl import CRLCache
|
from atst.domain.authnid.crl import CRLCache
|
||||||
from atst.domain.auth import apply_authentication
|
from atst.domain.auth import apply_authentication
|
||||||
from atst.domain.authz import Authorization
|
from atst.domain.authz import Authorization
|
||||||
|
from atst.domain.csp import make_csp_provider
|
||||||
from atst.models.permissions import Permissions
|
from atst.models.permissions import Permissions
|
||||||
from atst.eda_client import MockEDAClient
|
from atst.eda_client import MockEDAClient
|
||||||
from atst.uploader import Uploader
|
|
||||||
from atst.utils import mailer
|
from atst.utils import mailer
|
||||||
from atst.utils.form_cache import FormCache
|
from atst.utils.form_cache import FormCache
|
||||||
from atst.queue import queue
|
from atst.queue import queue
|
||||||
@ -52,7 +52,7 @@ def make_app(config):
|
|||||||
make_crl_validator(app)
|
make_crl_validator(app)
|
||||||
register_filters(app)
|
register_filters(app)
|
||||||
make_eda_client(app)
|
make_eda_client(app)
|
||||||
make_upload_storage(app)
|
make_csp_provider(app)
|
||||||
make_mailer(app)
|
make_mailer(app)
|
||||||
queue.init_app(app)
|
queue.init_app(app)
|
||||||
|
|
||||||
@ -191,16 +191,6 @@ def make_eda_client(app):
|
|||||||
app.eda_client = MockEDAClient()
|
app.eda_client = MockEDAClient()
|
||||||
|
|
||||||
|
|
||||||
def make_upload_storage(app):
|
|
||||||
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"),
|
|
||||||
)
|
|
||||||
app.uploader = uploader
|
|
||||||
|
|
||||||
|
|
||||||
def make_mailer(app):
|
def make_mailer(app):
|
||||||
if app.config["DEBUG"]:
|
if app.config["DEBUG"]:
|
||||||
mailer_connection = mailer.RedisConnection(app.redis)
|
mailer_connection = mailer.RedisConnection(app.redis)
|
||||||
|
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)
|
@ -25,7 +25,7 @@ class Attachment(Base, mixins.TimestampsMixin):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def attach(cls, fyle, resource=None, resource_id=None):
|
def attach(cls, fyle, resource=None, resource_id=None):
|
||||||
try:
|
try:
|
||||||
object_name = app.uploader.upload(fyle)
|
object_name = app.csp.files.upload(fyle)
|
||||||
except UploadError as e:
|
except UploadError as e:
|
||||||
raise AttachmentError("Could not add attachment. " + str(e))
|
raise AttachmentError("Could not add attachment. " + str(e))
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ def task_order_pdf_download(request_id):
|
|||||||
request = Requests.get(g.current_user, request_id)
|
request = Requests.get(g.current_user, request_id)
|
||||||
if request.legacy_task_order and request.legacy_task_order.pdf:
|
if request.legacy_task_order and request.legacy_task_order.pdf:
|
||||||
pdf = request.legacy_task_order.pdf
|
pdf = request.legacy_task_order.pdf
|
||||||
generator = app.uploader.download_stream(pdf.object_name)
|
generator = app.csp.files.download(pdf.object_name)
|
||||||
return Response(
|
return Response(
|
||||||
generator,
|
generator,
|
||||||
headers={
|
headers={
|
||||||
|
Loading…
x
Reference in New Issue
Block a user