Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mkdocs/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ For the FileIO there are several configuration options available:
| adls.dfs-storage-authority | .dfs.core.windows.net | The hostname[:port] of the Data Lake Gen 2 Service. Defaults to `.dfs.core.windows.net`. Useful for connecting to a local emulator, like [azurite](https://github.com/azure/azurite). See [AzureFileSystem](https://arrow.apache.org/docs/python/filesystems.html#azure-storage-file-system) for reference |
| adls.blob-storage-scheme | https | Either `http` or `https`. Defaults to `https`. Useful for connecting to a local emulator, like [azurite](https://github.com/azure/azurite). See [AzureFileSystem](https://arrow.apache.org/docs/python/filesystems.html#azure-storage-file-system) for reference |
| adls.dfs-storage-scheme | https | Either `http` or `https`. Defaults to `https`. Useful for connecting to a local emulator, like [azurite](https://github.com/azure/azurite). See [AzureFileSystem](https://arrow.apache.org/docs/python/filesystems.html#azure-storage-file-system) for reference |
| adls.token | eyJ0eXAiOiJKV1QiLCJhbGci... | Static access token for authenticating with ADLS. Used for OAuth2 flows. |

<!-- markdown-link-check-enable-->

Expand Down
1 change: 1 addition & 0 deletions pyiceberg/io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
ADLS_DFS_STORAGE_AUTHORITY = "adls.dfs-storage-authority"
ADLS_BLOB_STORAGE_SCHEME = "adls.blob-storage-scheme"
ADLS_DFS_STORAGE_SCHEME = "adls.dfs-storage-scheme"
ADLS_TOKEN = "adls.token"
GCS_TOKEN = "gcs.oauth2.token"
GCS_TOKEN_EXPIRES_AT_MS = "gcs.oauth2.token-expires-at"
GCS_PROJECT_ID = "gcs.project-id"
Expand Down
25 changes: 24 additions & 1 deletion pyiceberg/io/fsspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
ADLS_CREDENTIAL,
ADLS_SAS_TOKEN,
ADLS_TENANT_ID,
ADLS_TOKEN,
AWS_ACCESS_KEY_ID,
AWS_REGION,
AWS_SECRET_ACCESS_KEY,
Expand Down Expand Up @@ -192,7 +193,11 @@ def _gs(properties: Properties) -> AbstractFileSystem:


def _adls(properties: Properties) -> AbstractFileSystem:
# https://fsspec.github.io/adlfs/api/

from adlfs import AzureBlobFileSystem
from azure.core.credentials import AccessToken
from azure.core.credentials_async import AsyncTokenCredential

for key, sas_token in {
key.replace(f"{ADLS_SAS_TOKEN}.", ""): value for key, value in properties.items() if key.startswith(ADLS_SAS_TOKEN)
Expand All @@ -202,9 +207,27 @@ def _adls(properties: Properties) -> AbstractFileSystem:
if ADLS_SAS_TOKEN not in properties:
properties[ADLS_SAS_TOKEN] = sas_token

class StaticTokenCredential(AsyncTokenCredential):
_DEFAULT_EXPIRY_SECONDS = 3600

def __init__(self, token_string: str) -> None:
self._token = token_string

async def get_token(self, *scopes: str, **kwargs: Any) -> AccessToken:
import time

# Set expiration 1 hour from now
expires_on = int(time.time()) + self._DEFAULT_EXPIRY_SECONDS
return AccessToken(self._token, expires_on)

if token := properties.get(ADLS_TOKEN):
credential = StaticTokenCredential(token)
else:
credential = properties.get(ADLS_CREDENTIAL) # type: ignore

return AzureBlobFileSystem(
connection_string=properties.get(ADLS_CONNECTION_STRING),
credential=properties.get(ADLS_CREDENTIAL),
credential=credential,
account_name=properties.get(ADLS_ACCOUNT_NAME),
account_key=properties.get(ADLS_ACCOUNT_KEY),
sas_token=properties.get(ADLS_SAS_TOKEN),
Expand Down