-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Raise ValueError exception if bucket name is invalid. #3160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Raise ValueError exception if bucket name is invalid. #3160
Conversation
|
@daspecster I am 👎 on this change, not really sure what the right approach is but adding this check in the constructor makes EVERY constructed bucket pay the price |
|
|
||
| def __init__(self, name=None): | ||
| self.name = name | ||
| if name is None or (re.match(r'\w', name[0]) and |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
@dhermes you mean every existing bucket? I don't believe there could be any existing buckets that violate this rule? I think the API would have complained. |
|
@daspecster No I mean the local |
|
Quoting my follow up to #2956:
|
|
@lukesneeringer @tseaver any alternative ideas? ISTM that object creation would be the place to check this? Maybe there's a more efficient way to do it though? |
|
I think we can "fix" by just more clearly documenting the acceptable values. |
|
@dhermes If the API allows embedding |
|
@tseaver a user might be confused when then see their bucket names listed from some other library that may/maynot handle the urlencoding/urldecoding right? @dhermes sure, but the error that is returned is a 404 which doesn't explain what the allowed values are. |
|
@tseaver, you are making an orthogonal point; in actuality, slashes are not permissible at the start or end of a bucket name (by the API), but the client library allows them to pass through. |
|
@lukesneeringer the OP in #2956 reported having created a bucket with a trailing slash. |
|
@tseaver Yes, in our library, and then the API dropped the slash for the bucket name. |
That seems fine to me. It is not terribly expensive. |
lukesneeringer
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved, pending @dhermes explaining his problem with it and resolving that.
|
My issue is just that RegEx is expensive. In terms of this specific approach, we don't even need a regex: name[0].isalnum()
name[-1].isalnum()Though this is a little strange with >>> u'\xff'.isalnum()
True |
|
Sold. Change to that, and add EDIT: We should also add That is good enough. The API can complain about the remaining errors (e.g. "not containing |
|
@daspecster Suggestion: class _PropertyMixin(object):
def __init__(self, name=None):
if name:
self._validate_name(name)
[...]
def _validate_name(self, name):
# Names must start and end with a letter or number.
if not name[0].isalnum() or not name[-1].isalnum():
raise ValueError('Bucket names must start and end with an alphanumeric character.')
# Names must be between 3 and 222 total characters in length.
if len(name) < 3:
raise ValueError('Bucket names must be at least 3 characters.')
if len(name) > 222:
raise ValueError('Bucket names can not exceed 222 characters.')
# Each bucket name component can not exceed 63 characters.
if any([len(i) > 63 for i in name.split('.')]):
raise ValueError('Each dot-separated component in a bucket name '
'can not exceed 63 characters.') |
lukesneeringer
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated based on previous discussion.
|
@lukesneeringer where are you seeing the 63 char limit in the docs? |
|
|
@lukesneeringer found the link. Thanks! |
|
There is just so much complexity here. Why can't we just punt to the server validation and document the rules in our docstring? |
|
To echo @dhermes, there are more requirements for the names as well and I assume they're subject to change(with or without bumping the API version). |
|
I guess what I was thinking was, "catch the easy ones, let the API fail on the rest". I could go either way on the rest. |
99ce2e0 to
79f107d
Compare
|
@lukesneeringer did you have anything else for this? |
Fixes #2956.