|
28 | 28 | import logging
|
29 | 29 | import os
|
30 | 30 | from typing import Any, Union
|
| 31 | +from urllib.parse import urlparse |
31 | 32 |
|
32 | 33 | from asgiref.sync import sync_to_async
|
33 | 34 | from azure.core.exceptions import HttpResponseError, ResourceExistsError, ResourceNotFoundError
|
@@ -152,11 +153,13 @@ def get_conn(self) -> BlobServiceClient:
|
152 | 153 | # connection_string auth takes priority
|
153 | 154 | return BlobServiceClient.from_connection_string(connection_string, **extra)
|
154 | 155 |
|
155 |
| - account_url = ( |
156 |
| - conn.host |
157 |
| - if conn.host and conn.host.startswith("https://") |
158 |
| - else f"https://{conn.login}.blob.core.windows.net/" |
159 |
| - ) |
| 156 | + account_url = conn.host if conn.host else f"https://{conn.login}.blob.core.windows.net/" |
| 157 | + parsed_url = urlparse(account_url) |
| 158 | + |
| 159 | + if not parsed_url.netloc and "." not in parsed_url.path: |
| 160 | + # if there's no netloc and no dots in the path, then user only |
| 161 | + # provided the host ID, not the full URL or DNS name |
| 162 | + account_url = f"https://{conn.login}.blob.core.windows.net/" |
160 | 163 |
|
161 | 164 | tenant = self._get_field(extra, "tenant_id")
|
162 | 165 | if tenant:
|
@@ -555,11 +558,13 @@ async def get_async_conn(self) -> AsyncBlobServiceClient:
|
555 | 558 | )
|
556 | 559 | return self.blob_service_client
|
557 | 560 |
|
558 |
| - account_url = ( |
559 |
| - conn.host |
560 |
| - if conn.host and conn.host.startswith("https://") |
561 |
| - else f"https://{conn.login}.blob.core.windows.net/" |
562 |
| - ) |
| 561 | + account_url = conn.host if conn.host else f"https://{conn.login}.blob.core.windows.net/" |
| 562 | + parsed_url = urlparse(account_url) |
| 563 | + |
| 564 | + if not parsed_url.netloc and "." not in parsed_url.path: |
| 565 | + # if there's no netloc and no dots in the path, then user only |
| 566 | + # provided the host ID, not the full URL or DNS name |
| 567 | + account_url = f"https://{conn.login}.blob.core.windows.net/" |
563 | 568 |
|
564 | 569 | tenant = self._get_field(extra, "tenant_id")
|
565 | 570 | if tenant:
|
|
0 commit comments