Skip to content

Commit e07e92e

Browse files
committed
Return signed url as JSON object
1 parent e0dfcef commit e07e92e

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/stac_auth_proxy/handlers/s3_asset_signer.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import logging
44
import re
55
from dataclasses import dataclass
6+
from typing import Literal
67

78
import boto3
89
from botocore.exceptions import ClientError
@@ -16,17 +17,20 @@ class S3AssetSigner:
1617
bucket_pattern: str = r".*"
1718
max_expiration: int = 3600
1819

19-
def endpoint(self, payload: "S3AssetSignerPayload", expiration: int = 3600) -> str:
20+
def endpoint(
21+
self, payload: "S3AssetSignerPayload", expiration: int = 3600
22+
) -> dict[Literal["signed_url"], str]:
2023
"""Generate a presigned URL to share an S3 object."""
2124
if not re.match(self.bucket_pattern, payload.bucket_name):
2225
return HTTPException(status_code=404, detail="Item not found")
2326

2427
try:
25-
return boto3.client("s3").generate_presigned_url(
28+
url = boto3.client("s3").generate_presigned_url(
2629
"get_object",
2730
Params={"Bucket": payload.bucket_name, "Key": payload.object_name},
2831
ExpiresIn=min(expiration, self.max_expiration),
2932
)
33+
return {"signed_url": url}
3034
except ClientError as e:
3135
logging.error(e)
3236
return HTTPException(status_code=500, detail="Internal server error")

0 commit comments

Comments
 (0)