Skip to content

Commit

Permalink
Allow SFTPStorage to be configured via class variables
Browse files Browse the repository at this point in the history
  • Loading branch information
DoctorJohn committed Mar 7, 2020
1 parent d0f027c commit c3c9060
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ By order of apparition, thanks:
* Shaung Cheng (S3 docs)
* Andrew Perry (Bug fixes in SFTPStorage)
* Manuel Kaufmann (humitos)
* Jonathan Ehwald (Small tweak in SFTPStorage)


Extra thanks to Marty for adding this in Django,
Expand Down
39 changes: 20 additions & 19 deletions storages/backends/sftpstorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,30 @@

@deconstructible
class SFTPStorage(Storage):
host = setting('SFTP_STORAGE_HOST')
params = setting('SFTP_STORAGE_PARAMS', {})
interactive = setting('SFTP_STORAGE_INTERACTIVE', False)
file_mode = setting('SFTP_STORAGE_FILE_MODE')
dir_mode = setting('SFTP_STORAGE_DIR_MODE')
uid = setting('SFTP_STORAGE_UID')
gid = setting('SFTP_STORAGE_GID')
known_host_file = setting('SFTP_KNOWN_HOST_FILE')
root_path = setting('SFTP_STORAGE_ROOT', '')
base_url = setting('MEDIA_URL')

def __init__(self, host=None, params=None, interactive=None, file_mode=None,
dir_mode=None, uid=None, gid=None, known_host_file=None,
root_path=None, base_url=None):
self._host = host or setting('SFTP_STORAGE_HOST')

self._params = params or setting('SFTP_STORAGE_PARAMS', {})
self._interactive = setting('SFTP_STORAGE_INTERACTIVE', False) \
if interactive is None else interactive
self._file_mode = setting('SFTP_STORAGE_FILE_MODE') \
if file_mode is None else file_mode
self._dir_mode = setting('SFTP_STORAGE_DIR_MODE') if \
dir_mode is None else dir_mode

self._uid = setting('SFTP_STORAGE_UID') if uid is None else uid
self._gid = setting('SFTP_STORAGE_GID') if gid is None else gid
self._known_host_file = setting('SFTP_KNOWN_HOST_FILE') \
if known_host_file is None else known_host_file

self._root_path = setting('SFTP_STORAGE_ROOT', '') \
if root_path is None else root_path
self._base_url = setting('MEDIA_URL') if base_url is None else base_url

self._host = host or self.host
self._params = params or self.params
self._interactive = interactive or self.interactive
self._file_mode = file_mode or self.file_mode
self._dir_mode = dir_mode or self.dir_mode
self._uid = uid or self.uid
self._gid = gid or self.gid
self._known_host_file = known_host_file or self.known_host_file
self._root_path = root_path or self.root_path
self._base_url = base_url or self.base_url
self._sftp = None

def _connect(self):
Expand Down

0 comments on commit c3c9060

Please sign in to comment.