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

Use Django's system check instead of a log warning #156

Closed
wants to merge 1 commit into from
Closed
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
26 changes: 18 additions & 8 deletions django_s3_storage/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from botocore.exceptions import ClientError
from django.conf import settings
from django.contrib.staticfiles.storage import ManifestFilesMixin
from django.core.checks import Tags, Warning, register
from django.core.exceptions import ImproperlyConfigured
from django.core.files.base import File
from django.core.files.storage import Storage
Expand Down Expand Up @@ -75,6 +76,23 @@ def unpickle_helper(cls, kwargs):
_UNCOMPRESSED_SIZE_META_KEY = "uncompressed_size"


@register(Tags.security)
def system_checks(app_configs, **kwargs):
errors = []
storage = S3Storage()
if storage.settings.AWS_S3_PUBLIC_URL and storage.settings.AWS_S3_BUCKET_AUTH:
errors.append(
Warning(
f"Using AWS_S3_BUCKET_AUTH{storage.s3_settings_suffix} "
f"with AWS_S3_PUBLIC_URL{storage.s3_settings_suffix}. "
"Private files on S3 may be inaccessible via the public URL. "
"See https://github.com/etianen/django-s3-storage/issues/114 ",
id="django_s3_storage.W001",
)
)
return errors


class S3File(File):

"""
Expand Down Expand Up @@ -183,14 +201,6 @@ def _setup(self):
# Validate settings.
if not self.settings.AWS_S3_BUCKET_NAME:
raise ImproperlyConfigured(f"Setting AWS_S3_BUCKET_NAME{self.s3_settings_suffix} is required.")
if self.settings.AWS_S3_PUBLIC_URL and self.settings.AWS_S3_BUCKET_AUTH:
log.warning(
"Using AWS_S3_BUCKET_AUTH%s with AWS_S3_PUBLIC_URL%s. "
"Private files on S3 may be inaccessible via the public URL. "
"See https://github.com/etianen/django-s3-storage/issues/114 ",
self.s3_settings_suffix,
self.s3_settings_suffix,
)
# Create a thread-local connection manager.
self._connections = _Local(self)
# Set transfer config for S3 operations
Expand Down