From 260063152821a73dc770db85f9fff23c51a65a18 Mon Sep 17 00:00:00 2001
From: Ciaran Ainsworth <ciaran.ainsworth@oneserve.co.uk>
Date: Fri, 10 May 2019 13:33:03 +0100
Subject: [PATCH] Added variables to connect to Amazon S3 directly

---
 api/config/settings/common.py    | 3 ++-
 changes/changelog.d/826.bugfix   | 1 +
 deploy/env.prod.sample           | 9 +++++++++
 docs/admin/external-storages.rst | 5 +++++
 4 files changed, 17 insertions(+), 1 deletion(-)
 create mode 100644 changes/changelog.d/826.bugfix

diff --git a/api/config/settings/common.py b/api/config/settings/common.py
index 800f7bf234..5d65366864 100644
--- a/api/config/settings/common.py
+++ b/api/config/settings/common.py
@@ -320,10 +320,11 @@ if AWS_ACCESS_KEY_ID:
     AWS_SECRET_ACCESS_KEY = env("AWS_SECRET_ACCESS_KEY")
     AWS_STORAGE_BUCKET_NAME = env("AWS_STORAGE_BUCKET_NAME")
     AWS_S3_ENDPOINT_URL = env("AWS_S3_ENDPOINT_URL", default=None)
+    AWS_S3_REGION_NAME = env("AWS_S3_REGION_NAME", default=None)
+    AWS_S3_SIGNATURE_VERSION = "s3v4"
     AWS_LOCATION = env("AWS_LOCATION", default="")
     DEFAULT_FILE_STORAGE = "storages.backends.s3boto3.S3Boto3Storage"
 
-
 # See: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#std:setting-STATICFILES_DIRS
 STATICFILES_DIRS = (str(APPS_DIR.path("static")),)
 
diff --git a/changes/changelog.d/826.bugfix b/changes/changelog.d/826.bugfix
new file mode 100644
index 0000000000..6cf7c25cb9
--- /dev/null
+++ b/changes/changelog.d/826.bugfix
@@ -0,0 +1 @@
+Added env variable to set AWS region and signature version to serve media without proxy (#826)
diff --git a/deploy/env.prod.sample b/deploy/env.prod.sample
index 9fd1720494..b7b0301dad 100644
--- a/deploy/env.prod.sample
+++ b/deploy/env.prod.sample
@@ -160,3 +160,12 @@ AWS_STORAGE_BUCKET_NAME=
 # the full URL to the storage server. Example:
 #   AWS_S3_ENDPOINT_URL=https://minio.mydomain.com
 # AWS_S3_ENDPOINT_URL=
+
+# If you want to serve media directly from your S3 bucket rather than through a proxy,
+# set this to true
+# PROXY_MEDIA=false
+
+# If you are using Amazon S3 to serve media directly, you will need to specify your region
+# name in order to access files. Example:
+#   AWS_S3_REGION_NAME=eu-west-2
+# AWS_S3_REGION_NAME= 
diff --git a/docs/admin/external-storages.rst b/docs/admin/external-storages.rst
index 413f8cfb2d..c8dbbe9635 100644
--- a/docs/admin/external-storages.rst
+++ b/docs/admin/external-storages.rst
@@ -70,6 +70,11 @@ then issue a 302 redirect to the file URL in the bucket.
 This URL is actually be visible by the client, but contains a signature valid only for one hour, to ensure
 no one can reuse this URL or share it publicly to distribute unauthorized content.
 
+.. note::
+   
+   If you are using Amazon S3, you will need to set your ``AWS_S3_REGION_NAME`` in the ``.env`` file to
+   use this feature. 
+
 .. note::
 
     Since some Subsonic clients don't support 302 redirections, Funkwhale will ignore
-- 
GitLab