Skip to content

Commit 9bbab96

Browse files
committed
REST: Keep vended storage credentials for staged tables
1 parent 1310a19 commit 9bbab96

2 files changed

Lines changed: 29 additions & 3 deletions

File tree

‎pyiceberg/catalog/rest/__init__.py‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,9 +1170,8 @@ def _response_to_table(self, identifier_tuple: tuple[str, ...], table_response:
11701170

11711171
def _response_to_staged_table(self, identifier_tuple: tuple[str, ...], table_response: TableResponse) -> StagedTable:
11721172
# Per Iceberg spec: storage-credentials take precedence over config
1173-
credential_config = self._resolve_storage_credentials(
1174-
table_response.storage_credentials, table_response.metadata_location
1175-
)
1173+
credential_location = table_response.metadata_location or f"{table_response.metadata.location.rstrip('/')}/"
1174+
credential_config = self._resolve_storage_credentials(table_response.storage_credentials, credential_location)
11761175
return StagedTable(
11771176
identifier=identifier_tuple,
11781177
metadata_location=table_response.metadata_location, # type: ignore

‎tests/catalog/test_rest.py‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,6 +1744,33 @@ def test_create_staged_table_200(
17441744
assert actual_response == expected
17451745

17461746

1747+
def test_create_staged_table_with_storage_credentials(
1748+
rest_mock: Mocker,
1749+
table_schema_simple: Schema,
1750+
example_table_metadata_no_snapshot_v1: dict[str, Any],
1751+
) -> None:
1752+
table_location = "gs://bucket/ns/t"
1753+
rest_mock.post(
1754+
f"{TEST_URI}v1/namespaces/fokko/tables",
1755+
json={
1756+
"metadata": {**example_table_metadata_no_snapshot_v1, "location": table_location},
1757+
"config": {},
1758+
"storage-credentials": [
1759+
{
1760+
"prefix": f"{table_location}/",
1761+
"config": {"gcs.oauth2.token": "vended"},
1762+
}
1763+
],
1764+
},
1765+
status_code=200,
1766+
request_headers=TEST_HEADERS,
1767+
)
1768+
catalog = RestCatalog("rest", uri=TEST_URI, token=TEST_TOKEN)
1769+
txn = catalog.create_table_transaction(identifier=("fokko", "fokko2"), schema=table_schema_simple)
1770+
1771+
assert txn._table.io.properties["gcs.oauth2.token"] == "vended"
1772+
1773+
17471774
def test_create_table_409(rest_mock: Mocker, table_schema_simple: Schema) -> None:
17481775
rest_mock.post(
17491776
f"{TEST_URI}v1/namespaces/fokko/tables",

0 commit comments

Comments
 (0)