Repository: jschneier/django-storages

Issue:
Azure backend : unable to determine account name for shared key credential
Hi!

I'm trying to configure django-storages[azure] backend without success. In settings, I configured these variables:

```
DEFAULT_FILE_STORAGE = 'storages.backends.azure_storage.AzureStorage'

AZURE_ACCOUNT_NAME = 'myaccount'
AZURE_CUSTOM_DOMAIN = 'mycustomdomain.com'
AZURE_ACCOUNT_KEY = 'mykeylslkfjsdfkljsdkffsdjsfdjf;kfsd;ksdwithmissingcaracters=='
AZURE_CONTAINER = 'media'
AZURE_OVERWRITE_FILES = True
AZURE_URL_EXPIRATION_SECS = None

MEDIA_URL = f'https://{AZURE_CUSTOM_DOMAIN}/{AZURE_CONTAINER}/'
```

I get the following error 

```
... azure/storage/blob/_shared/base_client.py", line 351, in _format_shared_key_credential
    raise ValueError("Unable to determine account name for shared key credential.")
```
Not sure what happens. Am I missing something ?



Discussion:
I was using version 1.12.2. It seems the [fix for AZURE_CUSTOM_DOMAIN (1076)](https://github.com/jschneier/django-storages/pull/1076) still doesn't behave like 1.11.

I just rolled back to version 1.11 and it works.
Looks as though the SDK tries to infer the account name from the URL, which is not going to work for custom URLs.

But it looks as though you can provide it explicitly, I think this should do the trick:
```patch
diff --git a/storages/backends/azure_storage.py b/storages/backends/azure_storage.py
index 23509a5..f8e242a 100644
--- a/storages/backends/azure_storage.py
+++ b/storages/backends/azure_storage.py
@@ -158,7 +158,10 @@ class AzureStorage(BaseStorage):

         credential = None
         if self.account_key:
-            credential = self.account_key
+            credential = {
+                "account_name": self.account_name,
+                "account_key": self.account_key,
+            }
         elif self.sas_token:
             credential = self.sas_token
         elif self.token_credential:
```

Are you able to try that?
Thx for me it is working, can we patch it for future releases?

Resolving patch:
diff --git a/storages/backends/azure_storage.py b/storages/backends/azure_storage.py
--- a/storages/backends/azure_storage.py
+++ b/storages/backends/azure_storage.py
@@ -158,7 +158,10 @@ def _get_service_client(self):
 
         credential = None
         if self.account_key:
-            credential = self.account_key
+            credential = {
+                "account_name": self.account_name,
+                "account_key": self.account_key,
+            }
         elif self.sas_token:
             credential = self.sas_token
         elif self.token_credential:


Test patch:
diff --git a/tests/test_azure.py b/tests/test_azure.py
--- a/tests/test_azure.py
+++ b/tests/test_azure.py
@@ -232,7 +232,7 @@ def test_container_client_params_account_key(self):
             self.assertEqual(storage.client, client_mock)
             bsc_mocked.assert_called_once_with(
                 'https://foo_domain',
-                credential='foo_key')
+                credential={'account_name': 'foo_name', 'account_key': 'foo_key'})
 
     def test_container_client_params_sas_token(self):
         storage = azure_storage.AzureStorage()