Skip to content

Commit 76328e9

Browse files
[Storage] Fix batch APIs for Azurite (#36862)
1 parent 8a6980c commit 76328e9

File tree

7 files changed

+27
-2
lines changed

7 files changed

+27
-2
lines changed

sdk/storage/azure-storage-blob/azure/storage/blob/_container_client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,6 +1412,8 @@ def delete_blobs( # pylint: disable=delete-operation-wrong-return-type
14121412
"""
14131413
if len(blobs) == 0:
14141414
return iter([])
1415+
if self._is_localhost:
1416+
kwargs['url_prepend'] = self.account_name
14151417

14161418
reqs, options = _generate_delete_blobs_options(
14171419
self._query_str,
@@ -1494,6 +1496,8 @@ def set_standard_blob_tier_blobs(
14941496
:return: An iterator of responses, one for each blob in order
14951497
:rtype: Iterator[~azure.core.pipeline.transport.HttpResponse]
14961498
"""
1499+
if self._is_localhost:
1500+
kwargs['url_prepend'] = self.account_name
14971501
reqs, options = _generate_set_tiers_options(
14981502
self._query_str,
14991503
self.container_name,
@@ -1553,6 +1557,8 @@ def set_premium_page_blob_tier_blobs(
15531557
:return: An iterator of responses, one for each blob in order
15541558
:rtype: Iterator[~azure.core.pipeline.transport.HttpResponse]
15551559
"""
1560+
if self._is_localhost:
1561+
kwargs['url_prepend'] = self.account_name
15561562
reqs, options = _generate_set_tiers_options(
15571563
self._query_str,
15581564
self.container_name,

sdk/storage/azure-storage-blob/azure/storage/blob/_container_client_helpers.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ def _generate_delete_blobs_options(
120120
if_modified_since = kwargs.pop('if_modified_since', None)
121121
if_unmodified_since = kwargs.pop('if_unmodified_since', None)
122122
if_tags_match_condition = kwargs.pop('if_tags_match_condition', None)
123+
url_prepend = kwargs.pop('url_prepend', None)
123124
kwargs.update({'raise_on_any_failure': raise_on_any_failure,
124125
'sas': query_str.replace('?', '&'),
125126
'timeout': '&timeout=' + str(timeout) if timeout else "",
@@ -157,9 +158,11 @@ def _generate_delete_blobs_options(
157158

158159
req = HttpRequest(
159160
"DELETE",
160-
f"/{quote(container_name)}/{quote(str(blob_name), safe='/~')}{query_str}",
161+
(f"{'/' + quote(url_prepend) if url_prepend else ''}/"
162+
f"{quote(container_name)}/{quote(str(blob_name), safe='/~')}{query_str}"),
161163
headers=header_parameters
162164
)
165+
163166
req.format_parameters(query_parameters)
164167
reqs.append(req)
165168

@@ -223,6 +226,7 @@ def _generate_set_tiers_options(
223226
raise_on_any_failure = kwargs.pop('raise_on_any_failure', True)
224227
rehydrate_priority = kwargs.pop('rehydrate_priority', None)
225228
if_tags = kwargs.pop('if_tags_match_condition', None)
229+
url_prepend = kwargs.pop('url_prepend', None)
226230
kwargs.update({'raise_on_any_failure': raise_on_any_failure,
227231
'sas': query_str.replace('?', '&'),
228232
'timeout': '&timeout=' + str(timeout) if timeout else "",
@@ -252,7 +256,8 @@ def _generate_set_tiers_options(
252256

253257
req = HttpRequest(
254258
"PUT",
255-
f"/{quote(container_name)}/{quote(str(blob_name), safe='/~')}{query_str}",
259+
(f"{'/' + quote(url_prepend) if url_prepend else ''}/"
260+
f"{quote(container_name)}/{quote(str(blob_name), safe='/~')}{query_str}"),
256261
headers=header_parameters
257262
)
258263
req.format_parameters(query_parameters)

sdk/storage/azure-storage-blob/azure/storage/blob/_shared/base_client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ def __init__(
7676
self._location_mode = kwargs.get("_location_mode", LocationMode.PRIMARY)
7777
self._hosts = kwargs.get("_hosts")
7878
self.scheme = parsed_url.scheme
79+
self._is_localhost = False
7980

8081
if service not in ["blob", "queue", "file-share", "dfs"]:
8182
raise ValueError(f"Invalid service: {service}")
@@ -85,6 +86,7 @@ def __init__(
8586
self.account_name = account[0] if len(account) > 1 else None
8687
if not self.account_name and parsed_url.netloc.startswith("localhost") \
8788
or parsed_url.netloc.startswith("127.0.0.1"):
89+
self._is_localhost = True
8890
self.account_name = parsed_url.path.strip("/")
8991

9092
self.credential = _format_shared_key_credential(self.account_name, credential)

sdk/storage/azure-storage-blob/azure/storage/blob/aio/_container_client_async.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,6 +1406,8 @@ async def delete_blobs(
14061406
"""
14071407
if len(blobs) == 0:
14081408
return AsyncList([])
1409+
if self._is_localhost:
1410+
kwargs['url_prepend'] = self.account_name
14091411

14101412
reqs, options = _generate_delete_blobs_options(
14111413
self._query_str,
@@ -1485,6 +1487,8 @@ async def set_standard_blob_tier_blobs(
14851487
:return: An async iterator of responses, one for each blob in order
14861488
:rtype: asynciterator[~azure.core.pipeline.transport.AsyncHttpResponse]
14871489
"""
1490+
if self._is_localhost:
1491+
kwargs['url_prepend'] = self.account_name
14881492
reqs, options = _generate_set_tiers_options(
14891493
self._query_str,
14901494
self.container_name,
@@ -1544,6 +1548,8 @@ async def set_premium_page_blob_tier_blobs(
15441548
:return: An async iterator of responses, one for each blob in order
15451549
:rtype: asynciterator[~azure.core.pipeline.transport.AsyncHttpResponse]
15461550
"""
1551+
if self._is_localhost:
1552+
kwargs['url_prepend'] = self.account_name
15471553
reqs, options = _generate_set_tiers_options(
15481554
self._query_str,
15491555
self.container_name,

sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_shared/base_client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ def __init__(
7676
self._location_mode = kwargs.get("_location_mode", LocationMode.PRIMARY)
7777
self._hosts = kwargs.get("_hosts")
7878
self.scheme = parsed_url.scheme
79+
self._is_localhost = False
7980

8081
if service not in ["blob", "queue", "file-share", "dfs"]:
8182
raise ValueError(f"Invalid service: {service}")
@@ -85,6 +86,7 @@ def __init__(
8586
self.account_name = account[0] if len(account) > 1 else None
8687
if not self.account_name and parsed_url.netloc.startswith("localhost") \
8788
or parsed_url.netloc.startswith("127.0.0.1"):
89+
self._is_localhost = True
8890
self.account_name = parsed_url.path.strip("/")
8991

9092
self.credential = _format_shared_key_credential(self.account_name, credential)

sdk/storage/azure-storage-file-share/azure/storage/fileshare/_shared/base_client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ def __init__(
7676
self._location_mode = kwargs.get("_location_mode", LocationMode.PRIMARY)
7777
self._hosts = kwargs.get("_hosts")
7878
self.scheme = parsed_url.scheme
79+
self._is_localhost = False
7980

8081
if service not in ["blob", "queue", "file-share", "dfs"]:
8182
raise ValueError(f"Invalid service: {service}")
@@ -85,6 +86,7 @@ def __init__(
8586
self.account_name = account[0] if len(account) > 1 else None
8687
if not self.account_name and parsed_url.netloc.startswith("localhost") \
8788
or parsed_url.netloc.startswith("127.0.0.1"):
89+
self._is_localhost = True
8890
self.account_name = parsed_url.path.strip("/")
8991

9092
self.credential = _format_shared_key_credential(self.account_name, credential)

sdk/storage/azure-storage-queue/azure/storage/queue/_shared/base_client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ def __init__(
7676
self._location_mode = kwargs.get("_location_mode", LocationMode.PRIMARY)
7777
self._hosts = kwargs.get("_hosts")
7878
self.scheme = parsed_url.scheme
79+
self._is_localhost = False
7980

8081
if service not in ["blob", "queue", "file-share", "dfs"]:
8182
raise ValueError(f"Invalid service: {service}")
@@ -85,6 +86,7 @@ def __init__(
8586
self.account_name = account[0] if len(account) > 1 else None
8687
if not self.account_name and parsed_url.netloc.startswith("localhost") \
8788
or parsed_url.netloc.startswith("127.0.0.1"):
89+
self._is_localhost = True
8890
self.account_name = parsed_url.path.strip("/")
8991

9092
self.credential = _format_shared_key_credential(self.account_name, credential)

0 commit comments

Comments
 (0)