Skip to content

Commit 15f6625

Browse files
guitcastroguilhermecastroFokkosungwyedgarrmondragon
committed
REST: Set access delegation (apache#1033)
* s3_signer_endpoint * prune any trailing whitespaces Co-authored-by: Fokko Driesprong <[email protected]> * fallback to default value instead of "endpoint" property Co-authored-by: Fokko Driesprong <[email protected]> * fix test_s3v4_rest_signer_endpoint * Fix missing backtick Co-authored-by: Fokko Driesprong <[email protected]> * create access_delegation property * rename S3_SIGNER_ENDPOINT_DEFAULT_VALUE to S3_SIGNER_ENDPOINT_DEFAULT * fix s3.signer.endpoint docs * fk typo in signer * fix fmt * rename ACCESS_DELEGATION_DEFAULT_VALUE to ACCESS_DELEGATION_DEFAULT * rename access_delegation to access-delegation * fix grammar Co-authored-by: Sung Yun <[email protected]> * Suggestions for apache#1033 --------- Co-authored-by: guilhermecastro <[email protected]> Co-authored-by: Fokko Driesprong <[email protected]> Co-authored-by: Sung Yun <[email protected]> Co-authored-by: Edgar Ramírez-Mondragón <[email protected]>
1 parent 2b20100 commit 15f6625

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

pyiceberg/catalog/rest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ class IdentifierKind(Enum):
112112
VIEW = "view"
113113

114114

115+
ACCESS_DELEGATION_DEFAULT = "vended-credentials"
115116
AUTHORIZATION_HEADER = "Authorization"
116117
BEARER_PREFIX = "Bearer"
117118
CATALOG_SCOPE = "catalog"
@@ -556,7 +557,7 @@ def _config_headers(self, session: Session) -> None:
556557
session.headers["Content-type"] = "application/json"
557558
session.headers["X-Client-Version"] = ICEBERG_REST_SPEC_VERSION
558559
session.headers["User-Agent"] = f"PyIceberg/{__version__}"
559-
session.headers["X-Iceberg-Access-Delegation"] = "vended-credentials"
560+
session.headers.setdefault("X-Iceberg-Access-Delegation", ACCESS_DELEGATION_DEFAULT)
560561

561562
def _extract_headers_from_properties(self) -> Dict[str, str]:
562563
return {key[len(HEADER_PREFIX) :]: value for key, value in self.properties.items() if key.startswith(HEADER_PREFIX)}

tests/catalog/test_rest.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"X-Client-Version": "0.14.1",
6161
"User-Agent": f"PyIceberg/{pyiceberg.__version__}",
6262
"Authorization": f"Bearer {TEST_TOKEN}",
63+
"X-Iceberg-Access-Delegation": "vended-credentials",
6364
}
6465
OAUTH_TEST_HEADERS = {
6566
"Content-type": "application/x-www-form-urlencoded",
@@ -708,6 +709,38 @@ def test_load_table_200(rest_mock: Mocker, example_table_metadata_with_snapshot_
708709
assert actual == expected
709710

710711

712+
def test_load_table_honor_access_delegation(
713+
rest_mock: Mocker, example_table_metadata_with_snapshot_v1_rest_json: Dict[str, Any]
714+
) -> None:
715+
test_headers_with_remote_signing = {**TEST_HEADERS, "X-Iceberg-Access-Delegation": "remote-signing"}
716+
rest_mock.get(
717+
f"{TEST_URI}v1/namespaces/fokko/tables/table",
718+
json=example_table_metadata_with_snapshot_v1_rest_json,
719+
status_code=200,
720+
request_headers=test_headers_with_remote_signing,
721+
)
722+
# catalog = RestCatalog("rest", **{"uri": TEST_URI, "token": TEST_TOKEN, "access-delegation": "remote-signing"})
723+
catalog = RestCatalog(
724+
"rest",
725+
**{
726+
"uri": TEST_URI,
727+
"token": TEST_TOKEN,
728+
"header.X-Iceberg-Access-Delegation": "remote-signing",
729+
},
730+
)
731+
actual = catalog.load_table(("fokko", "table"))
732+
expected = Table(
733+
identifier=("fokko", "table"),
734+
metadata_location=example_table_metadata_with_snapshot_v1_rest_json["metadata-location"],
735+
metadata=TableMetadataV1(**example_table_metadata_with_snapshot_v1_rest_json["metadata"]),
736+
io=load_file_io(),
737+
catalog=catalog,
738+
)
739+
# First compare the dicts
740+
assert actual.metadata.model_dump() == expected.metadata.model_dump()
741+
assert actual == expected
742+
743+
711744
def test_load_table_from_self_identifier_200(
712745
rest_mock: Mocker, example_table_metadata_with_snapshot_v1_rest_json: Dict[str, Any]
713746
) -> None:

0 commit comments

Comments
 (0)