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

Added proxy for S3BotoStorage #41

Merged
merged 2 commits into from Apr 7, 2015
Merged
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
20 changes: 12 additions & 8 deletions storages/backends/s3boto.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ def close(self):
self._multipart.cancel_upload()
self.key.close()


@deconstructible
class S3BotoStorage(Storage):
"""
Expand Down Expand Up @@ -240,6 +241,8 @@ class S3BotoStorage(Storage):
host = setting('AWS_S3_HOST', S3Connection.DefaultHost)
use_ssl = setting('AWS_S3_USE_SSL', True)
port = setting('AWS_S3_PORT', None)
proxy = setting('AWS_S3_PROXY_HOST', None)
proxy_port = setting('AWS_S3_PROXY_PORT', None)

# The max amount of memory a returned file can take up before being
# rolled over into a temporary file on disk. Default is 0: Do not roll over.
Expand Down Expand Up @@ -282,6 +285,8 @@ def connection(self):
calling_format=self.calling_format,
host=self.host,
port=self.port,
proxy=self.proxy,
proxy_port=self.proxy_port
)
return self._connection

Expand All @@ -302,7 +307,7 @@ def entries(self):
"""
if self.preload_metadata and not self._entries:
self._entries = dict((self._decode_name(entry.key), entry)
for entry in self.bucket.list(prefix=self.location))
for entry in self.bucket.list(prefix=self.location))
return self._entries

def _get_access_keys(self):
Expand All @@ -325,8 +330,7 @@ def _get_or_create_bucket(self, name):
Retrieves a bucket if it exists, otherwise creates it.
"""
try:
return self.connection.get_bucket(name,
validate=self.auto_create_bucket)
return self.connection.get_bucket(name, validate=self.auto_create_bucket)
except self.connection_response_error:
if self.auto_create_bucket:
bucket = self.connection.create_bucket(name)
Expand Down Expand Up @@ -395,7 +399,7 @@ def _save(self, name, content):
name = self._normalize_name(cleaned_name)
headers = self.headers.copy()
content_type = getattr(content, 'content_type',
mimetypes.guess_type(name)[0] or self.key_class.DefaultContentType)
mimetypes.guess_type(name)[0] or self.key_class.DefaultContentType)

# setting the content_type in the key object is not enough.
headers.update({'Content-Type': content_type})
Expand Down Expand Up @@ -486,10 +490,10 @@ def url(self, name, headers=None, response_headers=None):
return "%s//%s/%s" % (self.url_protocol,
self.custom_domain, filepath_to_uri(name))
return self.connection.generate_url(self.querystring_expire,
method='GET', bucket=self.bucket.name, key=self._encode_name(name),
headers=headers,
query_auth=self.querystring_auth, force_http=not self.secure_urls,
response_headers=response_headers)
method='GET', bucket=self.bucket.name, key=self._encode_name(name),
headers=headers,
query_auth=self.querystring_auth, force_http=not self.secure_urls,
response_headers=response_headers)

def get_available_name(self, name):
""" Overwrite existing file with the same name. """
Expand Down