S3 Ignore Subdomain for Bucketname Flag (#1419)
* Some circumstances need subdomains to be ignored rather that interpreted as bucketname, this patch allows such behaviour to be configured * Adding helper case whereby localstack features as path based exception * Remove whitespace :(
This commit is contained in:
parent
c13f77173f
commit
1a8a4a084d
@ -57,10 +57,11 @@ class ResponseObject(_TemplateEnvironmentMixin):
|
|||||||
if not host:
|
if not host:
|
||||||
host = urlparse(request.url).netloc
|
host = urlparse(request.url).netloc
|
||||||
|
|
||||||
if (not host or host.startswith('localhost') or
|
if (not host or host.startswith('localhost') or host.startswith('localstack') or
|
||||||
re.match(r'^[^.]+$', host) or re.match(r'^.*\.svc\.cluster\.local$', host)):
|
re.match(r'^[^.]+$', host) or re.match(r'^.*\.svc\.cluster\.local$', host)):
|
||||||
# Default to path-based buckets for (1) localhost, (2) local host names that do not
|
# Default to path-based buckets for (1) localhost, (2) localstack hosts (e.g. localstack.dev),
|
||||||
# contain a "." (e.g., Docker container host names), or (3) kubernetes host names
|
# (3) local host names that do not contain a "." (e.g., Docker container host names), or
|
||||||
|
# (4) kubernetes host names
|
||||||
return False
|
return False
|
||||||
|
|
||||||
match = re.match(r'^([^\[\]:]+)(:\d+)?$', host)
|
match = re.match(r'^([^\[\]:]+)(:\d+)?$', host)
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
|
|
||||||
from boto.s3.key import Key
|
from boto.s3.key import Key
|
||||||
import re
|
import re
|
||||||
@ -15,6 +16,8 @@ bucket_name_regex = re.compile("(.+).s3(.*).amazonaws.com")
|
|||||||
|
|
||||||
|
|
||||||
def bucket_name_from_url(url):
|
def bucket_name_from_url(url):
|
||||||
|
if os.environ.get('S3_IGNORE_SUBDOMAIN_BUCKETNAME', '') in ['1', 'true']:
|
||||||
|
return None
|
||||||
domain = urlparse(url).netloc
|
domain = urlparse(url).netloc
|
||||||
|
|
||||||
if domain.startswith('www.'):
|
if domain.startswith('www.'):
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
import os
|
||||||
from sure import expect
|
from sure import expect
|
||||||
from moto.s3.utils import bucket_name_from_url, _VersionedKeyStore, parse_region_from_url
|
from moto.s3.utils import bucket_name_from_url, _VersionedKeyStore, parse_region_from_url
|
||||||
|
|
||||||
@ -16,6 +17,12 @@ def test_localhost_without_bucket():
|
|||||||
expect(bucket_name_from_url(
|
expect(bucket_name_from_url(
|
||||||
'https://www.localhost:5000/def')).should.equal(None)
|
'https://www.localhost:5000/def')).should.equal(None)
|
||||||
|
|
||||||
|
def test_force_ignore_subdomain_for_bucketnames():
|
||||||
|
os.environ['S3_IGNORE_SUBDOMAIN_BUCKETNAME'] = '1'
|
||||||
|
expect(bucket_name_from_url('https://subdomain.localhost:5000/abc/resource')).should.equal(None)
|
||||||
|
del(os.environ['S3_IGNORE_SUBDOMAIN_BUCKETNAME'])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def test_versioned_key_store():
|
def test_versioned_key_store():
|
||||||
d = _VersionedKeyStore()
|
d = _VersionedKeyStore()
|
||||||
|
Loading…
Reference in New Issue
Block a user