From b9e29b3d57a8fa5cfa08e157d4d79bf6d313f869 Mon Sep 17 00:00:00 2001 From: Benjamin Bolte Date: Tue, 20 Aug 2024 14:29:41 -0700 Subject: [PATCH] remove downloads --- store/app/crud/artifacts.py | 13 ++----------- store/app/crud/base.py | 10 ++++------ store/settings/configs/local.yaml | 1 - store/settings/environment.py | 1 - 4 files changed, 6 insertions(+), 19 deletions(-) diff --git a/store/app/crud/artifacts.py b/store/app/crud/artifacts.py index 5c8dcdfb..e5bec83e 100644 --- a/store/app/crud/artifacts.py +++ b/store/app/crud/artifacts.py @@ -7,7 +7,6 @@ from xml.etree import ElementTree as ET import trimesh -from aiobotocore.response import StreamingBody from boto3.dynamodb.conditions import ComparisonCondition from fastapi import UploadFile from PIL import Image @@ -65,7 +64,7 @@ async def _crop_image(self, image: Image.Image, size: tuple[int, int]) -> IO[byt async def _upload_cropped_image(self, image: Image.Image, artifact: Artifact, size: ArtifactSize) -> None: image_bytes = await self._crop_image(image, SizeMapping[size]) filename = get_artifact_name(artifact=artifact, size=size) - await self._upload_to_s3(image_bytes, artifact.name, filename, "image/png", private=False) + await self._upload_to_s3(image_bytes, artifact.name, filename, "image/png") async def _upload_image( self, @@ -165,7 +164,7 @@ async def _upload_and_store( description=description, ) await asyncio.gather( - self._upload_to_s3(file, name, get_artifact_name(artifact=artifact), content_type, private=True), + self._upload_to_s3(file, name, get_artifact_name(artifact=artifact), content_type), self._add_item(artifact), ) return artifact @@ -206,14 +205,6 @@ async def _remove_raw_artifact(self, artifact: Artifact) -> None: self._delete_item(artifact), ) - async def stream_artifact( - self, - artifact: Artifact, - private: bool = True, - size: ArtifactSize = "large", - ) -> StreamingBody: - return await self._download_from_s3(get_artifact_name(artifact=artifact, size=size), private=private) - async def remove_artifact(self, artifact: Artifact) -> None: match artifact.artifact_type: case "image": diff --git a/store/app/crud/base.py b/store/app/crud/base.py index 6115eacc..7a258e73 100644 --- a/store/app/crud/base.py +++ b/store/app/crud/base.py @@ -364,7 +364,7 @@ async def _update_item(self, item_id: str, item_class: type[T], new_values: dict AttributeUpdates={k: {"Value": v, "Action": "PUT"} for k, v in new_values.items() if k != "id"}, ) - async def _upload_to_s3(self, data: IO[bytes], name: str, filename: str, content_type: str, private: bool) -> None: + async def _upload_to_s3(self, data: IO[bytes], name: str, filename: str, content_type: str) -> None: """Uploads some data to S3. Args: @@ -373,28 +373,26 @@ async def _upload_to_s3(self, data: IO[bytes], name: str, filename: str, content filename: The resulting filename in S3 (should be unique). content_type: The file content type, for CloudFront to provide in the file header when the user retrieves it. - private: Whether the object is in the private S3 bucket. """ bucket = await self.s3.Bucket(settings.s3.bucket) await bucket.put_object( - Key=f"{settings.s3.private_prefix if private else settings.s3.prefix}{filename}", + Key=f"{settings.s3.prefix}{filename}", Body=data, ContentType=content_type, ContentDisposition=f'attachment; filename="{name}"', ) - async def _download_from_s3(self, filename: str, private: bool) -> StreamingBody: + async def _download_from_s3(self, filename: str) -> StreamingBody: """Downloads an object from S3. Args: filename: The filename of the object to download. - private: Whether the object is in the private S3 bucket. Returns: The object data. """ bucket = await self.s3.Bucket(settings.s3.bucket) - obj = await bucket.Object(f"{settings.s3.private_prefix if private else settings.s3.prefix}{filename}") + obj = await bucket.Object(f"{settings.s3.prefix}{filename}") data = await obj.get() return data["Body"] diff --git a/store/settings/configs/local.yaml b/store/settings/configs/local.yaml index abed744f..82434688 100644 --- a/store/settings/configs/local.yaml +++ b/store/settings/configs/local.yaml @@ -3,7 +3,6 @@ crypto: s3: bucket: artifacts prefix: media - private_prefix: private-media dynamo: table_name: kscale-store-local site: diff --git a/store/settings/environment.py b/store/settings/environment.py index b57fb5e4..048ef04b 100644 --- a/store/settings/environment.py +++ b/store/settings/environment.py @@ -51,7 +51,6 @@ class ArtifactSettings: class S3Settings: bucket: str = field(default=II("oc.env:S3_BUCKET")) prefix: str = field(default=II("oc.env:S3_PREFIX")) - private_prefix: str = field(default=II("oc.env:S3_PRIVATE_PREFIX")) @dataclass