Skip to content

Commit 0008d65

Browse files
authored
REST: Keep vended storage credentials for staged tables (#4329)
1 parent 533dea9 commit 0008d65

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
@@ -1198,9 +1198,8 @@ def _response_to_table(self, identifier_tuple: tuple[str, ...], table_response:
11981198

11991199
def _response_to_staged_table(self, identifier_tuple: tuple[str, ...], table_response: TableResponse) -> StagedTable:
12001200
# Per Iceberg spec: storage-credentials take precedence over config
1201-
credential_config = self._resolve_storage_credentials(
1202-
table_response.storage_credentials, table_response.metadata_location
1203-
)
1201+
credential_location = table_response.metadata_location or f"{table_response.metadata.location.rstrip('/')}/"
1202+
credential_config = self._resolve_storage_credentials(table_response.storage_credentials, credential_location)
12041203
return StagedTable(
12051204
identifier=identifier_tuple,
12061205
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
@@ -1798,6 +1798,33 @@ def test_create_staged_table_200(
17981798
assert actual_response == expected
17991799

18001800

1801+
def test_create_staged_table_with_storage_credentials(
1802+
rest_mock: Mocker,
1803+
table_schema_simple: Schema,
1804+
example_table_metadata_no_snapshot_v1: dict[str, Any],
1805+
) -> None:
1806+
table_location = "gs://bucket/ns/t"
1807+
rest_mock.post(
1808+
f"{TEST_URI}v1/namespaces/fokko/tables",
1809+
json={
1810+
"metadata": {**example_table_metadata_no_snapshot_v1, "location": table_location},
1811+
"config": {},
1812+
"storage-credentials": [
1813+
{
1814+
"prefix": f"{table_location}/",
1815+
"config": {"gcs.oauth2.token": "vended"},
1816+
}
1817+
],
1818+
},
1819+
status_code=200,
1820+
request_headers=TEST_HEADERS,
1821+
)
1822+
catalog = RestCatalog("rest", uri=TEST_URI, token=TEST_TOKEN)
1823+
txn = catalog.create_table_transaction(identifier=("fokko", "fokko2"), schema=table_schema_simple)
1824+
1825+
assert txn._table.io.properties["gcs.oauth2.token"] == "vended"
1826+
1827+
18011828
def test_create_table_409(rest_mock: Mocker, table_schema_simple: Schema) -> None:
18021829
rest_mock.post(
18031830
f"{TEST_URI}v1/namespaces/fokko/tables",

0 commit comments

Comments
 (0)