diff options
author | Corry Haines | 2022-11-28 09:22:39 -0800 |
---|---|---|
committer | GitHub | 2022-11-28 10:22:39 -0700 |
commit | ab1247fd2d1de5265f4bb956dafdbe06cea6efa2 (patch) | |
tree | e162dbfe72dab23e53c8b1618cf2603301b0b609 /takahe | |
parent | 9e99a6bba16f0378247c0fd93ea58457787d9e14 (diff) | |
download | takahe-ab1247fd2d1de5265f4bb956dafdbe06cea6efa2.tar.gz takahe-ab1247fd2d1de5265f4bb956dafdbe06cea6efa2.tar.bz2 takahe-ab1247fd2d1de5265f4bb956dafdbe06cea6efa2.zip |
Relax S3 URI parsing
Diffstat (limited to 'takahe')
-rw-r--r-- | takahe/settings.py | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/takahe/settings.py b/takahe/settings.py index cf74122..3e2ffcd 100644 --- a/takahe/settings.py +++ b/takahe/settings.py @@ -13,6 +13,11 @@ from sentry_sdk.integrations.django import DjangoIntegration BASE_DIR = Path(__file__).resolve().parent.parent +class MediaBackendUrl(AnyUrl): + host_required = False + allowed_schemes = {"s3", "gcs", "local"} + + def as_bool(v: Optional[Union[str, List[str]]]): if v is None: return False @@ -84,7 +89,7 @@ class Settings(BaseSettings): MEDIA_URL: str = "/media/" MEDIA_ROOT: str = str(BASE_DIR / "media") - MEDIA_BACKEND: Optional[AnyUrl] = None + MEDIA_BACKEND: Optional[MediaBackendUrl] = None PGHOST: Optional[str] = None PGPORT: Optional[int] = 5432 @@ -299,10 +304,12 @@ if SETUP.MEDIA_BACKEND: elif parsed.scheme == "s3": DEFAULT_FILE_STORAGE = "storages.backends.s3boto3.S3Boto3Storage" AWS_STORAGE_BUCKET_NAME = parsed.path.lstrip("/") - AWS_ACCESS_KEY_ID = parsed.username - AWS_SECRET_ACCESS_KEY = parsed.password - port = parsed.port or 443 - AWS_S3_ENDPOINT_URL = f"https://{parsed.hostname}:{port}" + if parsed.username is not None: + AWS_ACCESS_KEY_ID = parsed.username + AWS_SECRET_ACCESS_KEY = parsed.password + if parsed.hostname is not None: + port = parsed.port or 443 + AWS_S3_ENDPOINT_URL = f"https://{parsed.hostname}:{port}" else: raise ValueError(f"Unsupported media backend {parsed.scheme}") |