Skip to content

Commit

Permalink
Add S3 Object Lambda ARN and S3 Outposts ARN (#686)
Browse files Browse the repository at this point in the history

Co-authored-by: Martin Durant <martin.durant@alumni.utoronto.ca>
  • Loading branch information
matsalla and martindurant committed Jan 13, 2023
1 parent 9bf99f7 commit 11c4ff5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
41 changes: 26 additions & 15 deletions s3fs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,20 +377,29 @@ def _find_bucket_key(self, s3_path):
It will return the bucket and the key represented by the s3 path
"""

_S3_ACCESSPOINT_TO_BUCKET_KEY_REGEX = re.compile(
r"^(?P<bucket>arn:(aws).*:s3:[a-z\-0-9]*:[0-9]{12}:accesspoint[:/][^/]+)/?"
r"(?P<key>.*)$"
)
_S3_OUTPOST_TO_BUCKET_KEY_REGEX = re.compile(
r"^(?P<bucket>arn:(aws).*:s3-outposts:[a-z\-0-9]+:[0-9]{12}:outpost[/:]"
r"[a-zA-Z0-9\-]{1,63}[/:](bucket|accesspoint)[/:][a-zA-Z0-9\-]{1,63})[/:]?(?P<key>.*)$"
)
match = _S3_ACCESSPOINT_TO_BUCKET_KEY_REGEX.match(s3_path)
if match:
return match.group("bucket"), match.group("key")
match = _S3_OUTPOST_TO_BUCKET_KEY_REGEX.match(s3_path)
if match:
return match.group("bucket"), match.group("key")
bucket_format_list = [
re.compile(
r"^(?P<bucket>arn:(aws).*:s3:[a-z\-0-9]*:[0-9]{12}:accesspoint[:/][^/]+)/?"
r"(?P<key>.*)$"
),
re.compile(
r"^(?P<bucket>arn:(aws).*:s3-outposts:[a-z\-0-9]+:[0-9]{12}:outpost[/:]"
r"[a-zA-Z0-9\-]{1,63}[/:](bucket|accesspoint)[/:][a-zA-Z0-9\-]{1,63})[/:]?(?P<key>.*)$"
),
re.compile(
r"^(?P<bucket>arn:(aws).*:s3-outposts:[a-z\-0-9]+:[0-9]{12}:outpost[/:]"
r"[a-zA-Z0-9\-]{1,63}[/:]bucket[/:]"
r"[a-zA-Z0-9\-]{1,63})[/:]?(?P<key>.*)$"
),
re.compile(
r"^(?P<bucket>arn:(aws).*:s3-object-lambda:[a-z\-0-9]+:[0-9]{12}:"
r"accesspoint[/:][a-zA-Z0-9\-]{1,63})[/:]?(?P<key>.*)$"
),
]
for bucket_format in bucket_format_list:
match = bucket_format.match(s3_path)
if match:
return match.group("bucket"), match.group("key")
s3_components = s3_path.split("/", 1)
bucket = s3_components[0]
s3_key = ""
Expand Down Expand Up @@ -1544,7 +1553,9 @@ async def _chmod(self, path, acl, recursive=False, **kwargs):
bucket, key, version_id = self.split_path(path)
if recursive:
allfiles = await self._find(path, withdirs=False)
await asyncio.gather(*[self._chmod(p, acl, recursive=False) for p in allfiles])
await asyncio.gather(
*[self._chmod(p, acl, recursive=False) for p in allfiles]
)
elif key:
if acl not in key_acls:
raise ValueError("ACL not in %s", key_acls)
Expand Down
1 change: 1 addition & 0 deletions s3fs/tests/test_s3fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2433,6 +2433,7 @@ def test_split_path(s3):
"arn:aws:s3:region:123456789012:accesspoint/my-access-point-name",
"arn:aws:s3-outposts:region:123456789012:outpost/outpost-id/bucket/my-test-bucket",
"arn:aws:s3-outposts:region:123456789012:outpost/outpost-id/accesspoint/my-accesspoint-name",
"arn:aws:s3-object-lambda:region:123456789012:accesspoint/my-lambda-object-name",
]
test_key = "my/test/path"
for test_bucket in buckets:
Expand Down

0 comments on commit 11c4ff5

Please sign in to comment.