Skip to content

Commit e6d0198

Browse files
committed
Deprecate rest.authorization-url in favor of oauth2-server-uri
1 parent 861c563 commit e6d0198

File tree

7 files changed

+96
-17
lines changed

7 files changed

+96
-17
lines changed

mkdocs/docs/configuration.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -180,19 +180,19 @@ catalog:
180180
181181
<!-- markdown-link-check-disable -->
182182
183-
| Key | Example | Description |
184-
| ---------------------- | -------------------------------- | -------------------------------------------------------------------------------------------------- |
185-
| uri | https://rest-catalog/ws | URI identifying the REST Server |
186-
| ugi | t-1234:secret | Hadoop UGI for Hive client. |
187-
| credential | t-1234:secret | Credential to use for OAuth2 credential flow when initializing the catalog |
188-
| token | FEW23.DFSDF.FSDF | Bearer token value to use for `Authorization` header |
189-
| scope | openid offline corpds:ds:profile | Desired scope of the requested security token (default : catalog) |
190-
| resource | rest_catalog.iceberg.com | URI for the target resource or service |
191-
| audience | rest_catalog | Logical name of target resource or service |
192-
| rest.sigv4-enabled | true | Sign requests to the REST Server using AWS SigV4 protocol |
193-
| rest.signing-region | us-east-1 | The region to use when SigV4 signing a request |
194-
| rest.signing-name | execute-api | The service signing name to use when SigV4 signing a request |
195-
| rest.authorization-url | https://auth-service/cc | Authentication URL to use for client credentials authentication (default: uri + 'v1/oauth/tokens') |
183+
| Key | Example | Description |
184+
| ------------------- | -------------------------------- | -------------------------------------------------------------------------------------------------- |
185+
| uri | https://rest-catalog/ws | URI identifying the REST Server |
186+
| ugi | t-1234:secret | Hadoop UGI for Hive client. |
187+
| credential | t-1234:secret | Credential to use for OAuth2 credential flow when initializing the catalog |
188+
| token | FEW23.DFSDF.FSDF | Bearer token value to use for `Authorization` header |
189+
| scope | openid offline corpds:ds:profile | Desired scope of the requested security token (default : catalog) |
190+
| resource | rest_catalog.iceberg.com | URI for the target resource or service |
191+
| audience | rest_catalog | Logical name of target resource or service |
192+
| rest.sigv4-enabled | true | Sign requests to the REST Server using AWS SigV4 protocol |
193+
| rest.signing-region | us-east-1 | The region to use when SigV4 signing a request |
194+
| rest.signing-name | execute-api | The service signing name to use when SigV4 signing a request |
195+
| oauth2-server-uri | https://auth-service/cc | Authentication URL to use for client credentials authentication (default: uri + 'v1/oauth/tokens') |
196196

197197
<!-- markdown-link-check-enable-->
198198

mkdocs/docs/contributing.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,24 @@ Which will warn:
180180
Call to load_something, deprecated in 0.1.0, will be removed in 0.2.0. Please use load_something_else() instead.
181181
```
182182

183+
If you want to remove a property or notify about a behavior change, please add a deprecation notice by calling the deprecation_message function:
184+
185+
```python
186+
from pyiceberg.utils.deprecated import deprecation_message
187+
188+
deprecation_message(
189+
deprecated_in="0.1.0",
190+
removed_in="0.2.0",
191+
help_message="The old_property is deprecated. Please use the something_else property instead.",
192+
)
193+
```
194+
195+
Which will warn:
196+
197+
```
198+
Deprecated in 0.1.0, will be removed in 0.2.0. The old_property is deprecated. Please use the something_else property instead.
199+
```
200+
183201
## Type annotations
184202

185203
For the type annotation the types from the `Typing` package are used.

mkdocs/docs/how-to-release.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ For example, the API with the following deprecation tag should be removed when p
3838
)
3939
```
4040

41+
We also have the `deprecation_message` function. We need to change the behavior according to what is noted in the message of that deprecation.
42+
4143
## Running a release candidate
4244

4345
Make sure that the version is correct in `pyproject.toml` and `pyiceberg/__init__.py`. Correct means that it reflects the version that you want to release.

pyiceberg/catalog/rest.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,16 @@
6363
CommitTableRequest,
6464
CommitTableResponse,
6565
CreateTableTransaction,
66+
PropertyUtil,
6667
StagedTable,
6768
Table,
6869
TableIdentifier,
6970
)
7071
from pyiceberg.table.metadata import TableMetadata
7172
from pyiceberg.table.sorting import UNSORTED_SORT_ORDER, SortOrder, assign_fresh_sort_order_ids
7273
from pyiceberg.typedef import EMPTY_DICT, UTF8, IcebergBaseModel, Identifier, Properties
73-
from pyiceberg.types import transform_dict_value_to_str
74+
from pyiceberg.types import strtobool, transform_dict_value_to_str
75+
from pyiceberg.utils.deprecated import deprecation_message
7476

7577
if TYPE_CHECKING:
7678
import pyarrow as pa
@@ -119,6 +121,7 @@ class Endpoints:
119121
SIGV4_REGION = "rest.signing-region"
120122
SIGV4_SERVICE = "rest.signing-name"
121123
AUTH_URL = "rest.authorization-url"
124+
OAUTH2_SERVER_URI = "oauth2-server-uri"
122125
HEADER_PREFIX = "header."
123126

