added S3_CDN_DOMAIN support

This commit is contained in:
Erik Taubeneck
2013-06-12 11:28:03 -04:00
parent a7b815292a
commit a24098adc0
3 changed files with 12 additions and 1 deletions
+5
View File
@@ -177,6 +177,11 @@ uploading assets to S3.
`S3_BUCKET_DOMAIN` The domain part of the URI for your S3 bucket. You
probably won't need to change this.
**Default:** ``u's3.amazonaws.com'``
'S3_CDN_DOMAIN' AWS makes it easy to attach CloudFront to an S3
bucket. If you want to use this or another CDN,
set the base domain here. This is distinct from the
'S3_BUCKET_DOMAIN` since it will not include the
bucket name in the base url.
`S3_BUCKET_NAME` The desired name for your Amazon S3 bucket. Note:
the name will be visible in all your assets' URLs.
`S3_USE_HTTPS` Specifies whether or not to serve your assets
+4
View File
@@ -38,6 +38,8 @@ def url_for(endpoint, **values):
scheme = 'https'
bucket_path = '%s.%s' % (app.config['S3_BUCKET_NAME'],
app.config['S3_BUCKET_DOMAIN'])
if app.config['S3_CDN_DOMAIN']:
bucket_path = '%s' % app.config['S3_CDN_DOMAIN']
urls = app.url_map.bind(bucket_path, url_scheme=scheme)
return urls.build(endpoint, values=values, force_external=True)
return flask_url_for(endpoint, **values)
@@ -219,8 +221,10 @@ class FlaskS3(object):
('USE_S3', True),
('USE_S3_DEBUG', False),
('S3_BUCKET_DOMAIN', 's3.amazonaws.com'),
('S3_CDN_DOMAIN', ''),
('S3_USE_CACHE_CONTROL', False),
('S3_HEADERS', {})]
for k, v in defaults:
app.config.setdefault(k, v)
+3 -1
View File
@@ -29,7 +29,8 @@ class FlaskStaticTest(unittest.TestCase):
""" Tests configuration vars exist. """
FlaskS3(self.app)
defaults = ('S3_USE_HTTPS', 'USE_S3', 'USE_S3_DEBUG',
'S3_BUCKET_DOMAIN', 'S3_USE_CACHE_CONTROL', 'S3_HEADERS')
'S3_BUCKET_DOMAIN', 'S3_CDN_DOMAIN',
'S3_USE_CACHE_CONTROL', 'S3_HEADERS')
for default in defaults:
self.assertIn(default, self.app.config)
@@ -41,6 +42,7 @@ class UrlTests(unittest.TestCase):
self.app.config['S3_BUCKET_NAME'] = 'foo'
self.app.config['S3_USE_HTTPS'] = True
self.app.config['S3_BUCKET_DOMAIN'] = 's3.amazonaws.com'
self.app.config['S3_CDN_DOMAIN'] = ''
@self.app.route('/<url_for_string>')
def a(url_for_string):