diff --git a/django_webdav_storage/storage.py b/django_webdav_storage/storage.py index c437388..0318dc5 100644 --- a/django_webdav_storage/storage.py +++ b/django_webdav_storage/storage.py @@ -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') @@ -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() diff --git a/docs/source/configuration.rst b/docs/source/configuration.rst index 0de6e07..9b5e142 100644 --- a/docs/source/configuration.rst +++ b/docs/source/configuration.rst @@ -21,6 +21,16 @@ If you want use HTTP Basic authorization to WebDAV access, you can specify your WEBDAV_URL = 'http://johndoe:secret@my-internal-webdav-server.example.com' +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