File tree Expand file tree Collapse file tree 3 files changed +13
-6
lines changed Expand file tree Collapse file tree 3 files changed +13
-6
lines changed Original file line number Diff line number Diff line change 4040
4141_ENV_CONFIG = Config ()
4242
43+ TOKEN = "token"
4344TYPE = "type"
4445URI = "uri"
4546
Original file line number Diff line number Diff line change 3030
3131from pyiceberg import __version__
3232from pyiceberg .catalog import (
33+ TOKEN ,
3334 URI ,
3435 Catalog ,
3536 Identifier ,
@@ -87,7 +88,6 @@ class Endpoints:
8788CREDENTIAL = "credential"
8889GRANT_TYPE = "grant_type"
8990SCOPE = "scope"
90- TOKEN = "token"
9191TOKEN_EXCHANGE = "urn:ietf:params:oauth:grant-type:token-exchange"
9292SEMICOLON = ":"
9393KEY = "key"
@@ -206,12 +206,13 @@ def _create_session(self) -> None:
206206 elif ssl_client_cert := ssl_client .get (CERT ):
207207 self .session .cert = ssl_client_cert
208208
209+ # If we have credentials, but not a token, we want to fetch a token
210+ if TOKEN not in self .properties and CREDENTIAL in self .properties :
211+ self .properties [TOKEN ] = self ._fetch_access_token (self .properties [CREDENTIAL ])
212+
209213 # Set Auth token for subsequent calls in the session
210214 if token := self .properties .get (TOKEN ):
211215 self .session .headers [AUTHORIZATION_HEADER ] = f"{ BEARER_PREFIX } { token } "
212- elif credential := self .properties .get (CREDENTIAL ):
213- token = self ._fetch_access_token (credential )
214- self .session .headers [AUTHORIZATION_HEADER ] = f"{ BEARER_PREFIX } { token } "
215216
216217 # Set HTTP headers
217218 self .session .headers ["Content-type" ] = "application/json"
Original file line number Diff line number Diff line change 2727from requests import HTTPError
2828from s3fs import S3FileSystem
2929
30+ from pyiceberg .catalog import TOKEN
3031from pyiceberg .exceptions import SignError
3132from pyiceberg .io import FileIO , InputFile , OutputFile
3233from pyiceberg .typedef import Properties
3536
3637
3738def s3v4_rest_signer (properties : Properties , request : AWSRequest , ** _ ) -> AWSRequest :
39+ if TOKEN not in properties :
40+ raise SignError ("Signer set, but token is not available" )
41+
3842 signer_url = properties ["uri" ].rstrip ("/" )
39- signer_headers = {"Authorization" : f"Bearer { properties ['token' ]} " }
43+ signer_headers = {"Authorization" : f"Bearer { properties [TOKEN ]} " }
4044 signer_body = {
4145 "method" : request .method ,
4246 "region" : request .context ["client_region" ],
4347 "uri" : request .url ,
4448 "headers" : {key : [val ] for key , val in request .headers .items ()},
4549 }
50+
51+ response = requests .post (f"{ signer_url } /v1/aws/s3/sign" , headers = signer_headers , json = signer_body )
4652 try :
47- response = requests .post (f"{ signer_url } /v1/aws/s3/sign" , headers = signer_headers , json = signer_body )
4853 response .raise_for_status ()
4954 response_json = response .json ()
5055 except HTTPError as e :
You can’t perform that action at this time.
0 commit comments