Skip to content

Commit

Permalink
Merge pull request #39 from appknox/master
Browse files Browse the repository at this point in the history
Make django-mini-backend Region aware
  • Loading branch information
theriverman authored Feb 4, 2023
2 parents 4fa6ccf + b1f32ca commit abeed73
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions DjangoExampleProject/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@
MINIO_ACCESS_KEY = os.getenv("GH_MINIO_ACCESS_KEY", "Q3AM3UQ867SPQQA43P2F")
MINIO_SECRET_KEY = os.getenv("GH_MINIO_SECRET_KEY", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
MINIO_USE_HTTPS = bool(distutils.util.strtobool(os.getenv("GH_MINIO_USE_HTTPS", "true")))
MINIO_REGION = os.getenv("GH_MINIO_REGION", "us-east-1")
MINIO_PRIVATE_BUCKETS = [
'django-backend-dev-private',
'my-media-files-bucket',
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ from typing import List, Tuple
MINIO_ENDPOINT = 'minio.your-company.co.uk'
MINIO_EXTERNAL_ENDPOINT = "external-minio.your-company.co.uk" # Default is same as MINIO_ENDPOINT
MINIO_EXTERNAL_ENDPOINT_USE_HTTPS = True # Default is same as MINIO_USE_HTTPS
MINIO_REGION = 'us-east-1' # Default is set to None
MINIO_ACCESS_KEY = 'yourMinioAccessKey'
MINIO_SECRET_KEY = 'yourVeryS3cr3tP4ssw0rd'
MINIO_USE_HTTPS = True
Expand Down
6 changes: 4 additions & 2 deletions django_minio_backend/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def __init__(self,
self.__MINIO_ACCESS_KEY: str = get_setting("MINIO_ACCESS_KEY")
self.__MINIO_SECRET_KEY: str = get_setting("MINIO_SECRET_KEY")
self.__MINIO_USE_HTTPS: bool = get_setting("MINIO_USE_HTTPS")
self.__MINIO_REGION: str = get_setting("MINIO_REGION", "us-east-1") # MINIO defaults to "us-east-1" when region is set to None
self.__MINIO_EXTERNAL_ENDPOINT_USE_HTTPS: bool = get_setting("MINIO_EXTERNAL_ENDPOINT_USE_HTTPS", self.__MINIO_USE_HTTPS)
self.__MINIO_BUCKET_CHECK_ON_SAVE: bool = get_setting("MINIO_BUCKET_CHECK_ON_SAVE", False)

Expand Down Expand Up @@ -248,7 +249,8 @@ def url(self, name: str):
:return: (str) URL to object
"""
if self.is_bucket_public:
return f'{self.base_url_external}/{self.bucket}/{name}'
base_url = self.client._base_url.build("GET", self.__MINIO_REGION).geturl()
return f'{base_url}{self.bucket}/{name}'
if self.same_endpoints:
# in this scenario the fake client is not needed
client = self.client
Expand Down Expand Up @@ -373,7 +375,7 @@ def _create_new_client(self, fake: bool = False) -> minio.Minio:
secret_key=self.__MINIO_SECRET_KEY,
secure=self.__MINIO_EXTERNAL_ENDPOINT_USE_HTTPS if fake else self.__MINIO_USE_HTTPS,
http_client=self.HTTP_CLIENT,
region='us-east-1' if fake else None,
region=self.__MINIO_REGION,
)
if fake:
self.__CLIENT_FAKE = mc
Expand Down

0 comments on commit abeed73

Please sign in to comment.