mirror of
https://github.com/BerriAI/litellm.git
synced 2026-08-28 05:25:59 +00:00
refactor(bedrock): freeze the SSE-KMS header and key-source collections
The staging merge tightened the LIT002 ceiling, so the three mutable dict literals this branch added now breach it. Build the S3 request headers as MappingProxyType and resolve the encryption key from a tuple of sources.
This commit is contained in:
parent
10e2395395
commit
6b2ac7cc5b
2 changed files with 21 additions and 17 deletions
|
|
@ -1314,11 +1314,11 @@ def resolve_s3_encryption_key_id(
|
|||
Precedence: `s3_encryption_key_id` in litellm_params, then optional_params
|
||||
(client-side / request params), then the AWS_S3_ENCRYPTION_KEY_ID env var.
|
||||
"""
|
||||
for source in (litellm_params, optional_params or {}):
|
||||
value = source.get("s3_encryption_key_id")
|
||||
if isinstance(value, str) and value:
|
||||
return value
|
||||
return get_secret_str("AWS_S3_ENCRYPTION_KEY_ID")
|
||||
candidates: Final = tuple(
|
||||
source.get("s3_encryption_key_id") for source in (litellm_params, optional_params) if source is not None
|
||||
)
|
||||
explicit: Final = next((value for value in candidates if isinstance(value, str) and value), None)
|
||||
return explicit or get_secret_str("AWS_S3_ENCRYPTION_KEY_ID")
|
||||
|
||||
|
||||
class CommonBatchFilesUtils:
|
||||
|
|
|
|||
|
|
@ -788,20 +788,24 @@ class BedrockFilesConfig(BaseAWSLLM, BaseFilesConfig):
|
|||
|
||||
# Prepare headers with required S3 headers (same as s3_v2.py)
|
||||
sse_headers: Final = (
|
||||
{
|
||||
"x-amz-server-side-encryption": "aws:kms",
|
||||
"x-amz-server-side-encryption-aws-kms-key-id": s3_encryption_key_id,
|
||||
}
|
||||
MappingProxyType(
|
||||
{
|
||||
"x-amz-server-side-encryption": "aws:kms",
|
||||
"x-amz-server-side-encryption-aws-kms-key-id": s3_encryption_key_id,
|
||||
}
|
||||
)
|
||||
if s3_encryption_key_id
|
||||
else {}
|
||||
else MappingProxyType({})
|
||||
)
|
||||
request_headers: Final = MappingProxyType(
|
||||
{
|
||||
"Content-Type": "application/json", # JSONL files are JSON content
|
||||
"x-amz-content-sha256": content_hash, # REQUIRED by S3
|
||||
"Content-Language": "en",
|
||||
"Cache-Control": "private, immutable, max-age=31536000, s-maxage=0",
|
||||
**sse_headers,
|
||||
}
|
||||
)
|
||||
request_headers: Final = {
|
||||
"Content-Type": "application/json", # JSONL files are JSON content
|
||||
"x-amz-content-sha256": content_hash, # REQUIRED by S3
|
||||
"Content-Language": "en",
|
||||
"Cache-Control": "private, immutable, max-age=31536000, s-maxage=0",
|
||||
**sse_headers,
|
||||
}
|
||||
|
||||
# Use requests.Request to prepare the request (same pattern as s3_v2.py)
|
||||
req: Final = requests.Request("PUT", api_base, data=content, headers=request_headers)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue