You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2022/10/14 16:14:38 UTC

[GitHub] [iceberg] Fokko commented on a diff in pull request #5969: Python: Implement S3V4RestSigner

Fokko commented on code in PR #5969:
URL: https://github.com/apache/iceberg/pull/5969#discussion_r995925685


##########
python/pyiceberg/io/fsspec.py:
##########
@@ -15,28 +15,76 @@
 # specific language governing permissions and limitations
 # under the License.
 """FileIO implementation for reading and writing table files that uses fsspec compatible filesystems"""
-
-from functools import lru_cache
-from typing import Callable, Union
+import logging
+from functools import lru_cache, partial
+from typing import Callable, Dict, Union
 from urllib.parse import urlparse
 
+import requests
+from botocore import UNSIGNED
+from botocore.awsrequest import AWSRequest
 from fsspec import AbstractFileSystem
+from requests import HTTPError
 from s3fs import S3FileSystem
 
+from pyiceberg.exceptions import SignError
 from pyiceberg.io import FileIO, InputFile, OutputFile
 from pyiceberg.typedef import Properties
 
+logger = logging.getLogger(__name__)
+
+
+def s3v4_rest_signer(properties: Properties, request: AWSRequest, **_) -> AWSRequest:
+    signer_url = properties["uri"].rstrip("/")
+    signer_headers = {"Authorization": f"Bearer {properties['token']}"}
+    signer_body = {
+        "method": request.method,
+        "region": request.context["client_region"],
+        "uri": request.url,
+        "headers": {key: [val] for key, val in request.headers.items()},
+    }
+    try:
+        response = requests.post(f"{signer_url}/v1/aws/s3/sign", headers=signer_headers, json=signer_body)
+        response.raise_for_status()
+        response_json = response.json()
+    except HTTPError as e:
+        raise SignError(f"Failed to sign request: {signer_headers}") from e

Review Comment:
   Good call, thanks!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org