Skip to content

Storage clients should handle AzureNamedKeyCredential as credential #24836

Description

@bluenote10

Is your feature request related to a problem? Please describe.

The storage clients (blob, queue, ...) doesn't seem to support the type AzureNamedKeyCredential. This is inconsistent with many other parts of the API. For instance the table client allows it:

class AccountHostsMixin(object): # pylint: disable=too-many-instance-attributes
def __init__(
self,
account_url, # type: Any
credential=None, # type: Optional[Union[AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]]
**kwargs # type: Any
):

It is also frustrating that the credential is typed as Any.

This causes a lot of guessing what kind of credential the clients support 😕

Describe the solution you'd like

The signature should get proper type annotations, and this function should simply handle AzureNamedKeyCredential.

def _format_shared_key_credential(account_name, credential):
if isinstance(credential, six.string_types):
if not account_name:
raise ValueError("Unable to determine account name for shared key credential.")
credential = {"account_name": account_name, "account_key": credential}
if isinstance(credential, dict):
if "account_name" not in credential:
raise ValueError("Shared key credential missing 'account_name")
if "account_key" not in credential:
raise ValueError("Shared key credential missing 'account_key")
return SharedKeyCredentialPolicy(**credential)
return credential

Perhaps the private type SharedKeyCredentialPolicy should be even completely be replaced by AzureNamedKeyCredential.

Describe alternatives you've considered

Type guessing and constantly converting from and to AzureNamedKeyCredential and the plain {"account_name": str, "account_key": str} that the blob storage wants.

Metadata

Metadata

Labels

ClientThis issue points to a problem in the data-plane of the library.StorageStorage Service (Queues, Blobs, Files)customer-reportedIssues that are reported by GitHub users external to the Azure organization.feature-requestThis issue requires a new behavior in the product in order be resolved.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions