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

feat: add django storages and settings for s3 storage #617

Merged
merged 1 commit into from
Jul 11, 2023
Merged
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
23 changes: 22 additions & 1 deletion CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,28 @@ If either `EMAIL_HOST_USER` or `EMAIL_HOST_PASSWORD` is empty, Django won't atte
* `ADMINS`: list of people who will get code error notifications. Items in the list should follow this example: `Test Example <[email protected]>,Test2 <[email protected]>`

## Sentry
* `SENTRY_DSN`: identifier (data source name) for where to send events to. If no value is provided, sentry won't be activated (default: ")
* `SENTRY_DSN`: identifier (data source name) for where to send events to. If no value is provided, sentry won't be activated (default: "")
* `SENTRY_ENVIRONMENT`: which app environment sent an event to sentry (default: `development`)
* `SENTRY_TRACES_SAMPLE_RATE`: percentage chance a given transaction will be sent to Sentry (default: `1.0`)
* `SENTRY_SEND_DEFAULT_PII`: enable send PII data that associates users to errors (default: `True`)

## Template storage
* `FILE_STORAGE`: Django file storage backend (default: `django.core.files.storage.FileSystemStorage`)
* `MEDIA_ROOT`: Absolute filesystem path to the directory that will hold user-uploaded files. (default: "")
* `MEDIA_URL`: URL that handles the media served from MEDIA_ROOT, used for managing stored files. When using buckets this needs to be changed. (default: `api/v1/template/`)


### [django-storages](https://django-storages.readthedocs.io/en/1.13.2/backends/amazon-S3.html) S3 settings
Refer to for example [Digital Ocean](https://django-storages.readthedocs.io/en/1.13.2/backends/digital-ocean-spaces.html) configuration if using a S3 compatible storage which isn't AWS.

Required to use S3 storage:
* `AWS_ACCESS_KEY_ID`: AWS access key id
* `AWS_S3_SECRET_ACCESS_KEY`: AWS secret access key
* `AWS_STORAGE_BUCKET_NAME`: Storage bucket name

Optional:
* `AWS_S3_ENDPOINT_URL`: Custom S3 URL to use when connecting to S3, including scheme. (default: "")
* `AWS_S3_REGION_NAME`: Region of the storage (default: "")
* `AWS_LOCATION`: A path prefix that will be prepended to all uploads (default: "")
* `AWS_S3_FILE_OVERWRITE`: If `True` Files with the same name will overwrite each other. Otherwise extra characters are appended. (default: `False`)
* `AWS_S3_SIGNATURE_VERSION`: S3 signature version to use (default: `s2`)
16 changes: 13 additions & 3 deletions document_merge_service/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,21 @@ def parse_admins(admins):
"FILE_STORAGE", default="django.core.files.storage.FileSystemStorage"
)
MEDIA_ROOT = env.str("MEDIA_ROOT", "")

# TODO: This should be removed in favor of storing the files in a bucket
# https://code.djangoproject.com/ticket/32991
MEDIA_URL = "api/v1/template/"

MEDIA_URL = env.str("MEDIA_URL", "api/v1/template/")

# django-storages S3 settings
AWS_S3_ACCESS_KEY_ID = env.str("AWS_S3_ACCESS_KEY_ID", "")
AWS_S3_SECRET_ACCESS_KEY = env.str("AWS_S3_SECRET_ACCESS_KEY", "")
AWS_STORAGE_BUCKET_NAME = env.str("AWS_STORAGE_BUCKET_NAME", "")
AWS_S3_ENDPOINT_URL = env.str("AWS_S3_ENDPOINT_URL", "")
AWS_S3_REGION_NAME = env.str("AWS_S3_REGION_NAME", "")
AWS_LOCATION = env.str("AWS_LOCATION", "")
AWS_S3_FILE_OVERWRITE = env.bool("AWS_S3_FILE_OVERWRITE", False)
AWS_S3_SIGNATURE_VERSION = env.str("AWS_S3_SIGNATURE_VERSION", "v2")

# unoconv
UNOCONV_ALLOWED_TYPES = env.list("UNOCOV_ALLOWED_TYPES", default=["pdf"])
UNOCONV_PYTHON = env.str("UNOCONV_PYTHON", default="/usr/bin/python3")
UNOCONV_PATH = env.str("UNOCONV_PATH", default="/usr/bin/unoconv")
Expand Down
29 changes: 26 additions & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ xltpl = "^0.16"
openpyxl = "^3.0.10"
django-generic-api-permissions = "^0.2.0"
sentry-sdk = "^1.12.1"
django-storages = "^1.13.2"

[tool.poetry.group.dev.dependencies]
black = "22.10.0"
Expand Down