From b1ae9e8ce81ea828a491f193f356e6d638dee454 Mon Sep 17 00:00:00 2001 From: Alok Saldanha Date: Fri, 2 Apr 2021 11:37:11 -0400 Subject: [PATCH] ensure s3 bucket does not include trailing slash --- cellxgene_gateway/items/s3/s3item_source.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cellxgene_gateway/items/s3/s3item_source.py b/cellxgene_gateway/items/s3/s3item_source.py index bcf7d39..39abe03 100644 --- a/cellxgene_gateway/items/s3/s3item_source.py +++ b/cellxgene_gateway/items/s3/s3item_source.py @@ -29,6 +29,8 @@ class S3ItemSource(ItemSource): ): self._name = name self.s3 = s3fs.S3FileSystem() + if bucket.startswith('s3://'): + raise Exception(f"Bucket name should not include s3:// prefix, got {bucket}") self.bucket = bucket self.h5ad_suffix = h5ad_suffix self.annotation_dir_suffix = annotation_dir_suffix @@ -67,7 +69,7 @@ class S3ItemSource(ItemSource): raise Exception(f"S3 url '{url}' does not exist.") s3key_map = dict( - (filepath[len(self.bucket) :], "s3://" + filepath) + (filepath[len(self.bucket) :].lstrip('/'), "s3://" + filepath) for filepath in sorted(self.s3.ls(url)) )