Skip to content

Commit 3ed43b0

Browse files
committed
Handle ceph bucket names
Fix an issue where multi-tenant ceph S3 bucket names would not be correctly parsed, since they include a colon.
1 parent 6d0019e commit 3ed43b0

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

python/lsst/resources/s3.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,15 @@ def profile(self) -> str | None:
200200

201201
@property
202202
def bucket(self) -> str:
203-
bucket = self._uri.hostname
203+
split = self._uri.netloc.split("@")
204+
num_components = len(split)
205+
if num_components == 2:
206+
bucket = split[1]
207+
elif num_components == 1:
208+
bucket = split[0]
209+
else:
210+
raise ValueError(f"Unexpected extra '@' in S3 URI: '{str(self)}'")
211+
204212
if not bucket:
205213
raise ValueError(f"S3 URI does not include bucket name: '{str(self)}'")
206214

tests/test_s3.py

+17
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,23 @@ def test_s3_endpoint_url(self):
266266
path.write(data)
267267
self.assertEqual(path.read(), data)
268268

269+
def test_uri_syntax(self):
270+
path1 = ResourcePath("s3://profile@bucket/path")
271+
self.assertEqual(path1.bucket, "bucket")
272+
self.assertEqual(path1.profile, "profile")
273+
path2 = ResourcePath("s3://bucket2/path")
274+
self.assertEqual(path2.bucket, "bucket2")
275+
self.assertEqual(path2.profile, None)
276+
277+
def test_ceph_uri_syntax(self):
278+
# The Ceph S3 'multi-tenant' syntax for buckets can include colons.
279+
path1 = ResourcePath("s3://profile@ceph:bucket/path")
280+
self.assertEqual(path1.bucket, "ceph:bucket")
281+
self.assertEqual(path1.profile, "profile")
282+
path2 = ResourcePath("s3://ceph:bucket2/path")
283+
self.assertEqual(path2.bucket, "ceph:bucket2")
284+
self.assertEqual(path2.profile, None)
285+
269286

270287
if __name__ == "__main__":
271288
unittest.main()

0 commit comments

Comments
 (0)