Uh oh!
There was an error while loading. Please reload this page.
Raise ValueError exception if bucket name is invalid. - #3160
Conversation
dhermes
commented
Mar 16, 2017
@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.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
daspecster
commented
Mar 16, 2017
@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. |
dhermes
commented
Mar 16, 2017
@daspecster No I mean the local |
tseaver
commented
Mar 16, 2017
Quoting my follow up to #2956:
|
daspecster
commented
Mar 16, 2017
@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? |
dhermes
commented
Mar 16, 2017
I think we can "fix" by just more clearly documenting the acceptable values. |
tseaver
commented
Mar 16, 2017
@dhermes If the API allows embedding |
daspecster
commented
Mar 16, 2017
@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. |
lukesneeringer
commented
Mar 16, 2017
@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. |
tseaver
commented
Mar 16, 2017
@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. |
lukesneeringer
commented
Mar 16, 2017
That seems fine to me. It is not terribly expensive. |
lukesneeringer
left a comment
There was a problem hiding this comment.
Approved, pending @dhermes explaining his problem with it and resolving that.
dhermes
commented
Mar 17, 2017
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):
ifname:
self._validate_name(name)
[...]
def_validate_name(self, name):
# Names must start and end with a letter or number.ifnotname[0].isalnum() ornotname[-1].isalnum():
raiseValueError('Bucket names must start and end with an alphanumeric character.')
# Names must be between 3 and 222 total characters in length.iflen(name) <3:
raiseValueError('Bucket names must be at least 3 characters.')
iflen(name) >222:
raiseValueError('Bucket names can not exceed 222 characters.')
# Each bucket name component can not exceed 63 characters.ifany([len(i) >63foriinname.split('.')]):
raiseValueError('Each dot-separated component in a bucket name ''can not exceed 63 characters.') |
lukesneeringer
left a comment
There was a problem hiding this comment.
Updated based on previous discussion.
daspecster
commented
Mar 17, 2017
@lukesneeringer where are you seeing the 63 char limit in the docs? |
lukesneeringer
commented
Mar 17, 2017
|
daspecster
commented
Mar 17, 2017
@lukesneeringer found the link. Thanks! |
dhermes
commented
Mar 17, 2017
There is just so much complexity here. Why can't we just punt to the server validation and document the rules in our docstring? |
daspecster
commented
Mar 17, 2017
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). |
lukesneeringer
commented
Mar 17, 2017
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
79f107dComparedaspecster
commented
Mar 20, 2017
@lukesneeringer did you have anything else for this? |
Fixes#2956.