4848 ADLS_CREDENTIAL ,
4949 ADLS_SAS_TOKEN ,
5050 ADLS_TENANT_ID ,
51+ ADLS_TOKEN ,
5152 AWS_ACCESS_KEY_ID ,
5253 AWS_REGION ,
5354 AWS_SECRET_ACCESS_KEY ,
@@ -192,7 +193,11 @@ def _gs(properties: Properties) -> AbstractFileSystem:
192193
193194
194195def _adls (properties : Properties ) -> AbstractFileSystem :
196+ import time
197+
195198 from adlfs import AzureBlobFileSystem
199+ from azure .core .credentials import AccessToken
200+ from azure .core .credentials_async import AsyncTokenCredential
196201
197202 for key , sas_token in {
198203 key .replace (f"{ ADLS_SAS_TOKEN } ." , "" ): value for key , value in properties .items () if key .startswith (ADLS_SAS_TOKEN )
@@ -202,9 +207,29 @@ def _adls(properties: Properties) -> AbstractFileSystem:
202207 if ADLS_SAS_TOKEN not in properties :
203208 properties [ADLS_SAS_TOKEN ] = sas_token
204209
210+ class StaticTokenCredential (AsyncTokenCredential ):
211+ def __init__ (self , token_string : str ) -> None :
212+ self ._token = token_string
213+ # If no expiry provided, set 1 hour from now
214+ self ._expires_on = int (time .time ()) + 3600
215+
216+ async def get_token (self , * scopes : str , ** kwargs : Any ) -> AccessToken :
217+ return AccessToken (self ._token , self ._expires_on )
218+
219+ if ADLS_TOKEN in properties :
220+ token = properties .get (ADLS_TOKEN )
221+ if token is not None :
222+ credential = StaticTokenCredential (token )
223+ else :
224+ credential = None
225+ elif ADLS_CREDENTIAL in properties :
226+ credential = properties .get (ADLS_CREDENTIAL )
227+ else :
228+ credential = None
229+
205230 return AzureBlobFileSystem (
206231 connection_string = properties .get (ADLS_CONNECTION_STRING ),
207- credential = properties . get ( ADLS_CREDENTIAL ) ,
232+ credential = credential ,
208233 account_name = properties .get (ADLS_ACCOUNT_NAME ),
209234 account_key = properties .get (ADLS_ACCOUNT_KEY ),
210235 sas_token = properties .get (ADLS_SAS_TOKEN ),
0 commit comments