Skip to content

Commit 1b68085

Browse files
Refactor _IcebergSigV4Auth to reuse canonical_request logic instead of rsplit
1 parent 8c5af07 commit 1b68085

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

pyiceberg/catalog/rest/__init__.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -745,9 +745,20 @@ def _init_sigv4(self, session: Session) -> None:
745745

746746
class _IcebergSigV4Auth(SigV4Auth):
747747
def canonical_request(self, request: Any) -> str:
748-
cr = super().canonical_request(request)
749-
# Replace the last line (body_checksum) with hex-encoded payload hash.
750-
return cr.rsplit("\n", 1)[0] + "\n" + self.payload(request)
748+
# Reuses the logic from botocore's SigV4Auth.canonical_request
749+
# (https://github.com/boto/botocore/blob/develop/botocore/auth.py)
750+
# but always uses self.payload(request) for the body checksum.
751+
cr = [request.method.upper()]
752+
path = self._normalize_url_path(parse.urlsplit(request.url).path)
753+
cr.append(path)
754+
cr.append(self.canonical_query_string(request))
755+
headers_to_sign = self.headers_to_sign(request)
756+
cr.append(self.canonical_headers(headers_to_sign) + "\n")
757+
cr.append(self.signed_headers(headers_to_sign))
758+
# Always use hex-encoded payload hash per SigV4 spec,
759+
# regardless of the x-amz-content-sha256 header value (which may be base64).
760+
cr.append(self.payload(request))
761+
return "\n".join(cr)
751762

752763
class SigV4Adapter(HTTPAdapter):
753764
def __init__(self, **properties: str):

0 commit comments

Comments
 (0)