Skip to content

Commit 8e6d612

Browse files
committed
refactor: update docstrings
1 parent c021dfb commit 8e6d612

1 file changed

Lines changed: 8 additions & 10 deletions

File tree

  • src/streamable/utils

src/streamable/utils/s3.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""AWS S3 Signature Version 4 utility for generating authentication headers.
1+
"""AWS S3 Signature V4 utility for generating authentication headers.
22
33
This module provides functions to calculate AWS Signature V4 signatures
44
and build headers for S3 upload requests.
@@ -9,7 +9,7 @@
99
import hashlib
1010
import hmac
1111
from datetime import datetime, timezone
12-
from typing import Optional
12+
from typing import Literal, Optional, Union
1313
from urllib.parse import quote
1414
from ..api.models import UploadInfo
1515

@@ -69,7 +69,7 @@ def _create_canonical_request(
6969
canonical_query_string: str,
7070
canonical_headers: str,
7171
signed_headers: str,
72-
payload_hash: str,
72+
payload_hash: Union[Literal["UNSIGNED-PAYLOAD"], str],
7373
) -> str:
7474
"""Create the canonical request string.
7575
@@ -126,16 +126,16 @@ def calculate_aws_s3_v4_signature(
126126
session_token: str,
127127
region: str,
128128
timestamp: str,
129-
payload_hash: str = "UNSIGNED-PAYLOAD",
129+
payload_hash: Union[Literal["UNSIGNED-PAYLOAD"], str] = "UNSIGNED-PAYLOAD",
130130
query_params: Optional[dict[str, str]] = None,
131131
extra_headers: Optional[dict[str, str]] = None,
132132
) -> tuple[str, str, str]:
133133
"""Calculate AWS S3 V4 signature.
134134
135135
Args:
136136
method: HTTP method (e.g., 'PUT', 'GET')
137-
host: Host header value (e.g., 'streamables-upload.s3.amazonaws.com')
138-
path: Request path (e.g., '/upload/y3vwnh')
137+
host: Host header value (e.g., 'some-bucket.s3.amazonaws.com')
138+
path: Request path (e.g., '/some/key')
139139
access_key: AWS access key ID
140140
secret_key: AWS secret access key
141141
session_token: AWS session token
@@ -223,16 +223,14 @@ def calculate_aws_s3_v4_signature(
223223
def build_s3_upload_headers(
224224
upload_info: UploadInfo,
225225
content_length: int,
226-
content_type: str = "application/octet-stream",
227226
use_current_timestamp: bool = True,
228227
) -> dict[str, str]:
229228
"""Build headers for S3 upload request from UploadInfo model.
230229
231230
Args:
232231
upload_info: UploadInfo pydantic model instance
233232
content_length: Size of the file being uploaded in bytes
234-
content_type: MIME type of the content (default: 'application/octet-stream')
235-
use_current_timestamp: If True, generate a new timestamp (recommended for actual uploads)
233+
use_current_timestamp: If True, generate a new timestamp (must use for actual uploads)
236234
237235
Returns:
238236
Dictionary of headers ready for the PUT request
@@ -281,7 +279,7 @@ def build_s3_upload_headers(
281279
headers: dict[str, str] = {
282280
"Host": host,
283281
"Authorization": auth_header,
284-
"Content-Type": content_type,
282+
"Content-Type": "application/octet-stream",
285283
"Content-Length": str(content_length),
286284
"x-amz-content-sha256": "UNSIGNED-PAYLOAD",
287285
"x-amz-date": timestamp,

0 commit comments

Comments
 (0)