|
| 1 | +""" |
| 2 | +boto3 doc |
| 3 | +https://boto3.amazonaws.com/v1/documentation/api/latest/guide/collections.html |
| 4 | +
|
| 5 | +bucket = s3.get_bucket() |
| 6 | +s3.get_bucket_cors(bucket) |
| 7 | +s3.get_bucket_policy(bucket) |
| 8 | +""" |
| 9 | + |
1 | 10 | import json |
2 | 11 |
|
3 | 12 | import boto3 |
4 | 13 | from botocore.client import Config |
5 | 14 | from django.conf import settings |
6 | 15 |
|
7 | 16 |
|
8 | | -# boto3 doc |
9 | | -# https://boto3.amazonaws.com/v1/documentation/api/latest/guide/collections.html |
10 | | - |
11 | | - |
12 | 17 | API_CONNECTION_DICT = { |
13 | 18 | "endpoint_url": settings.S3_ENDPOINT, |
14 | 19 | "aws_access_key_id": settings.S3_ACCESS_KEY, |
|
32 | 37 | } |
33 | 38 |
|
34 | 39 | DEFAULT_POLICY_CONFIGURATION = { |
35 | | - "Version": "2012-10-17", |
| 40 | + "Version": "2023-04-17", |
36 | 41 | "Statement": [ |
37 | 42 | { |
38 | 43 | "Sid": "AllowPublicRead", |
|
42 | 47 | "Resource": f"{settings.S3_BUCKET_NAME}/*", |
43 | 48 | }, |
44 | 49 | { |
45 | | - "Sid": "DenyPublicUpdate", |
46 | | - "Effect": "Deny", |
47 | | - "Principal": "*", |
48 | | - "Action": "s3:PutObject", |
49 | | - "Resource": f"{settings.S3_BUCKET_NAME}/*", |
50 | | - }, |
51 | | - { |
52 | | - "Sid": "DenyPublicDelete", |
53 | | - "Effect": "Deny", |
54 | | - "Principal": "*", |
55 | | - "Action": "s3:DeleteObject", |
56 | | - "Resource": f"{settings.S3_BUCKET_NAME}/*", |
| 50 | + "Sid": "AllowPrivateReadAndUpdate", |
| 51 | + "Effect": "Allow", |
| 52 | + "Principal": {"SCW": f"user_id:{settings.S3_USER_ID}"}, |
| 53 | + "Action": "*", |
| 54 | + "Resource": [f"{settings.S3_BUCKET_NAME}", f"{settings.S3_BUCKET_NAME}/*"], |
57 | 55 | }, |
58 | 56 | ], |
59 | 57 | } |
|
0 commit comments