Skip to content

Commit

Permalink
fix handler, fix mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
KonstantAnxiety committed Dec 19, 2024
1 parent 2a1bf4a commit 7b73fe3
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ def create_app(self, app_version: str) -> web.Application:
app.router.add_route("get", "/api/v2/metrics", MetricsView)

app.router.add_route("post", "/api/v2/files", files_views.FilesView)
app.router.add_route("post", "/api/v2/make_presigned_url", files_views.MakePresignedUrlView)
app.router.add_route("post", "/api/v2/links", files_views.LinksView)
app.router.add_route("post", "/api/v2/documents", files_views.DocumentsView)
app.router.add_route("post", "/api/v2/update_connection_data", files_views.UpdateConnectionDataView)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@ class Meta:
unknown = ma.INCLUDE

key = ma.fields.String()
x_amz_algorithm = ma.fields.String(data_key="x-amz-algorithm")
x_amz_credential = ma.fields.String(data_key="x-amz-credential")
x_amz_date = ma.fields.String(data_key="x-amz-date")
x_amz_algorithm = ma.fields.String(attribute="x-amz-algorithm", data_key="x-amz-algorithm")
x_amz_credential = ma.fields.String(attribute="x-amz-credential", data_key="x-amz-credential")
x_amz_date = ma.fields.String(attribute="x-amz-date", data_key="x-amz-date")
policy = ma.fields.String()
x_amz_signature = ma.fields.String(data_key="x-amz-signature")
x_amz_signature = ma.fields.String(attribute="x-amz-signature", data_key="x-amz-signature")

url = ma.fields.String(required=True)
fields = ma.fields.Nested(PresignedUrlFields)
_fields = ma.fields.Nested(PresignedUrlFields, required=True, attribute="fields", data_key="fields")


class FileStatusRequestSchema(BaseRequestSchema):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,23 +131,21 @@ async def _chunk_iter(chunk_size: int = 10 * 1024 * 1024) -> AsyncGenerator[byte


class MakePresignedUrlView(FileUploaderBaseView):
REQUIRED_RESOURCES: ClassVar[frozenset[RequiredResource]] = frozenset() # Don't skip CSRF check

async def post(self) -> web.StreamResponse:
req_data = await self._load_post_request_schema_data(files_schemas.MakePresignedUrlRequestSchema)
content_md5: str = req_data["content_md5"]

s3 = self.dl_request.get_s3_service()
s3_key = "{}_{}".format(self.dl_request.rci.user_id or "unknown", str(uuid.uuid4()))

url = s3.client.generate_presigned_post(
url = await s3.client.generate_presigned_post(
Bucket=s3.tmp_bucket_name,
Key=s3_key,
ExpiresIn=60 * 60, # 1 hour # TODO config?
Conditions=[
["content-length-range", 1, 200 * 1024 * 1024], # 1B .. 200MB # TODO use constant
{"Content-MD5": content_md5},
]
],
)

return web.json_response(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def upload_documents(
def presigned_url(cls, content_md5: str, *, require_ok: bool = True) -> Req:
return Req(
method="post",
url=f"/api/v2/make_presigned_url",
url="/api/v2/make_presigned_url",
data_json={
"content_md5": content_md5,
},
Expand Down
2 changes: 1 addition & 1 deletion lib/dl_s3/dl_s3/s3_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ async def initialize(self) -> None:
aws_access_key_id=self._access_key_id,
aws_secret_access_key=self._secret_access_key,
endpoint_url=self._endpoint_url,
config=AioConfig(signature_version="s3v4")
config=AioConfig(signature_version="s3v4"),
)

session = get_session()
Expand Down

0 comments on commit 7b73fe3

Please sign in to comment.