Skip to content

Commit 4e39756

Browse files
[Storage] [STG 95] Merge STG 95 into main branch (#36770)
1 parent 3e9ab9a commit 4e39756

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1466
-129
lines changed

sdk/storage/azure-storage-blob/CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
# Release History
22

3-
## 12.23.0b1 (Unreleased)
3+
## 12.23.0b1 (2024-08-07)
44

55
### Features Added
6+
- Added support for service version 2024-11-04.
67

8+
### Other Changes
9+
- Bumped minimum `azure-core` dependency to 1.30.0.
710

811
## 12.22.0 (2024-08-06)
912

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
'2023-11-03',
5757
'2024-05-04',
5858
'2024-08-04',
59+
'2024-11-04',
5960
]
6061

6162

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,17 @@ def __init__(self, account_name, account_key, x_ms_version=X_MS_VERSION):
107107
self.account_key = account_key
108108
self.x_ms_version = x_ms_version
109109

110-
def generate_account(self, services, resource_types, permission, expiry, start=None,
111-
ip=None, protocol=None, **kwargs) -> str:
110+
def generate_account(
111+
self, services,
112+
resource_types,
113+
permission,
114+
expiry,
115+
start=None,
116+
ip=None,
117+
protocol=None,
118+
sts_hook=None,
119+
**kwargs
120+
) -> str:
112121
'''
113122
Generates a shared access signature for the account.
114123
Use the returned signature with the sas_token parameter of the service
@@ -152,6 +161,10 @@ def generate_account(self, services, resource_types, permission, expiry, start=N
152161
:keyword str encryption_scope:
153162
Optional. If specified, this is the encryption scope to use when sending requests
154163
authorized with this SAS URI.
164+
:param sts_hook:
165+
For debugging purposes only. If provided, the hook is called with the string to sign
166+
that was used to generate the SAS.
167+
:type sts_hook: Optional[Callable[[str], None]]
155168
:returns: The generated SAS token for the account.
156169
:rtype: str
157170
'''
@@ -161,12 +174,16 @@ def generate_account(self, services, resource_types, permission, expiry, start=N
161174
sas.add_encryption_scope(**kwargs)
162175
sas.add_account_signature(self.account_name, self.account_key)
163176

177+
if sts_hook is not None:
178+
sts_hook(sas.string_to_sign)
179+
164180
return sas.get_token()
165181

166182

167183
class _SharedAccessHelper(object):
168184
def __init__(self):
169185
self.query_dict = {}
186+
self.string_to_sign = ""
170187

171188
def _add_query(self, name, val):
172189
if val:
@@ -229,6 +246,7 @@ def get_value_to_append(query):
229246

230247
self._add_query(QueryStringConstants.SIGNED_SIGNATURE,
231248
sign_string(account_key, string_to_sign))
249+
self.string_to_sign = string_to_sign
232250

233251
def get_token(self) -> str:
234252
return '&'.join([f'{n}={url_quote(v)}' for n, v in self.query_dict.items() if v is not None])

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

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
# --------------------------------------------------------------------------
66
# pylint: disable=docstring-keyword-should-match-keyword-only
77

8-
from typing import Union, Optional, Any, TYPE_CHECKING
8+
from typing import (
9+
Any, Callable, Optional, Union,
10+
TYPE_CHECKING
11+
)
912
from urllib.parse import parse_qs
1013

1114
from ._shared import sign_string, url_quote
@@ -64,6 +67,7 @@ def generate_blob(
6467
content_encoding: Optional[str] = None,
6568
content_language: Optional[str] = None,
6669
content_type: Optional[str] = None,
70+
sts_hook: Optional[Callable[[str], None]] = None,
6771
**kwargs: Any
6872
) -> str:
6973
'''
@@ -132,6 +136,10 @@ def generate_blob(
132136
:param str content_type:
133137
Response header value for Content-Type when resource is accessed
134138
using this shared access signature.
139+
:param sts_hook:
140+
For debugging purposes only. If provided, the hook is called with the string to sign
141+
that was used to generate the SAS.
142+
:type sts_hook: Optional[Callable[[str], None]]
135143
:return: A Shared Access Signature (sas) token.
136144
:rtype: str
137145
'''
@@ -155,6 +163,9 @@ def generate_blob(
155163
sas.add_resource_signature(self.account_name, self.account_key, resource_path,
156164
user_delegation_key=self.user_delegation_key)
157165

166+
if sts_hook is not None:
167+
sts_hook(sas.string_to_sign)
168+
158169
return sas.get_token()
159170

160171
def generate_container(
@@ -170,6 +181,7 @@ def generate_container(
170181
content_encoding: Optional[str] = None,
171182
content_language: Optional[str] = None,
172183
content_type: Optional[str] = None,
184+
sts_hook: Optional[Callable[[str], None]] = None,
173185
**kwargs: Any
174186
) -> str:
175187
'''
@@ -228,6 +240,10 @@ def generate_container(
228240
:param str content_type:
229241
Response header value for Content-Type when resource is accessed
230242
using this shared access signature.
243+
:param sts_hook:
244+
For debugging purposes only. If provided, the hook is called with the string to sign
245+
that was used to generate the SAS.
246+
:type sts_hook: Optional[Callable[[str], None]]
231247
:return: A Shared Access Signature (sas) token.
232248
:rtype: str
233249
'''
@@ -242,6 +258,10 @@ def generate_container(
242258
sas.add_info_for_hns_account(**kwargs)
243259
sas.add_resource_signature(self.account_name, self.account_key, container_name,
244260
user_delegation_key=self.user_delegation_key)
261+
262+
if sts_hook is not None:
263+
sts_hook(sas.string_to_sign)
264+
245265
return sas.get_token()
246266

247267

@@ -316,6 +336,7 @@ def add_resource_signature(self, account_name, account_key, path, user_delegatio
316336
self._add_query(QueryStringConstants.SIGNED_SIGNATURE,
317337
sign_string(account_key if user_delegation_key is None else user_delegation_key.value,
318338
string_to_sign))
339+
self.string_to_sign = string_to_sign
319340

320341
def get_token(self) -> str:
321342
# a conscious decision was made to exclude the timestamp in the generated token
@@ -335,6 +356,7 @@ def generate_account_sas(
335356
ip: Optional[str] = None,
336357
*,
337358
services: Union[Services, str] = Services(blob=True),
359+
sts_hook: Optional[Callable[[str], None]] = None,
338360
**kwargs: Any
339361
) -> str:
340362
"""Generates a shared access signature for the blob service.
@@ -376,6 +398,10 @@ def generate_account_sas(
376398
Specifies the protocol permitted for a request made. The default value is https.
377399
:keyword str encryption_scope:
378400
Specifies the encryption scope for a request made so that all write operations will be service encrypted.
401+
:keyword sts_hook:
402+
For debugging purposes only. If provided, the hook is called with the string to sign
403+
that was used to generate the SAS.
404+
:paramtype sts_hook: Optional[Callable[[str], None]]
379405
:return: A Shared Access Signature (sas) token.
380406
:rtype: str
381407
@@ -396,6 +422,7 @@ def generate_account_sas(
396422
expiry=expiry,
397423
start=start,
398424
ip=ip,
425+
sts_hook=sts_hook,
399426
**kwargs
400427
)
401428

@@ -410,6 +437,8 @@ def generate_container_sas(
410437
start: Optional[Union["datetime", str]] = None,
411438
policy_id: Optional[str] = None,
412439
ip: Optional[str] = None,
440+
*,
441+
sts_hook: Optional[Callable[[str], None]] = None,
413442
**kwargs: Any
414443
) -> str:
415444
"""Generates a shared access signature for a container.
@@ -483,6 +512,10 @@ def generate_container_sas(
483512
:keyword str correlation_id:
484513
The correlation id to correlate the storage audit logs with the audit logs used by the principal
485514
generating and distributing the SAS. This can only be used when generating a SAS with delegation key.
515+
:keyword sts_hook:
516+
For debugging purposes only. If provided, the hook is called with the string to sign
517+
that was used to generate the SAS.
518+
:paramtype sts_hook: Optional[Callable[[str], None]]
486519
:return: A Shared Access Signature (sas) token.
487520
:rtype: str
488521
@@ -515,6 +548,7 @@ def generate_container_sas(
515548
start=start,
516549
policy_id=policy_id,
517550
ip=ip,
551+
sts_hook=sts_hook,
518552
**kwargs
519553
)
520554

@@ -531,6 +565,8 @@ def generate_blob_sas(
531565
start: Optional[Union["datetime", str]] = None,
532566
policy_id: Optional[str] = None,
533567
ip: Optional[str] = None,
568+
*,
569+
sts_hook: Optional[Callable[[str], None]] = None,
534570
**kwargs: Any
535571
) -> str:
536572
"""Generates a shared access signature for a blob.
@@ -616,6 +652,10 @@ def generate_blob_sas(
616652
:keyword str correlation_id:
617653
The correlation id to correlate the storage audit logs with the audit logs used by the principal
618654
generating and distributing the SAS. This can only be used when generating a SAS with delegation key.
655+
:keyword sts_hook:
656+
For debugging purposes only. If provided, the hook is called with the string to sign
657+
that was used to generate the SAS.
658+
:paramtype sts_hook: Optional[Callable[[str], None]]
619659
:return: A Shared Access Signature (sas) token.
620660
:rtype: str
621661
"""
@@ -645,6 +685,7 @@ def generate_blob_sas(
645685
start=start,
646686
policy_id=policy_id,
647687
ip=ip,
688+
sts_hook=sts_hook,
648689
**kwargs
649690
)
650691

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,14 @@
7878
]),
7979
python_requires=">=3.8",
8080
install_requires=[
81-
"azure-core>=1.28.0",
81+
"azure-core>=1.30.0",
8282
"cryptography>=2.1.4",
8383
"typing-extensions>=4.6.0",
8484
"isodate>=0.6.1"
8585
],
8686
extras_require={
8787
"aio": [
88-
"azure-core[aio]>=1.28.0",
88+
"azure-core[aio]>=1.30.0",
8989
],
9090
},
9191
)

sdk/storage/azure-storage-file-datalake/CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
# Release History
22

3-
## 12.17.0b1 (Unreleased)
3+
## 12.17.0b1 (2024-08-07)
44

55
### Features Added
6+
- Added support for service version 2024-11-04.
67

8+
### Other Changes
9+
- Bumped minimum `azure-core` dependency to 1.30.0.
710

811
## 12.16.0 (2024-07-18)
912

sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_serialize.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
'2023-11-03',
3636
'2024-05-04',
3737
'2024-08-04',
38+
'2024-11-04',
3839
] # This list must be in chronological order!
3940

4041

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,17 @@ def __init__(self, account_name, account_key, x_ms_version=X_MS_VERSION):
107107
self.account_key = account_key
108108
self.x_ms_version = x_ms_version
109109

110-
def generate_account(self, services, resource_types, permission, expiry, start=None,
111-
ip=None, protocol=None, **kwargs) -> str:
110+
def generate_account(
111+
self, services,
112+
resource_types,
113+
permission,
114+
expiry,
115+
start=None,
116+
ip=None,
117+
protocol=None,
118+
sts_hook=None,
119+
**kwargs
120+
) -> str:
112121
'''
113122
Generates a shared access signature for the account.
114123
Use the returned signature with the sas_token parameter of the service
@@ -152,6 +161,10 @@ def generate_account(self, services, resource_types, permission, expiry, start=N
152161
:keyword str encryption_scope:
153162
Optional. If specified, this is the encryption scope to use when sending requests
154163
authorized with this SAS URI.
164+
:param sts_hook:
165+
For debugging purposes only. If provided, the hook is called with the string to sign
166+
that was used to generate the SAS.
167+
:type sts_hook: Optional[Callable[[str], None]]
155168
:returns: The generated SAS token for the account.
156169
:rtype: str
157170
'''
@@ -161,12 +174,16 @@ def generate_account(self, services, resource_types, permission, expiry, start=N
161174
sas.add_encryption_scope(**kwargs)
162175
sas.add_account_signature(self.account_name, self.account_key)
163176

177+
if sts_hook is not None:
178+
sts_hook(sas.string_to_sign)
179+
164180
return sas.get_token()
165181

166182

167183
class _SharedAccessHelper(object):
168184
def __init__(self):
169185
self.query_dict = {}
186+
self.string_to_sign = ""
170187

171188
def _add_query(self, name, val):
172189
if val:
@@ -229,6 +246,7 @@ def get_value_to_append(query):
229246

230247
self._add_query(QueryStringConstants.SIGNED_SIGNATURE,
231248
sign_string(account_key, string_to_sign))
249+
self.string_to_sign = string_to_sign
232250

233251
def get_token(self) -> str:
234252
return '&'.join([f'{n}={url_quote(v)}' for n, v in self.query_dict.items() if v is not None])

0 commit comments

Comments
 (0)