rdblue commented on code in PR #5969:
URL: https://github.com/apache/iceberg/pull/5969#discussion_r995911632
##########
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
+
+ for key, value in response_json["headers"].items():
+ request.headers.add_header(key, value[0])
Review Comment:
Do we need to handle a case where there's more than one header value? Would
that be joined somehow?
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]