Skip to content

Commit

Permalink
Merge Develop to Staging 24.34.0 | Patchh (#2360)
Browse files Browse the repository at this point in the history
fix s3 client error on gcp (#2359)

Co-authored-by: Aakash Singh <[email protected]>
  • Loading branch information
nihal467 and sainak authored Aug 14, 2024
1 parent ddc20cf commit aa29b86
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
15 changes: 9 additions & 6 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,12 +169,14 @@ def save(self, **kwargs):
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,
ACL="public-read",
)
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

0 comments on commit aa29b86

Please sign in to comment.