Skip to content
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

Disable dns support for buckets when "host_bucket" hostname doesn't have a %(bucket)s item in it. #416

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions S3/S3.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def __init__(self, config):
self.config = config

def get_hostname(self, bucket):
if bucket and check_bucket_name_dns_conformity(bucket):
if bucket and check_bucket_name_dns_support(self.config.host_bucket, bucket):
if self.redir_map.has_key(bucket):
host = self.redir_map[bucket]
else:
Expand All @@ -222,7 +222,7 @@ def set_hostname(self, bucket, redir_hostname):
self.redir_map[bucket] = redir_hostname

def format_uri(self, resource):
if resource['bucket'] and not check_bucket_name_dns_conformity(resource['bucket']):
if resource['bucket'] and not check_bucket_name_dns_support(self.config.host_bucket, resource['bucket']):
uri = "/%s%s" % (resource['bucket'], resource['uri'])
else:
uri = resource['uri']
Expand Down
2 changes: 1 addition & 1 deletion S3/S3Uri.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def uri(self):
return u"/".join([u"s3:/", self._bucket, self._object])

def is_dns_compatible(self):
return check_bucket_name_dns_conformity(self._bucket)
return check_bucket_name_dns_support(Config.Config().host_bucket, self._bucket)

def public_url(self):
if self.is_dns_compatible():
Expand Down
14 changes: 14 additions & 0 deletions S3/Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,20 @@ def check_bucket_name_dns_conformity(bucket):
return False
__all__.append("check_bucket_name_dns_conformity")

def check_bucket_name_dns_support(bucket_host, bucket_name):
"""
Check whether either the host_bucket support buckets and
either bucket name is dns compatible
"""
if "%(bucket)s" not in bucket_host:
return False

try:
return check_bucket_name(bucket_name, dns_strict = True)
except Exceptions.ParameterError:
return False
__all__.append("check_bucket_name_dns_support")

def getBucketFromHostname(hostname):
"""
bucket, success = getBucketFromHostname(hostname)
Expand Down