Skip to content

Commit 5bcd14e

Browse files
committed
updated docs
1 parent 494ad54 commit 5bcd14e

File tree

2 files changed

+41
-21
lines changed

2 files changed

+41
-21
lines changed

src/maggma/stores/azure.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,15 @@
4141
]
4242

4343

44-
def _get_azure_credential(credential_class: str):
45-
"""Import the azure.identity module and return the credential class."""
46-
module_name = "azure.identity"
47-
credential_class = getattr(importlib.import_module(module_name), credential_class)
44+
def _get_azure_credential(credential_class):
45+
"""Import the azure.identity module and return the credential class.
46+
47+
If the credential_class is a class, return an instance of it.
48+
If the credential_class is a string, import the module first
49+
"""
50+
if isinstance(credential_class, str):
51+
module_name = "azure.identity"
52+
credential_class = getattr(importlib.import_module(module_name), credential_class)
4853
return credential_class()
4954

5055

@@ -86,7 +91,9 @@ def __init__(
8691
Currently supported keywords:
8792
- connection_string: a connection string for the Azure blob
8893
credential_type: the type of credential to use to authenticate with Azure.
89-
Default is "DefaultAzureCredential".
94+
Default is "DefaultAzureCredential". For serializable stores, provide
95+
a string representation of the credential class. Otherwises, you may
96+
provide the class itself.
9097
compress: compress files inserted into the store
9198
sub_dir: (optional) subdirectory of the container to store the data.
9299
When defined, a final "/" will be added if not already present.

tests/stores/test_azure.py

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -422,19 +422,32 @@ def test_no_login():
422422
store.connect()
423423

424424

425-
@pytest.mark.parametrize(
426-
"credential_type",
427-
[
428-
"DefaultAzureCredential",
429-
"AzureCliCredential",
430-
],
431-
)
432-
def test_credential_type_valid(credential_type):
433-
with azurite_container():
434-
index = MemoryStore("index")
435-
store = AzureBlobStore(
436-
index,
437-
AZURITE_CONTAINER_NAME,
438-
credential_type=credential_type,
439-
)
440-
store.connect()
425+
def test_credential_type_valid():
426+
credential_type = "DefaultAzureCredential"
427+
index = MemoryStore("index")
428+
store = AzureBlobStore(
429+
index,
430+
AZURITE_CONTAINER_NAME,
431+
credential_type=credential_type,
432+
)
433+
assert store.credential_type == credential_type
434+
435+
credential_type = "AzureCliCredential"
436+
index = MemoryStore("index")
437+
store = AzureBlobStore(
438+
index,
439+
AZURITE_CONTAINER_NAME,
440+
credential_type=credential_type,
441+
)
442+
assert store.credential_type == credential_type
443+
444+
from azure.identity import DefaultAzureCredential
445+
446+
credential_type = DefaultAzureCredential
447+
index = MemoryStore("index")
448+
store = AzureBlobStore(
449+
index,
450+
AZURITE_CONTAINER_NAME,
451+
credential_type=credential_type,
452+
)
453+
assert not isinstance(store.credential_type, str)

0 commit comments

Comments
 (0)