Skip to content

Commit 3835f5f

Browse files
committed
refactor: improve get_s3_config to handle optional environment variables more robustly
1 parent 72f44ec commit 3835f5f

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

src/gitingest/utils/s3_utils.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,27 @@ def is_s3_enabled() -> bool:
2222

2323
def get_s3_config() -> dict[str, Any]:
2424
"""Get S3 configuration from environment variables."""
25-
return {
26-
"endpoint_url": os.getenv("S3_ENDPOINT"),
27-
"aws_access_key_id": os.getenv("S3_ACCESS_KEY"),
28-
"aws_secret_access_key": os.getenv("S3_SECRET_KEY"),
29-
"region_name": os.getenv("S3_REGION", "us-east-1"),
30-
}
25+
config = {}
26+
27+
# Only include endpoint_url if it's set (for custom S3-compatible services)
28+
endpoint_url = os.getenv("S3_ENDPOINT")
29+
if endpoint_url:
30+
config["endpoint_url"] = endpoint_url
31+
32+
# Only include credentials if they're explicitly set
33+
access_key = os.getenv("S3_ACCESS_KEY")
34+
if access_key:
35+
config["aws_access_key_id"] = access_key
36+
37+
secret_key = os.getenv("S3_SECRET_KEY")
38+
if secret_key:
39+
config["aws_secret_access_key"] = secret_key
40+
41+
# For region, check S3_REGION first, then fall back to AWS_REGION
42+
region = os.getenv("S3_REGION") or os.getenv("AWS_REGION", "us-east-1")
43+
config["region_name"] = region
44+
45+
return config
3146

3247

3348
def get_s3_bucket_name() -> str:

0 commit comments

Comments
 (0)