Skip to content

Commit 9d851f8

Browse files
committed
bye legacy url
1 parent 58f1646 commit 9d851f8

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

packages/aws-library/src/aws_library/s3/_client.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from boto3.s3.transfer import TransferConfig
1414
from botocore import exceptions as botocore_exc
1515
from botocore.client import Config
16-
from common_library.pydantic_networks_extension import AnyUrlLegacy
1716
from models_library.api_schemas_storage import ETag, S3BucketName, UploadedPart
1817
from models_library.basic_types import SHA256Str
1918
from pydantic import AnyUrl, ByteSize, TypeAdapter
@@ -255,7 +254,7 @@ async def create_single_presigned_download_link(
255254
bucket: S3BucketName,
256255
object_key: S3ObjectKey,
257256
expiration_secs: int,
258-
) -> str:
257+
) -> AnyUrl:
259258
# NOTE: ensure the bucket/object exists, this will raise if not
260259
await self._client.head_bucket(Bucket=bucket)
261260
await self._client.head_object(Bucket=bucket, Key=object_key)
@@ -264,20 +263,20 @@ async def create_single_presigned_download_link(
264263
Params={"Bucket": bucket, "Key": object_key},
265264
ExpiresIn=expiration_secs,
266265
)
267-
return f"{TypeAdapter(AnyUrlLegacy).validate_python(generated_link)}"
266+
return TypeAdapter(AnyUrl).validate_python(generated_link)
268267

269268
@s3_exception_handler(_logger)
270269
async def create_single_presigned_upload_link(
271270
self, *, bucket: S3BucketName, object_key: S3ObjectKey, expiration_secs: int
272-
) -> str:
271+
) -> AnyUrl:
273272
# NOTE: ensure the bucket/object exists, this will raise if not
274273
await self._client.head_bucket(Bucket=bucket)
275274
generated_link = await self._client.generate_presigned_url(
276275
"put_object",
277276
Params={"Bucket": bucket, "Key": object_key},
278277
ExpiresIn=expiration_secs,
279278
)
280-
return f"{TypeAdapter(AnyUrlLegacy).validate_python(generated_link)}"
279+
return TypeAdapter(AnyUrl).validate_python(generated_link)
281280

282281
@s3_exception_handler(_logger)
283282
async def create_multipart_upload_links(
@@ -474,6 +473,6 @@ def is_multipart(file_size: ByteSize) -> bool:
474473

475474
@staticmethod
476475
def compute_s3_url(*, bucket: S3BucketName, object_key: S3ObjectKey) -> AnyUrl:
477-
return TypeAdapter(AnyUrlLegacy).validate_python(
476+
return TypeAdapter(AnyUrl).validate_python(
478477
f"s3://{bucket}/{urllib.parse.quote(object_key)}"
479478
)

packages/aws-library/tests/test_s3_client.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ async def test_create_single_presigned_upload_link(
742742
create_file_of_size: Callable[[ByteSize], Path],
743743
default_expiration_time_seconds: int,
744744
upload_to_presigned_link: Callable[
745-
[Path, str, S3BucketName, S3ObjectKey], Awaitable[None]
745+
[Path, AnyUrl, S3BucketName, S3ObjectKey], Awaitable[None]
746746
],
747747
):
748748
file = create_file_of_size(TypeAdapter(ByteSize).validate_python("1Mib"))
@@ -1289,20 +1289,24 @@ def test_is_multipart(file_size: ByteSize, expected_multipart: bool):
12891289
(
12901290
"some-bucket",
12911291
"an/object/separate/by/slashes",
1292-
"s3://some-bucket/an/object/separate/by/slashes",
1292+
TypeAdapter(AnyUrl).validate_python(
1293+
"s3://some-bucket/an/object/separate/by/slashes"
1294+
),
12931295
),
12941296
(
12951297
"some-bucket",
12961298
"an/object/separate/by/slashes-?/3#$",
1297-
r"s3://some-bucket/an/object/separate/by/slashes-%3F/3%23%24",
1299+
TypeAdapter(AnyUrl).validate_python(
1300+
r"s3://some-bucket/an/object/separate/by/slashes-%3F/3%23%24"
1301+
),
12981302
),
12991303
],
13001304
)
13011305
def test_compute_s3_url(
13021306
bucket: S3BucketName, object_key: S3ObjectKey, expected_s3_url: AnyUrl
13031307
):
13041308
assert (
1305-
str(SimcoreS3API.compute_s3_url(bucket=bucket, object_key=object_key))
1309+
SimcoreS3API.compute_s3_url(bucket=bucket, object_key=object_key)
13061310
== expected_s3_url
13071311
)
13081312

0 commit comments

Comments
 (0)