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