124127
NAMESPACE_SEPARATOR = b"\x1f".decode(UTF8)
@@ -290,11 +293,38 @@ def url(self, endpoint: str, prefixed: bool = True, **kwargs: Any) -> str:
290293

291294
@property
292295
def auth_url(self) -> str:
293-
if url := self.properties.get(AUTH_URL):
296+
if self.properties.get(AUTH_URL):
297+
deprecation_message(
298+
deprecated_in="0.7.0",
299+
removed_in="0.8.0",
300+
help_message=f"The property {AUTH_URL} is deprecated. Please use {OAUTH2_SERVER_URI} instead",
301+
)
302+
303+
self._warn_oauth_tokens_deprecation()
304+
305+
if url := PropertyUtil.get_first_property_value(self.properties, AUTH_URL, OAUTH2_SERVER_URI):
294306
return url
295307
else:
296308
return self.url(Endpoints.get_token, prefixed=False)
297309

310+
def _warn_oauth_tokens_deprecation(self) -> None:
311+
has_oauth_server_uri = OAUTH2_SERVER_URI in self.properties
312+
has_credential = CREDENTIAL in self.properties
313+
has_init_token = TOKEN in self.properties
314+
has_sigv4_enabled = strtobool(self.properties.get(SIGV4, "false"))
315+
316+
if not has_oauth_server_uri and (has_init_token or has_credential) and not has_sigv4_enabled:
317+
deprecation_message(
318+
deprecated_in="0.7.0",
319+
removed_in="0.8.0",
320+
help_message="Iceberg REST client is missing the OAuth2 server URI "
321+
f"configuration and defaults to {self.uri}{Endpoints.get_token}. "
322+
"This automatic fallback will be removed in a future Iceberg release."
323+
f"It is recommended to configure the OAuth2 endpoint using the '{OAUTH2_SERVER_URI}'"
324+
"property to be prepared. This warning will disappear if the OAuth2"
325+
"endpoint is explicitly configured. See https://github.com/apache/iceberg/issues/10537",
326+
)
327+
298328
def _extract_optional_oauth_params(self) -> Dict[str, str]:
299329
optional_oauth_param = {SCOPE: self.properties.get(SCOPE) or CATALOG_SCOPE}
300330
set_of_optional_params = {AUDIENCE, RESOURCE}

pyiceberg/utils/deprecated.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,18 @@ def new_func(*args: Any, **kwargs: Any) -> Any:
4343
return new_func
4444

4545
return decorator
46+
47+
48+
def deprecation_message(deprecated_in: str, removed_in: str, help_message: Optional[str]) -> None:
49+
"""Mark properties as deprecated.
50+
51+
Adding this will result in a warning being emitted when the property is used.
52+
"""
53+
warnings.simplefilter("always", DeprecationWarning) # turn off filter
54+
55+
warnings.warn(
56+
f"Deprecated in {deprecated_in}, will be removed in {removed_in}. {help_message}",
57+
category=DeprecationWarning,
58+
stacklevel=2,
59+
)
60+
warnings.simplefilter("default", DeprecationWarning) # reset filter

tests/catalog/test_rest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
import pyiceberg
2626
from pyiceberg.catalog import PropertiesUpdateSummary, load_catalog
27-
from pyiceberg.catalog.rest import AUTH_URL, RestCatalog
27+
from pyiceberg.catalog.rest import OAUTH2_SERVER_URI, RestCatalog
2828
from pyiceberg.exceptions import (
2929
AuthorizationExpiredError,
3030
NamespaceAlreadyExistsError,
@@ -235,7 +235,7 @@ def test_token_200_w_auth_url(rest_mock: Mocker) -> None:
235235
)
236236
# pylint: disable=W0212
237237
assert (
238-
RestCatalog("rest", uri=TEST_URI, credential=TEST_CREDENTIALS, **{AUTH_URL: TEST_AUTH_URL})._session.headers[
238+
RestCatalog("rest", uri=TEST_URI, credential=TEST_CREDENTIALS, **{OAUTH2_SERVER_URI: TEST_AUTH_URL})._session.headers[
239239
"Authorization"
240240
]
241241
== f"Bearer {TEST_TOKEN}"

tests/utils/test_deprecated.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,17 @@ def deprecated_method() -> None:
3535
assert warn.call_args[0] == (
3636
"Call to deprecated_method, deprecated in 0.1.0, will be removed in 0.2.0. Please use load_something_else() instead.",
3737
)
38+
39+
40+
@patch("warnings.warn")
41+
def test_deprecation_message(warn: Mock) -> None:
42+
from pyiceberg.utils.deprecated import deprecation_message
43+
44+
deprecation_message(
45+
deprecated_in="0.1.0",
46+
removed_in="0.2.0",
47+
help_message="Please use something_else instead",
48+
)
49+
50+
assert warn.called
51+
assert warn.call_args[0] == ("Deprecated in 0.1.0, will be removed in 0.2.0. Please use something_else instead",)

0 commit comments

Comments
 (0)