add prefix/bucket_region params to get_all_buckets() method#71
add prefix/bucket_region params to get_all_buckets() method#71mozawa wants to merge 1 commit intoall_cloudian_fixesfrom
Conversation
hysh
left a comment
There was a problem hiding this comment.
PR Review: Add prefix/bucket_region params to get_all_buckets()
Summary
This PR adds support for prefix and bucket-region parameters to the get_all_buckets() method and refactors the query string construction to be more maintainable.
✅ Positives
-
Cleaner Code: The refactoring from repetitive if-else blocks to a dictionary-based approach with list comprehension is much more readable and maintainable.
-
Feature Addition: Properly adds the two new S3 ListBuckets API parameters (
prefixandbucket-region) as referenced in the Jira tickets. -
Backward Compatible: The changes maintain backward compatibility - all existing parameters remain optional with default
Nonevalues. -
Consistent Handling: The
sharedparameter special case (flag without value) is handled correctly by inserting it at the beginning of the query list.
⚠️ Potential Issues
-
URL Encoding Not Applied: The PR doesn't URL-encode parameter values. While this is consistent with the existing code for
max-bucketsandcontinuation-token, theprefixparameter could potentially contain special characters (spaces, slashes, etc.) that should be encoded.Looking at line 229 in
boto/s3/bucket.py, there's precedent for usingurllib.parse.quote()for user-provided values:query_args_l.append('%s=%s' % (rk, urllib.parse.quote(rv)))
Recommendation: Consider encoding at least the
prefixparameter:params = { 'max-buckets': max_buckets, 'continuation-token': continuation_token, 'prefix': urllib.parse.quote(prefix) if prefix else None, 'bucket-region': bucket_region, }
-
No Input Validation: There's no validation on the new parameters (e.g., checking if
bucket_regionis a valid region). However, this is consistent with the existing code style in this file, which appears to rely on the server to validate inputs.
📝 Minor Notes
- The f-string usage (
f"{k}={v}") is fine and more modern than%formatting - The logic correctly filters out
Nonevalues with theif v is not Nonecheck - The
&joining logic is correct
Verdict
The PR is good to merge with the caveat that URL encoding should be considered as a follow-up enhancement for the prefix parameter if users encounter issues with special characters. The refactoring improves code quality significantly.
Suggested priority: Add URL encoding for prefix parameter before merging to prevent potential issues with bucket names containing special characters.
I'm ok to add URL encoding for |
add prefix/bucket_region params to get_all_buckets() method