Skip to content

Commit

Permalink
Fix custom domain for S3 URLs
Browse files Browse the repository at this point in the history
This commit restores the Django AWS_S3_CUSTOM_DOMAIN setting which was
incorrectly removed in commit 853c948.

Without this setting, S3 URLs are constructed like:

https://s3.amazonaws.com/files.consumerfinance.gov/something

where we want them to be instead constructed like:

https://files.consumerfinance.gov/something

This fix makes that happen.

To test this, you can run this command at the command line:

> S3_ENABLED=True AWS_STORAGE_BUCKET_NAME=files.consumerfinance.gov AWS_ACCESS_KEY_ID=x AWS_SECRET_ACCESS_KEY=x AWS_S3_CUSTOM_DOMAIN=files.consumerfinance.gov cfgov/manage.py shell -c "from wagtail.documents import get_document_model; Document = get_document_model(); print(Document.objects.last().file.url)"

This prints out the URL of the most recent Wagtail document; on the
main branch this will use the incorrect URL structure. With this commit
the URL will be https://files.cf.gov as desired.

Addresses internal D&CP#325.
  • Loading branch information
chosak committed Aug 31, 2023
1 parent 1a84328 commit e2b46e6
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions cfgov/cfgov/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@
AWS_ACCESS_KEY_ID = os.environ["AWS_ACCESS_KEY_ID"]
AWS_SECRET_ACCESS_KEY = os.environ["AWS_SECRET_ACCESS_KEY"]
DEFAULT_FILE_STORAGE = "storages.backends.s3boto3.S3Boto3Storage"
AWS_S3_CUSTOM_DOMAIN = os.environ.get("AWS_S3_CUSTOM_DOMAIN")
MEDIA_URL = os.path.join(
AWS_STORAGE_BUCKET_NAME + ".s3.amazonaws.com", AWS_LOCATION, ""
)
Expand Down

0 comments on commit e2b46e6

Please sign in to comment.