Skip to content

Commit 0830fdc

Browse files
committed
Deprecate rest.authorization-url in favor of oauth2-server-uri
1 parent 6c0d307 commit 0830fdc

File tree

7 files changed

+113
-24
lines changed

7 files changed

+113
-24
lines changed

mkdocs/docs/configuration.md

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

203203
<!-- markdown-link-check-enable-->
204204

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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ 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+
43+
```python
44+
deprecation_message(
45+
deprecated_in="0.1.0",
46+
removed_in="0.2.0",
47+
help_message="The old_property is deprecated. Please use the something_else property instead.",
48+
)
49+
```
50+
4151
## Running a release candidate
4252

4353
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: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
CommitTableRequest,
6464
CommitTableResponse,
6565
CreateTableTransaction,
66+
PropertyUtil,
6667
StagedTable,
6768
Table,
6869
TableIdentifier,
@@ -71,6 +72,7 @@
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
7374
from pyiceberg.types import transform_dict_value_to_str
75+
from pyiceberg.utils.deprecated import deprecation_message
7476
from pyiceberg.utils.properties import property_as_bool
7577

7678
if TYPE_CHECKING:
@@ -120,6 +122,7 @@ class Endpoints:
120122
SIGV4_REGION = "rest.signing-region"
121123
SIGV4_SERVICE = "rest.signing-name"
122124
AUTH_URL = "rest.authorization-url"
125+
OAUTH2_SERVER_URI = "oauth2-server-uri"
123126
HEADER_PREFIX = "header."
124127

125128
NAMESPACE_SEPARATOR = b"\x1f".decode(UTF8)
@@ -291,11 +294,38 @@ def url(self, endpoint: str, prefixed: bool = True, **kwargs: Any) -> str:
291294

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

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

pyiceberg/utils/deprecated.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,33 @@ def deprecated(deprecated_in: str, removed_in: str, help_message: Optional[str]
3030
def decorator(func: Callable): # type: ignore
3131
@functools.wraps(func)
3232
def new_func(*args: Any, **kwargs: Any) -> Any:
33-
warnings.simplefilter("always", DeprecationWarning) # turn off filter
34-
35-
warnings.warn(
36-
f"Call to {func.__name__}, deprecated in {deprecated_in}, will be removed in {removed_in}.{help_message}",
37-
category=DeprecationWarning,
38-
stacklevel=2,
39-
)
40-
warnings.simplefilter("default", DeprecationWarning) # reset filter
33+
message = f"Call to {func.__name__}, deprecated in {deprecated_in}, will be removed in {removed_in}.{help_message}"
34+
35+
_deprecation_warning(message)
36+
4137
return func(*args, **kwargs)
4238

4339
return new_func
4440

4541
return decorator
42+
43+
44+
def deprecation_message(deprecated_in: str, removed_in: str, help_message: Optional[str]) -> None:
45+
"""Mark properties or behaviors as deprecated.
46+
47+
Adding this will result in a warning being emitted.
48+
"""
49+
message = f"Deprecated in {deprecated_in}, will be removed in {removed_in}. {help_message}"
50+
51+
_deprecation_warning(message)
52+
53+
54+
def _deprecation_warning(message: str) -> None:
55+
warnings.simplefilter("always", DeprecationWarning) # turn off filter
56+
57+
warnings.warn(
58+
message,
59+
category=DeprecationWarning,
60+
stacklevel=2,
61+
)
62+
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)