Skip to content

Commit

Permalink
add AzureStorage support for fsspec
Browse files Browse the repository at this point in the history
  • Loading branch information
leo-schick committed Jun 27, 2023
1 parent 9135987 commit 88afd24
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion mara_storage/integrations/fsspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def filesystem(storage: Union[str, storages.Storage], **storage_options) -> Abst
Args:
db: the storage as alias or class
**kargs: additional arguments to be passed to the
**kargs: additional arguments to be passed to the
"""
raise NotImplementedError(f'Please implement filesystem for type "{storage.__class__.__name__}"')

Expand Down Expand Up @@ -50,6 +50,17 @@ def __(storage: storages.GoogleCloudStorage, **kargs):
**kargs)


@filesystem.register(storages.AzureStorage)
def __(storage: storages.AzureStorage, **kargs):
return fsspec.filesystem('adl' if storage.storage_type == 'dfs' else 'az',
account_name=kargs.pop('account_name', storage.account_name),
account_key=kargs.pop('account_key', storage.account_key),
sas_token=kargs.pop('sas_token', storage.sas),
tenant_id=kargs.pop('tenant_id', storage.spa_tenant),
client_id=kargs.pop('client_id', storage.spa_application),
client_secret=kargs.pop('client_secret', storage.spa_client_secret),
**kargs)


@singledispatch
def build_path(storage: Union[str, storages.Storage], path: str) -> str:
Expand Down Expand Up @@ -87,3 +98,8 @@ def __(storage: storages.GoogleCloudStorage, path: str):
@build_path.register(storages.SftpStorage)
def __(storage: storages.SftpStorage, path: str):
return path


@build_path.register(storages.AzureStorage)
def __(storage: storages.AzureStorage, path: str):
return f"{storage.container_name}/{path}"

0 comments on commit 88afd24

Please sign in to comment.