Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Production release 24.34.0 #2362

Merged
merged 3 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions care/facility/api/serializers/facility.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import boto3
from django.conf import settings
from django.contrib.auth import get_user_model
from rest_framework import serializers

Expand Down Expand Up @@ -168,11 +169,14 @@
config, bucket_name = get_client_config(BucketType.FACILITY)
s3 = boto3.client("s3", **config)
image_location = f"cover_images/{facility.external_id}_cover.{image_extension}"
s3.put_object(
Bucket=bucket_name,
Key=image_location,
Body=image.file,
)
boto_params = {

Check warning on line 172 in care/facility/api/serializers/facility.py

View check run for this annotation

Codecov / codecov/patch

care/facility/api/serializers/facility.py#L172

Added line #L172 was not covered by tests
"Bucket": bucket_name,
"Key": image_location,
"Body": image.file,
}
if settings.BUCKET_HAS_FINE_ACL:
boto_params["ACL"] = "public-read"
s3.put_object(**boto_params)

Check warning on line 179 in care/facility/api/serializers/facility.py

View check run for this annotation

Codecov / codecov/patch

care/facility/api/serializers/facility.py#L178-L179

Added lines #L178 - L179 were not covered by tests
facility.cover_image_url = image_location
facility.save()
return facility
18 changes: 12 additions & 6 deletions care/utils/csp/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class ClientConfig(TypedDict):
class CSProvider(enum.Enum):
AWS = "AWS"
GCP = "GCP"
DIGITAL_OCEAN = "DIGITAL_OCEAN"
MINIO = "MINIO"
DOCKER = "DOCKER" # localstack in docker
LOCAL = "LOCAL" # localstack on host

Expand All @@ -31,9 +33,11 @@ def get_facility_bucket_config(external) -> tuple[ClientConfig, BucketName]:
"region_name": settings.FACILITY_S3_REGION,
"aws_access_key_id": settings.FACILITY_S3_KEY,
"aws_secret_access_key": settings.FACILITY_S3_SECRET,
"endpoint_url": settings.FACILITY_S3_BUCKET_EXTERNAL_ENDPOINT
if external
else settings.FACILITY_S3_BUCKET_ENDPOINT,
"endpoint_url": (
settings.FACILITY_S3_BUCKET_EXTERNAL_ENDPOINT
if external
else settings.FACILITY_S3_BUCKET_ENDPOINT
),
}, settings.FACILITY_S3_BUCKET


Expand All @@ -42,9 +46,11 @@ def get_patient_bucket_config(external) -> tuple[ClientConfig, BucketName]:
"region_name": settings.FILE_UPLOAD_REGION,
"aws_access_key_id": settings.FILE_UPLOAD_KEY,
"aws_secret_access_key": settings.FILE_UPLOAD_SECRET,
"endpoint_url": settings.FILE_UPLOAD_BUCKET_EXTERNAL_ENDPOINT
if external
else settings.FILE_UPLOAD_BUCKET_ENDPOINT,
"endpoint_url": (
settings.FILE_UPLOAD_BUCKET_EXTERNAL_ENDPOINT
if external
else settings.FILE_UPLOAD_BUCKET_ENDPOINT
),
}, settings.FILE_UPLOAD_BUCKET


Expand Down
1 change: 1 addition & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@
BUCKET_SECRET = env("BUCKET_SECRET", default="")
BUCKET_ENDPOINT = env("BUCKET_ENDPOINT", default="")
BUCKET_EXTERNAL_ENDPOINT = env("BUCKET_EXTERNAL_ENDPOINT", default=BUCKET_ENDPOINT)
BUCKET_HAS_FINE_ACL = env.bool("BUCKET_HAS_FINE_ACL", default=False)

if BUCKET_PROVIDER not in csp_config.CSProvider.__members__:
print(f"Warning Invalid CSP Found! {BUCKET_PROVIDER}")
Expand Down
Loading