-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PR #453 breaks the use of DefaultAzureCredential for a Azure Storage Account Gen2 #476
Comments
@pjbull it looks like this is because we make assumptions about the type of cloudpathlib/cloudpathlib/azure/azblobclient.py Lines 116 to 119 in 8207b3d
|
Yeah, I am remembering that this is an issue with the Azure SDK is architected. The credentials attached to the object end up wrapped in some service-specific object so you can't just pass Here's and example of the error we get when we run the live tests after trying to just pass cloudpathlib/azure/azblobclient.py:113: in __init__
self.data_lake_client = DataLakeServiceClient(
../../miniconda3/envs/cloudpathlib/lib/python3.11/site-packages/azure/storage/filedatalake/_data_lake_service_client.py:109: in __init__
super(DataLakeServiceClient, self).__init__(parsed_url, service='dfs',
../../miniconda3/envs/cloudpathlib/lib/python3.11/site-packages/azure/storage/filedatalake/_shared/base_client.py:108: in __init__
self._config, self._pipeline = self._create_pipeline(self.credential, sdk_moniker=self._sdk_moniker, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <azure.storage.filedatalake._data_lake_service_client.DataLakeServiceClient object at 0x10f1dce10>
credential = <azure.storage.blob._shared.authentication.SharedKeyCredentialPolicy object at 0x10f330a90>
kwargs = {'sdk_moniker': 'storage-dfs/12.16.0'}
def _create_pipeline(
self, credential: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, TokenCredential]] = None, # pylint: disable=line-too-long
**kwargs: Any
) -> Tuple[StorageConfiguration, Pipeline]:
self._credential_policy: Any = None
if hasattr(credential, "get_token"):
if kwargs.get('audience'):
audience = str(kwargs.pop('audience')).rstrip('/') + DEFAULT_OAUTH_SCOPE
else:
audience = STORAGE_OAUTH_SCOPE
self._credential_policy = StorageBearerTokenCredentialPolicy(cast(TokenCredential, credential), audience)
elif isinstance(credential, SharedKeyCredentialPolicy):
self._credential_policy = credential
elif isinstance(credential, AzureSasCredential):
self._credential_policy = AzureSasCredentialPolicy(credential)
elif credential is not None:
> raise TypeError(f"Unsupported credential: {type(credential)}")
E TypeError: Unsupported credential: <class 'azure.storage.blob._shared.authentication.SharedKeyCredentialPolicy'>
../../miniconda3/envs/cloudpathlib/lib/python3.11/site-packages/azure/storage/filedatalake/_shared/base_client.py:240: TypeError |
@johschmidt42 Could you try passing your account_url and credential straight to E.g., just remove the creation of the from azure.identity import DefaultAzureCredential
from cloudpathlib import AzureBlobClient
# Define your Azure Blob Storage details
account_url = "https://storage-account.blob.core.windows.net"
container_name = "az://container-name"
blob_name = "some/blob.txt"
# Initialize the DefaultAzureCredential
credential = DefaultAzureCredential()
# Create an AzureBlobClient
client = AzureBlobClient(account_url=account_url, credential=credential)
# Construct the full path to the blob
blob_path = f"{container_name}/{blob_name}"
# Use the client to read the blob
blob = client.CloudPath(blob_path)
if __name__ == "__main__":
# Read the content of the blob
with blob.open("r") as file:
content = file.read() |
Tried that. Getting this error: File "/Users/XXX/Library/Caches/pypoetry/virtualenvs/some-project/lib/python3.11/site-packages/cloudpathlib/cloudpath.py", line 655, in open
raise CloudPathIsADirectoryError(
cloudpathlib.exceptions.CloudPathIsADirectoryError: Cannot open directory, only files. Tried to open (az://container-name/some/blob.txt) |
Thank @johschmidt42 a few follow ups to help debug:
Thanks! |
Happy to help! @pjbull
0.19.0 (same code works with 0.18.1)
Yes
Actually, it is enabled.. sorry for the confusion. |
Repro'd this and debugged. Root cause is the same as #470 that Going to close this as a dupe and consolidate to #470 |
@johschmidt42 Just released v0.20.0 to PyPI. Please, take it for a spin and see if it fixes these issues for you! |
@pjbull Great! I just the tried the code again with v0.20.0 and it works! Thanks for quickly resolving the issue! |
With #453, in the
AzureBlobClient
class, an instance of theDataLakeServiceClient
class is created if ablob_service_client
is passed as a parameter. The Storage Account might not have a hierarchical namespace (datalake). I would expect that theAzureBlobClient
does not try to create an instance of theDataLakeServiceClient
class.The error:
The code:
Therefore, 0.19.0 becomes unusable to interact with blob data on a Azure Storage Account Gen2 without hierarchical namespace. 0.18.1 works just fine.
The text was updated successfully, but these errors were encountered: