-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[Storage Blob] Migrating to TypeSpec #45133
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
base: main
Are you sure you want to change the base?
Changes from all commits
ca88ac2
b9bb2c2
0375995
2343cab
04dd250
05c4ae7
b7244d0
45f2ae1
b766a06
d69a467
bb29e86
ae1d4b6
58d4b5e
bb4da34
b54cfb8
067d1df
df3bf8a
d79a511
418b716
8d50117
b916276
46a484b
87fd92c
1b6c906
293f043
74f076c
d47a25b
f1d5cd8
bbae834
1c59a77
2904d1f
9c07bf4
822f278
22aa47a
41db1f3
23e4046
48c0b21
21e9878
a1420e5
00c6454
cb2db2f
705573a
e20c51f
9828ac7
eb7b9ee
bcc8e74
2d261df
7254c3f
acd81a1
1f487b8
df5bf3b
fc646e4
0ce3070
596a3e4
cfb4e65
2868d95
cab86ee
9d53b1b
6fbf728
9b82899
d713734
8cdeae2
3a1d412
c2db1d8
df03e2d
5c4931d
17f8748
7842fdc
655b886
1ea2198
7dbf379
7212a3a
4951e36
89360e0
e9e269d
c1314d8
d15e572
8b98eec
885b510
fc6aaa6
f8d6d72
f30a855
952296b
09b4dbb
31b7d5e
e86f21b
57f819d
9c11698
8c7af8e
efdaca0
f722281
05dd529
f27ce09
70ab168
bfb043c
fe34a8b
4e7dbf6
6ba022a
a31b10c
b77219b
0e0d714
8efe172
4009ecb
93c7887
4016823
e5cf415
b7f27d4
7977103
f5f7bb2
0162981
8095223
c1d621e
71056ab
612aa01
62d3885
0162ac0
afb67b5
221e0e9
6239b32
1b1c716
6ace16b
0042c03
b915fee
e599ae2
dac4055
d3a1409
6bec206
8d63575
4c100ce
b910a2f
916aa62
9f35305
7a8bd37
1bb804e
a753dba
6003ac6
e36ef84
5160501
359fab5
7048e9a
30dc5ac
8bbb1ae
21f4482
ee781b7
ff48caa
09896ab
8e353a6
0783f61
5e53c7a
81c517d
ddfcbd3
0d9fec6
dd89844
90fd84c
67fd199
16be550
84d39fa
26eec5a
aa031af
828d7b3
42e21ec
9d4ad58
4c42b50
f80e124
d1179c1
d33d1df
856d81f
cd7c17c
5706a1e
bcca667
436e23f
0eef06f
e73ad47
b64ce60
3979658
9c2eedd
8c8e6b6
8a48590
cac55cd
1f51ecf
27c5a99
9841cc3
b56492e
06e9966
7fc2f1c
25d1f3b
6d82758
642ee4a
0d2d8c9
c9e70eb
2b626c6
2333f3e
f2979d4
432d31d
42244e2
dcc91a4
0c163f2
70aed14
67a7160
9137005
405b0d1
09fc6e9
1257acf
00b35bd
5772554
4d4432b
7b45ec2
5e8378d
48e729f
05c49e4
73dfd82
a9bad99
1ab95bd
a23e561
519dcb2
f50925e
6c8d01e
b7914e4
11a64b5
754066c
f0e090b
64c2023
fe07f0a
ecd6318
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| include *.md | ||
| include azure/__init__.py | ||
| include azure/storage/__init__.py | ||
| include LICENSE | ||
| include azure/storage/blob/py.typed | ||
| recursive-include tests *.py | ||
| recursive-include samples *.py *.md | ||
| include azure/storage/blob/py.typed | ||
| include azure/__init__.py | ||
| include azure/storage/__init__.py |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "apiVersion": "2026-06-06", | ||
| "apiVersions": { | ||
| "Storage.Blob": "2026-06-06" | ||
| } | ||
| } |
Large diffs are not rendered by default.
This file was deleted.
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -1,3 +1,4 @@ | ||||
| # pylint: disable=too-many-lines | ||||
| # ------------------------------------------------------------------------- | ||||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||||
| # Licensed under the MIT License. See License.txt in the project root for | ||||
|
|
@@ -33,6 +34,7 @@ | |||
| _get_page_ranges_options, | ||||
| _parse_url, | ||||
| _quick_query_options, | ||||
| _strip_snapshot_from_url, | ||||
| _resize_blob_options, | ||||
| _seal_append_blob_options, | ||||
| _set_blob_metadata_options, | ||||
|
|
@@ -56,15 +58,23 @@ | |||
| from ._download import StorageStreamDownloader | ||||
| from ._encryption import StorageEncryptionMixin, _ERROR_UNSUPPORTED_METHOD_FOR_ENCRYPTION | ||||
| from ._generated import AzureBlobStorage | ||||
| from ._generated.models import CpkInfo | ||||
| from ._lease import BlobLeaseClient | ||||
| from ._models import BlobBlock, BlobProperties, BlobQueryError, BlobType, PageRange, PageRangePaged | ||||
| from ._quick_query_helper import BlobQueryReader | ||||
| from ._shared.base_client import parse_connection_str, StorageAccountHostsMixin, TransportWrapper | ||||
| from ._shared.response_handlers import process_storage_error, return_response_headers | ||||
| from ._shared.validation import is_crc64_validation, parse_validation_option | ||||
| from ._serialize import get_access_conditions, get_api_version, get_modify_conditions, get_version_id | ||||
| from ._upload_helpers import upload_append_blob, upload_block_blob, upload_page_blob | ||||
| from ._serialize import ( | ||||
| get_access_conditions, | ||||
| get_api_version, | ||||
| get_modify_conditions, | ||||
| get_version_id | ||||
| ) | ||||
| from ._upload_helpers import ( | ||||
| upload_append_blob, | ||||
| upload_block_blob, | ||||
| upload_page_blob | ||||
| ) | ||||
|
|
||||
| if TYPE_CHECKING: | ||||
| from azure.core.credentials import AzureNamedKeyCredential, AzureSasCredential, TokenCredential | ||||
|
|
@@ -178,7 +188,11 @@ def __init__( | |||
| self._raw_credential = credential if credential else sas_token | ||||
| self._query_str, credential = self._format_query_string(sas_token, credential, snapshot=self.snapshot) | ||||
| super(BlobClient, self).__init__(parsed_url, service="blob", credential=credential, **kwargs) | ||||
| self._client = AzureBlobStorage(self.url, get_api_version(kwargs), base_url=self.url, pipeline=self._pipeline) | ||||
| # The generated client should not include snapshot in the base URL since | ||||
| # it is passed as a method parameter by operations that need it. | ||||
| self._client = AzureBlobStorage( | ||||
| _strip_snapshot_from_url(self.url), version=get_api_version(kwargs), pipeline=self._pipeline | ||||
| ) | ||||
| self._configure_encryption(kwargs) | ||||
|
|
||||
| def __enter__(self) -> Self: | ||||
|
|
@@ -612,7 +626,7 @@ def upload_blob( | |||
| raise ValueError("Encryption required but no key was provided.") | ||||
| if kwargs.get("cpk") and self.scheme.lower() != "https": | ||||
| raise ValueError("Customer provided encryption key must be used over HTTPS.") | ||||
| validate_content = parse_validation_option(kwargs.pop("validate_content", None)) | ||||
| validate_content = parse_validation_option(kwargs.pop('validate_content', None)) | ||||
| if is_crc64_validation(validate_content) and self.key_encryption_key: | ||||
| raise ValueError("Using encryption and content validation together is not currently supported.") | ||||
| options = _upload_blob_options( | ||||
|
|
@@ -753,12 +767,13 @@ def download_blob( | |||
| raise ValueError("Offset value must not be None if length is set.") | ||||
| if kwargs.get("cpk") and self.scheme.lower() != "https": | ||||
| raise ValueError("Customer provided encryption key must be used over HTTPS.") | ||||
| validate_content = parse_validation_option(kwargs.pop("validate_content", None)) | ||||
| validate_content = parse_validation_option(kwargs.pop('validate_content', None)) | ||||
| if is_crc64_validation(validate_content) and self.key_encryption_key: | ||||
| raise ValueError("Using encryption and content validation together is not currently supported.") | ||||
| options = _download_blob_options( | ||||
| blob_name=self.blob_name, | ||||
| container_name=self.container_name, | ||||
| snapshot=self.snapshot, | ||||
| version_id=get_version_id(self.version_id, kwargs), | ||||
| offset=offset, | ||||
| length=length, | ||||
|
|
@@ -863,7 +878,7 @@ def query_blob(self, query_expression: str, **kwargs: Any) -> BlobQueryReader: | |||
| raise ValueError("Customer provided encryption key must be used over HTTPS.") | ||||
| options, delimiter = _quick_query_options(self.snapshot, query_expression, **kwargs) | ||||
| try: | ||||
| headers, raw_response_body = self._client.blob.query(**options) | ||||
| headers, raw_response_body = self._client.block_blob.query(**options) | ||||
| except HttpResponseError as error: | ||||
| process_storage_error(error) | ||||
| return BlobQueryReader( | ||||
|
|
@@ -1106,13 +1121,13 @@ def get_blob_properties(self, **kwargs: Any) -> BlobProperties: | |||
| mod_conditions = get_modify_conditions(kwargs) | ||||
| version_id = get_version_id(self.version_id, kwargs) | ||||
| cpk = kwargs.pop("cpk", None) | ||||
| cpk_info = None | ||||
| cpk_kwargs = {} | ||||
| if cpk: | ||||
| if self.scheme.lower() != "https": | ||||
| raise ValueError("Customer provided encryption key must be used over HTTPS.") | ||||
| cpk_info = CpkInfo( | ||||
| encryption_key=cpk.key_value, encryption_key_sha256=cpk.key_hash, encryption_algorithm=cpk.algorithm | ||||
| ) | ||||
| cpk_kwargs["encryption_key"] = cpk.key_value | ||||
| cpk_kwargs["encryption_key_sha256"] = cpk.key_hash | ||||
| cpk_kwargs["encryption_algorithm"] = cpk.algorithm | ||||
| try: | ||||
| cls_method = kwargs.pop("cls", None) | ||||
| if cls_method: | ||||
|
|
@@ -1123,10 +1138,10 @@ def get_blob_properties(self, **kwargs: Any) -> BlobProperties: | |||
| timeout=kwargs.pop("timeout", None), | ||||
| version_id=version_id, | ||||
| snapshot=self.snapshot, | ||||
| lease_access_conditions=access_conditions, | ||||
| modified_access_conditions=mod_conditions, | ||||
| cls=kwargs.pop("cls", None) or deserialize_blob_properties, | ||||
| cpk_info=cpk_info, | ||||
| **access_conditions, | ||||
| **mod_conditions, | ||||
| **cpk_kwargs, | ||||
| **kwargs, | ||||
| ), | ||||
| ) | ||||
|
|
@@ -1284,11 +1299,16 @@ def set_immutability_policy(self, immutability_policy: "ImmutabilityPolicy", **k | |||
| """ | ||||
|
|
||||
| version_id = get_version_id(self.version_id, kwargs) | ||||
| kwargs["immutability_policy_expiry"] = immutability_policy.expiry_time | ||||
| kwargs["immutability_policy_mode"] = immutability_policy.policy_mode | ||||
| return cast( | ||||
| Dict[str, str], | ||||
| self._client.blob.set_immutability_policy(cls=return_response_headers, version_id=version_id, **kwargs), | ||||
| self._client.blob.set_immutability_policy( | ||||
| immutability_policy_expiry=immutability_policy.expiry_time, | ||||
| immutability_policy_mode=immutability_policy.policy_mode, | ||||
| cls=return_response_headers, | ||||
| version_id=version_id, | ||||
| snapshot=self.snapshot, | ||||
| **kwargs, | ||||
| ), | ||||
| ) | ||||
|
|
||||
| @distributed_trace | ||||
|
|
@@ -1312,7 +1332,7 @@ def delete_immutability_policy(self, **kwargs: Any) -> None: | |||
| """ | ||||
|
|
||||
| version_id = get_version_id(self.version_id, kwargs) | ||||
| self._client.blob.delete_immutability_policy(version_id=version_id, **kwargs) | ||||
| self._client.blob.delete_immutability_policy(version_id=version_id, snapshot=self.snapshot, **kwargs) | ||||
|
|
||||
| @distributed_trace | ||||
| def set_legal_hold(self, legal_hold: bool, **kwargs: Any) -> Dict[str, Union[str, datetime, bool]]: | ||||
|
|
@@ -1339,7 +1359,13 @@ def set_legal_hold(self, legal_hold: bool, **kwargs: Any) -> Dict[str, Union[str | |||
| version_id = get_version_id(self.version_id, kwargs) | ||||
| return cast( | ||||
| Dict[str, Union[str, datetime, bool]], | ||||
| self._client.blob.set_legal_hold(legal_hold, version_id=version_id, cls=return_response_headers, **kwargs), | ||||
| self._client.blob.set_legal_hold( | ||||
| legal_hold=legal_hold, | ||||
| version_id=version_id, | ||||
| snapshot=self.snapshot, | ||||
| cls=return_response_headers, | ||||
| **kwargs, | ||||
| ), | ||||
| ) | ||||
|
|
||||
| @distributed_trace | ||||
|
|
@@ -1971,9 +1997,9 @@ def set_standard_blob_tier(self, standard_blob_tier: Union[str, "StandardBlobTie | |||
| tier=standard_blob_tier, | ||||
| snapshot=self.snapshot, | ||||
| timeout=kwargs.pop("timeout", None), | ||||
| modified_access_conditions=mod_conditions, | ||||
| lease_access_conditions=access_conditions, | ||||
| version_id=version_id, | ||||
| if_tags=mod_conditions.get("if_tags"), | ||||
| **access_conditions, | ||||
| **kwargs, | ||||
| ) | ||||
| except HttpResponseError as error: | ||||
|
|
@@ -2154,8 +2180,8 @@ def get_block_list( | |||
| list_type=block_list_type, | ||||
| snapshot=self.snapshot, | ||||
| timeout=kwargs.pop("timeout", None), | ||||
| lease_access_conditions=access_conditions, | ||||
| modified_access_conditions=mod_conditions, | ||||
| if_tags=mod_conditions.get("if_tags"), | ||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if_tags is the only modification condition that applies here?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line 1817 in c6fc36e
|
||||
| **access_conditions, | ||||
| **kwargs, | ||||
| ) | ||||
| except HttpResponseError as error: | ||||
|
|
@@ -2309,8 +2335,9 @@ def set_premium_page_blob_tier(self, premium_page_blob_tier: "PremiumPageBlobTie | |||
| self._client.blob.set_tier( | ||||
| tier=premium_page_blob_tier, | ||||
| timeout=kwargs.pop("timeout", None), | ||||
| lease_access_conditions=access_conditions, | ||||
| modified_access_conditions=mod_conditions, | ||||
| snapshot=self.snapshot, | ||||
|
l0lawrence marked this conversation as resolved.
|
||||
| if_tags=mod_conditions.get("if_tags"), | ||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here as well.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yup just the tags |
||||
| **access_conditions, | ||||
| **kwargs, | ||||
| ) | ||||
| except HttpResponseError as error: | ||||
|
|
||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if_tags is the only modification condition that applies here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes set_tier only takes if_tags before we just passed in the rest as extra
azure-sdk-for-python/sdk/storage/azure-storage-blob/azure/storage/blob/_generated/operations/_blob_operations.py
Line 4152 in c6fc36e