Skip to content

Commit 50077af

Browse files
authored
Deprecate rest.authorization-url in favor of oauth2-server-uri (apache#962)
* Deprecate rest.authorization-url in favor of oauth2-server-uri * Use deprecation_message instead of deprecated for property deprecation
1 parent cb5dc12 commit 50077af

File tree

8 files changed

+116
-28
lines changed

8 files changed

+116
-28
lines changed

mkdocs/docs/configuration.md

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

214214
<!-- markdown-link-check-enable-->
215215

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/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
RecursiveDict,
6868
)
6969
from pyiceberg.utils.config import Config, merge_config
70-
from pyiceberg.utils.deprecated import deprecated
70+
from pyiceberg.utils.deprecated import deprecation_message
7171

7272
if TYPE_CHECKING:
7373
import pyarrow as pa
@@ -742,11 +742,11 @@ def __init__(self, name: str, **properties: str):
742742

743743
for property_name in DEPRECATED_PROPERTY_NAMES:
744744
if self.properties.get(property_name):
745-
deprecated(
745+
deprecation_message(
746746
deprecated_in="0.7.0",
747747
removed_in="0.8.0",
748748
help_message=f"The property {property_name} is deprecated. Please use properties that start with client., glue., and dynamo. instead",
749-
)(lambda: None)()
749+
)
750750

751751
def create_table_transaction(
752752
self,

pyiceberg/catalog/rest.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@
7171
from pyiceberg.table.sorting import UNSORTED_SORT_ORDER, SortOrder, assign_fresh_sort_order_ids
7272
from pyiceberg.typedef import EMPTY_DICT, UTF8, IcebergBaseModel, Identifier, Properties
7373
from pyiceberg.types import transform_dict_value_to_str
74-
from pyiceberg.utils.properties import property_as_bool
74+
from pyiceberg.utils.deprecated import deprecation_message
75+
from pyiceberg.utils.properties import get_first_property_value, property_as_bool
7576

7677
if TYPE_CHECKING:
7778
import pyarrow as pa
@@ -120,6 +121,7 @@ class Endpoints:
120121
SIGV4_REGION = "rest.signing-region"
121122
SIGV4_SERVICE = "rest.signing-name"
122123
AUTH_URL = "rest.authorization-url"
124+
OAUTH2_SERVER_URI = "oauth2-server-uri"
123125
HEADER_PREFIX = "header."
124126

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

292294
@property
293295
def auth_url(self) -> str:
294-
if url := self.properties.get(AUTH_URL):
296+
if self.properties.get(AUTH_URL):
297+
deprecation_message(
298+
deprecated_in="0.8.0",
299+
removed_in="0.9.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 := get_first_property_value(self.properties, AUTH_URL, OAUTH2_SERVER_URI):
295306
return url
296307
else:
297308
return self.url(Endpoints.get_token, prefixed=False)
298309

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 = property_as_bool(self.properties, 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.8.0",
319+
removed_in="1.0.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+
299328
def _extract_optional_oauth_params(self) -> Dict[str, str]:
300329
optional_oauth_param = {SCOPE: self.properties.get(SCOPE) or CATALOG_SCOPE}
301330
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)