Skip to content

Commit 8ddb459

Browse files
authored
Merge pull request #97 from lsst/tickets/DM-46701
DM-46701: Implement generate_presigned_get_url for plain HTTP
2 parents cc6cc24 + f27ef02 commit 8ddb459

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

python/lsst/resources/http.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1261,7 +1261,9 @@ def generate_presigned_get_url(self, *, expiration_time_seconds: int) -> str:
12611261
HTTP URL signed for GET.
12621262
"""
12631263
if not self.is_webdav_endpoint:
1264-
return super().generate_presigned_get_url(expiration_time_seconds=expiration_time_seconds)
1264+
# This is already an HTTP URL readable without any authentication
1265+
# credentials, so return it as-is.
1266+
return str(self)
12651267

12661268
return self._sign_with_macaroon(ActivityCaveat.DOWNLOAD, expiration_time_seconds)
12671269

@@ -1867,7 +1869,7 @@ def _openImpl(
18671869
if mode == "r":
18681870
# cast because the protocol is compatible, but does not have
18691871
# BytesIO in the inheritance tree
1870-
yield io.TextIOWrapper(cast(io.BytesIO, handle), encoding=encoding)
1872+
yield io.TextIOWrapper(cast(Any, handle), encoding=encoding)
18711873
else:
18721874
yield handle
18731875
else:

tests/test_http.py

+19
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,25 @@ def test_is_webdav_endpoint(self):
460460
responses.add(responses.OPTIONS, notWebdavEndpoint, status=403)
461461
self.assertFalse(ResourcePath(notWebdavEndpoint).is_webdav_endpoint)
462462

463+
@responses.activate
464+
def test_plain_http_url_signing(self):
465+
# As in test_is_webdav_endpoint above, configure a URL to appear as a
466+
# non-webdav HTTP server.
467+
plainHttpEndpoint = "http://nonwebdav.test"
468+
responses.add(responses.OPTIONS, plainHttpEndpoint, status=200)
469+
470+
# Plain HTTP URLs are already readable without authentication, so
471+
# generating a pre-signed URL is a no-op.
472+
path = ResourcePath("http://nonwebdav.test/file")
473+
self.assertEqual(
474+
path.generate_presigned_get_url(expiration_time_seconds=300), "http://nonwebdav.test/file"
475+
)
476+
477+
# Writing to an arbitrary plain HTTP URL is unlikely to work, so we
478+
# don't generate put URLs.
479+
with self.assertRaises(NotImplementedError):
480+
path.generate_presigned_put_url(expiration_time_seconds=300)
481+
463482
@responses.activate
464483
def test_server_identity(self):
465484
server = "MyServer/v1.2.3"

0 commit comments

Comments
 (0)