2626from tenacity import RetryCallState , retry , retry_if_exception_type , stop_after_attempt
2727
2828from pyiceberg import __version__
29- from pyiceberg .catalog import (
30- BOTOCORE_SESSION ,
31- TOKEN ,
32- URI ,
33- WAREHOUSE_LOCATION ,
34- Catalog ,
35- PropertiesUpdateSummary ,
36- )
29+ from pyiceberg .catalog import AUTH_MANAGER , BOTOCORE_SESSION , TOKEN , URI , WAREHOUSE_LOCATION , Catalog , PropertiesUpdateSummary
3730from pyiceberg .catalog .rest .auth import AuthManager , AuthManagerAdapter , AuthManagerFactory , LegacyOAuth2AuthManager
3831from pyiceberg .catalog .rest .response import _handle_non_200_response
3932from pyiceberg .exceptions import (
4942 TableAlreadyExistsError ,
5043 UnauthorizedError ,
5144)
52- from pyiceberg .io import AWS_ACCESS_KEY_ID , AWS_REGION , AWS_SECRET_ACCESS_KEY , AWS_SESSION_TOKEN
45+ from pyiceberg .io import AWS_ACCESS_KEY_ID , AWS_REGION , AWS_SECRET_ACCESS_KEY , AWS_SESSION_TOKEN , FileIO , load_file_io
5346from pyiceberg .partitioning import UNPARTITIONED_PARTITION_SPEC , PartitionSpec , assign_fresh_partition_spec_ids
5447from pyiceberg .schema import Schema , assign_fresh_schema_ids
5548from pyiceberg .table import (
@@ -214,6 +207,7 @@ class ListViewsResponse(IcebergBaseModel):
214207class RestCatalog (Catalog ):
215208 uri : str
216209 _session : Session
210+ _auth_manager : AuthManager | None
217211
218212 def __init__ (self , name : str , ** properties : str ):
219213 """Rest Catalog.
@@ -225,6 +219,7 @@ def __init__(self, name: str, **properties: str):
225219 properties: Properties that are passed along to the configuration.
226220 """
227221 super ().__init__ (name , ** properties )
222+ self ._auth_manager : AuthManager | None = None
228223 self .uri = properties [URI ]
229224 self ._fetch_config ()
230225 self ._session = self ._create_session ()
@@ -259,16 +254,24 @@ def _create_session(self) -> Session:
259254 if auth_type != CUSTOM and auth_impl :
260255 raise ValueError ("auth.impl can only be specified when using custom auth.type" )
261256
262- session .auth = AuthManagerAdapter (AuthManagerFactory .create (auth_impl or auth_type , auth_type_config ))
257+ self ._auth_manager = AuthManagerFactory .create (auth_impl or auth_type , auth_type_config )
258+ session .auth = AuthManagerAdapter (self ._auth_manager )
263259 else :
264- session .auth = AuthManagerAdapter (self ._create_legacy_oauth2_auth_manager (session ))
260+ self ._auth_manager = self ._create_legacy_oauth2_auth_manager (session )
261+ session .auth = AuthManagerAdapter (self ._auth_manager )
265262
266263 # Configure SigV4 Request Signing
267264 if property_as_bool (self .properties , SIGV4 , False ):
268265 self ._init_sigv4 (session )
269266
270267 return session
271268
269+ def _load_file_io (self , properties : Properties = EMPTY_DICT , location : str | None = None ) -> FileIO :
270+ merged_properties = {** self .properties , ** properties }
271+ if self ._auth_manager :
272+ merged_properties [AUTH_MANAGER ] = self ._auth_manager
273+ return load_file_io (merged_properties , location )
274+
272275 def _create_legacy_oauth2_auth_manager (self , session : Session ) -> AuthManager :
273276 """Create the LegacyOAuth2AuthManager by fetching required properties.
274277
0 commit comments