Skip to content
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

Azure backend : unable to determine account name for shared key credential #1082

Closed
pascalthivierge opened this issue Oct 21, 2021 · 3 comments · Fixed by #1083
Closed

Azure backend : unable to determine account name for shared key credential #1082

pascalthivierge opened this issue Oct 21, 2021 · 3 comments · Fixed by #1083

Comments

@pascalthivierge
Copy link

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 ?

@pascalthivierge
Copy link
Author

I was using version 1.12.2. It seems the fix for AZURE_CUSTOM_DOMAIN (1076) still doesn't behave like 1.11.

I just rolled back to version 1.11 and it works.

@dimbleby
Copy link
Contributor

dimbleby commented Oct 22, 2021

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:

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?

@raucodes
Copy link

Thx for me it is working, can we patch it for future releases?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants