-
Notifications
You must be signed in to change notification settings - Fork 329
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix bucket configurations * add type annotations
- Loading branch information
Showing
11 changed files
with
114 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,56 @@ | ||
import enum | ||
from typing import TypeAlias, TypedDict | ||
|
||
from django.conf import settings | ||
|
||
|
||
class ClientConfig(TypedDict): | ||
region_name: str | ||
aws_access_key_id: str | ||
aws_secret_access_key: str | ||
endpoint_url: str | ||
|
||
|
||
BucketName: TypeAlias = str | ||
|
||
|
||
class CSProvider(enum.Enum): | ||
AWS = "AWS" | ||
GCP = "GCP" | ||
AZURE = "AZURE" | ||
DOCKER = "DOCKER" # localstack in docker | ||
LOCAL = "LOCAL" # localstack on host | ||
|
||
|
||
class BucketType(enum.Enum): | ||
PATIENT = "PATIENT" | ||
FACILITY = "FACILITY" | ||
|
||
|
||
DEFAULT = CSProvider.AWS.value | ||
|
||
|
||
def get_client_config(bucket_type=BucketType.PATIENT.value): | ||
config = { | ||
BucketType.PATIENT.value: { | ||
"region_name": settings.CLOUD_REGION, | ||
"aws_access_key_id": settings.FILE_UPLOAD_KEY, | ||
"aws_secret_access_key": settings.FILE_UPLOAD_SECRET, | ||
"endpoint_url": settings.FILE_UPLOAD_BUCKET_ENDPOINT, | ||
}, | ||
BucketType.FACILITY.value: { | ||
"region_name": settings.CLOUD_REGION, | ||
"aws_access_key_id": settings.FACILITY_S3_KEY, | ||
"aws_secret_access_key": settings.FACILITY_S3_SECRET, | ||
"endpoint_url": settings.FACILITY_S3_BUCKET_ENDPOINT, | ||
}, | ||
} | ||
|
||
if settings.CLOUD_PROVIDER == CSProvider.GCP.value: | ||
for key in config.keys(): | ||
config[key]["endpoint_url"] = "https://storage.googleapis.com" | ||
|
||
return config[bucket_type] | ||
def get_facility_bucket_config(external) -> tuple[ClientConfig, BucketName]: | ||
return { | ||
"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, | ||
}, settings.FACILITY_S3_BUCKET | ||
|
||
|
||
def get_patient_bucket_config(external) -> tuple[ClientConfig, BucketName]: | ||
return { | ||
"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, | ||
}, settings.FILE_UPLOAD_BUCKET | ||
|
||
|
||
def get_client_config(bucket_type: BucketType, external=False): | ||
if bucket_type == BucketType.FACILITY: | ||
return get_facility_bucket_config(external=external) | ||
elif bucket_type == BucketType.PATIENT: | ||
return get_patient_bucket_config(external=external) | ||
raise ValueError("Invalid Bucket Type") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
#!/usr/bin/env bash | ||
#!/usr/bin/sh | ||
|
||
set -x | ||
awslocal s3 mb s3://patient-bucket | ||
awslocal s3 mb s3://facility-bucket | ||
|