Skip to content
Open
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions django_webdav_storage/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def __init__(self, **kwargs):
self.public_url = self.set_public_url(**kwargs)
self.listing_backend = kwargs.get('listinb_backend') or \
setting('WEBDAV_LISTING_BACKEND')
self.basic_auth = setting('WEBDAV_BASIC_AUTH')

if not self.webdav_url:
raise NotImplementedError('Please define webdav url')
Expand Down Expand Up @@ -58,6 +59,10 @@ def get_requests_instance(self, **kwargs):
def webdav(self, method, name, *args, **kwargs):
url = self.get_webdav_url(name)
method = method.lower()
if self.basic_auth:
if not kwargs:
kwargs = {}
kwargs["auth"] = (self.basic_auth["user"], self.basic_auth["password"])
response = getattr(self.requests, method)(url, *args, **kwargs)
response.raise_for_status()

Expand Down
10 changes: 10 additions & 0 deletions docs/source/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ If you want use HTTP Basic authorization to WebDAV access, you can specify your
WEBDAV_URL = 'http://johndoe:[email protected]'


Alternatively, if you want to avoid having the password written to log files in case of errors, you can specify authentication settings like this:

.. code:: python

WEBDAV_BASIC_AUTH = {
"user": "dav_user",
"password": "secret123456",
}


Second, set the ``django_webdav_storage.storage.WebDavStorage`` storage class as default storage class:

.. code:: python
Expand Down