|
71 | 71 | from pyiceberg.table.sorting import UNSORTED_SORT_ORDER, SortOrder, assign_fresh_sort_order_ids |
72 | 72 | from pyiceberg.typedef import EMPTY_DICT, UTF8, IcebergBaseModel, Identifier, Properties |
73 | 73 | 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 |
75 | 76 |
|
76 | 77 | if TYPE_CHECKING: |
77 | 78 | import pyarrow as pa |
@@ -120,6 +121,7 @@ class Endpoints: |
120 | 121 | SIGV4_REGION = "rest.signing-region" |
121 | 122 | SIGV4_SERVICE = "rest.signing-name" |
122 | 123 | AUTH_URL = "rest.authorization-url" |
| 124 | +OAUTH2_SERVER_URI = "oauth2-server-uri" |
123 | 125 | HEADER_PREFIX = "header." |
124 | 126 |
|
125 | 127 | NAMESPACE_SEPARATOR = b"\x1f".decode(UTF8) |
@@ -291,11 +293,38 @@ def url(self, endpoint: str, prefixed: bool = True, **kwargs: Any) -> str: |
291 | 293 |
|
292 | 294 | @property |
293 | 295 | 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): |
295 | 306 | return url |
296 | 307 | else: |
297 | 308 | return self.url(Endpoints.get_token, prefixed=False) |
298 | 309 |
|
| 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 | + |
299 | 328 | def _extract_optional_oauth_params(self) -> Dict[str, str]: |
300 | 329 | optional_oauth_param = {SCOPE: self.properties.get(SCOPE) or CATALOG_SCOPE} |
301 | 330 | set_of_optional_params = {AUDIENCE, RESOURCE} |
|
0 commit comments