Skip to content

Commit 3a5d25b

Browse files
authored
Use S3 from community (#7920)
Bring `S3PrivateBucketMixin` into community code so we can share more code with commercial and between our community classes as well.
1 parent 958338b commit 3a5d25b

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

readthedocs/storage/mixins.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,15 @@ def url(self, *args, **kwargs):
2424
url = urlunsplit(parts)
2525

2626
return url
27+
28+
29+
class S3PrivateBucketMixin:
30+
31+
"""Make the bucket private and use auth querystring."""
32+
33+
def __init__(self, *args, **kwargs):
34+
super().__init__(*args, **kwargs)
35+
36+
self.bucket_acl = 'private'
37+
self.default_acl = 'private'
38+
self.querystring_auth = True

readthedocs/storage/s3_storage.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
from storages.backends.s3boto3 import S3Boto3Storage
1616

1717
from readthedocs.builds.storage import BuildMediaStorageMixin
18-
from readthedocs.storage.mixins import OverrideHostnameMixin
18+
19+
from .mixins import OverrideHostnameMixin, S3PrivateBucketMixin
1920

2021

2122
class S3BuildMediaStorage(BuildMediaStorageMixin, OverrideHostnameMixin, S3Boto3Storage):
@@ -35,7 +36,7 @@ def __init__(self, *args, **kwargs):
3536
)
3637

3738

38-
class S3BuildCommandsStorage(S3Boto3Storage):
39+
class S3BuildCommandsStorage(S3PrivateBucketMixin, S3Boto3Storage):
3940

4041
"""An AWS S3 Storage backend for build commands."""
4142

@@ -50,10 +51,6 @@ def __init__(self, *args, **kwargs):
5051
'Ensure S3_BUILD_COMMANDS_STORAGE_BUCKET is defined.',
5152
)
5253

53-
self.bucket_acl = 'private'
54-
self.default_acl = 'private'
55-
self.querystring_auth = True
56-
5754

5855
class S3StaticStorage(OverrideHostnameMixin, ManifestFilesMixin, S3Boto3Storage):
5956

@@ -80,7 +77,7 @@ def __init__(self, *args, **kwargs):
8077
self.querystring_auth = False
8178

8279

83-
class S3BuildEnvironmentStorage(BuildMediaStorageMixin, S3Boto3Storage):
80+
class S3BuildEnvironmentStorage(S3PrivateBucketMixin, BuildMediaStorageMixin, S3Boto3Storage):
8481

8582
bucket_name = getattr(settings, 'S3_BUILD_ENVIRONMENT_STORAGE_BUCKET', None)
8683

@@ -92,7 +89,3 @@ def __init__(self, *args, **kwargs):
9289
'AWS S3 not configured correctly. '
9390
'Ensure S3_BUILD_ENVIRONMENT_STORAGE_BUCKET is defined.',
9491
)
95-
96-
self.bucket_acl = 'private'
97-
self.default_acl = 'private'
98-
self.querystring_auth = True

0 commit comments

Comments
 (0)