From c6f3fec302653d3cf383a3d913a95f971e032a42 Mon Sep 17 00:00:00 2001 From: nocturnalastro Date: Sat, 19 Aug 2023 17:01:19 +0100 Subject: [PATCH] Add configurations to allow boto to connect to minio --- NearBeach/views/document_views.py | 14 ++++++++++++++ local/settings.py | 8 ++++++++ 2 files changed, 22 insertions(+) diff --git a/NearBeach/views/document_views.py b/NearBeach/views/document_views.py index fab9a69a2..d0cfc2687 100644 --- a/NearBeach/views/document_views.py +++ b/NearBeach/views/document_views.py @@ -489,6 +489,20 @@ def __init__(self, settings): "aws_access_key_id": settings.AWS_ACCESS_KEY_ID, "aws_secret_access_key": settings.AWS_SECRET_ACCESS_KEY, } + if getattr(settings, "AWS_S3_ENDPOINT_URL", None): + # Assume the person is using minio so defualts are the values + # which will allow for connection to minio + botoInitValues.update( + aws_endpoint_url=settings.AWS_S3_ENDPOINT_URL, + aws_session_token=getattr(settings, "AWS_S3_SESSION_TOKEN", None), + config=getattr( + settings, + "AWS_CONFIG", + boto3.session.Config(signature_version='s3v4'), + ), + verify=getattr(settings, "AWS_VERIFY_TLS", True), + **getattr(settings, "AWS_INIT_VALUES", {}) + ) self._s3 = boto3.client("s3", **botoInitValues) self._bucket = settings.AWS_STORAGE_BUCKET_NAME diff --git a/local/settings.py b/local/settings.py index 5ebd4fb07..7d680a8f2 100644 --- a/local/settings.py +++ b/local/settings.py @@ -139,6 +139,14 @@ AWS_LOCATION = F"{VERSION}" AWS_S3_ENDPOINT_URL = F"https://{CLOUDFLARE_ACCOUNT_ID}.r2.cloudflarestorage.com" + # To use a selfsigned cert you can put the path to the cert bundle + # here e.g. AWS_VERIFY_TLS = path/to/cert/bundle.pem + # AWS_VERIFY_TLS = False + + # AWS_CONFIG can be used to set configure the botocore config + # see https://botocore.amazonaws.com/v1/documentation/api/latest/reference/config.html + + # Defining STORAGES STORAGES = {"staticfiles": {"BACKEND": "storages.backends.s3boto3.S3StaticStorage"}}