Skip to content

Commit 0d1de4e

Browse files
committed
support adls.token
1 parent 640c592 commit 0d1de4e

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

pyiceberg/io/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
ADLS_DFS_STORAGE_AUTHORITY = "adls.dfs-storage-authority"
8787
ADLS_BLOB_STORAGE_SCHEME = "adls.blob-storage-scheme"
8888
ADLS_DFS_STORAGE_SCHEME = "adls.dfs-storage-scheme"
89+
ADLS_TOKEN = "adls.token"
8990
GCS_TOKEN = "gcs.oauth2.token"
9091
GCS_TOKEN_EXPIRES_AT_MS = "gcs.oauth2.token-expires-at"
9192
GCS_PROJECT_ID = "gcs.project-id"

pyiceberg/io/fsspec.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
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

194195
def _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

Comments
 (0)