mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-07-12 13:29:04 +00:00
33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
from typing import Any
|
|
|
|
|
|
class S3Client:
|
|
def __init__(self, boto_s3_client: Any, bucket: str) -> None:
|
|
self._client = boto_s3_client
|
|
self._bucket = bucket
|
|
|
|
@property
|
|
def bucket(self) -> str:
|
|
return self._bucket
|
|
|
|
def get_object(self, key: str) -> bytes:
|
|
response: dict[str, Any] = self._client.get_object(
|
|
Bucket=self._bucket, Key=key
|
|
)
|
|
body: bytes = response["Body"].read()
|
|
return body
|
|
|
|
def put_object(self, key: str, body: bytes) -> str:
|
|
self._client.put_object(Bucket=self._bucket, Key=key, Body=body)
|
|
return f"s3://{self._bucket}/{key}"
|
|
|
|
def generate_presigned_url(self, key: str, expires_in: int) -> str:
|
|
"""A time-limited URL that lets the holder GET this object without AWS
|
|
credentials (ADR-0060 — how a Download Package link is delivered).
|
|
``expires_in`` is the validity window in seconds."""
|
|
url: str = self._client.generate_presigned_url(
|
|
"get_object",
|
|
Params={"Bucket": self._bucket, "Key": key},
|
|
ExpiresIn=expires_in,
|
|
)
|
|
return url
|