Skip to content

Commit

Permalink
Boto3: Add AWS_S3_PROXIES setting
Browse files Browse the repository at this point in the history
  • Loading branch information
jschneier committed Sep 3, 2018
1 parent 28ecb5d commit 5909b0c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
8 changes: 8 additions & 0 deletions docs/backends/amazon-S3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@ Available are numerous settings. It should be especially noted the following:
``AWS_S3_ADDRESSING_STYLE`` (default is ``None``, boto3 only)
Possible values ``virtual`` and ``path``.

``AWS_S3_PROXIES`` (boto3 only, default ``None``)
A dictionary of proxy servers to use by protocol or endpoint, e.g.:
{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}.

.. note::

The minimum required version of ``boto3`` to use this feature is 1.4.4

``AWS_S3_CALLING_FORMAT`` (optional: default is ``SubdomainCallingFormat()``)
Defines the S3 calling format to use to connect to the static bucket.

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def read(filename):
extras_require={
'azure': ['azure>=3.0.0', 'azure-storage-blob>=1.3.1'],
'boto': ['boto>=2.32.0'],
'boto3': ['boto3>=1.2.3'],
'boto3': ['boto3>=1.4.4'],
'dropbox': ['dropbox>=7.2.1'],
'google': ['google-cloud-storage>=0.22.0'],
'libcloud': ['apache-libcloud'],
Expand Down
24 changes: 14 additions & 10 deletions storages/backends/s3boto3.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@

boto3_version_info = tuple([int(i) for i in boto3_version.split('.')])

if boto3_version_info[:2] < (1, 2):
raise ImproperlyConfigured("The installed Boto3 library must be 1.2.0 or "
"higher.\nSee https://github.com/boto/boto3")


@deconstructible
class S3Boto3StorageFile(File):
Expand Down Expand Up @@ -219,6 +215,7 @@ class S3Boto3Storage(Storage):
))
url_protocol = setting('AWS_S3_URL_PROTOCOL', 'http:')
endpoint_url = setting('AWS_S3_ENDPOINT_URL')
proxies = setting('AWS_S3_PROXIES')
region_name = setting('AWS_S3_REGION_NAME')
use_ssl = setting('AWS_S3_USE_SSL', True)
verify = setting('AWS_S3_VERIFY', None)
Expand Down Expand Up @@ -265,8 +262,19 @@ def __init__(self, acl=None, bucket=None, **settings):
self.security_token = self._get_security_token()

if not self.config:
self.config = Config(s3={'addressing_style': self.addressing_style},
signature_version=self.signature_version)
kwargs = dict(
s3={'addressing_style': self.addressing_style},
signature_version=self.signature_version,
)

if boto3_version_info >= (1, 4, 4):
kwargs['proxies'] = self.proxies
else:
warnings.warn(
"In version 2.0 of django-storages the minimum required version of "
"boto3 will be 1.4.4. You have %s " % boto3_version_info
)
self.config = Config(**kwargs)

# warn about upcoming change in default AWS_DEFAULT_ACL setting
if not hasattr(django_settings, 'AWS_DEFAULT_ACL'):
Expand All @@ -292,10 +300,6 @@ def __setstate__(self, state):

@property
def connection(self):
# TODO: Support host, port like in s3boto
# Note that proxies are handled by environment variables that the underlying
# urllib/requests libraries read. See https://github.com/boto/boto3/issues/338
# and http://docs.python-requests.org/en/latest/user/advanced/#proxies
connection = getattr(self._connections, 'connection', None)
if connection is None:
session = boto3.session.Session()
Expand Down

0 comments on commit 5909b0c

Please sign in to comment.