Skip to content

Commit 5b06b6e

Browse files
[Tables] Add SAS to tables (#16717)
#16610
1 parent 66c78c2 commit 5b06b6e

30 files changed

+54
-2956
lines changed

sdk/tables/azure-data-tables/CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Release History
22

33
## 12.0.0b5 (Unreleased)
4-
4+
* Adds SAS credential as an authentication option
55
* Bumped minimum requirement of msrest from `0.6.10` to `0.6.19`.
66
* Added support for datetime entities with milliseconds
77

sdk/tables/azure-data-tables/azure/data/tables/_base_client.py

+7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from urllib2 import quote # type: ignore
1919

2020
from azure.core.configuration import Configuration
21+
from azure.core.credentials import AzureSasCredential
2122
from azure.core.exceptions import ClientAuthenticationError, ResourceNotFoundError
2223
from azure.core.pipeline import Pipeline
2324
from azure.core.pipeline.transport import (
@@ -32,6 +33,7 @@
3233
DistributedTracingPolicy,
3334
HttpLoggingPolicy,
3435
UserAgentPolicy,
36+
AzureSasCredentialPolicy
3537
)
3638

3739
from ._common_conversion import _to_utc_datetime
@@ -245,6 +247,9 @@ def _format_query_string(
245247
query_str += "snapshot={}&".format(self.snapshot)
246248
if share_snapshot:
247249
query_str += "sharesnapshot={}&".format(self.snapshot)
250+
if sas_token and isinstance(credential, AzureSasCredential):
251+
raise ValueError(
252+
"You cannot use AzureSasCredential when the resource URI also contains a Shared Access Signature.")
248253
if sas_token and not credential:
249254
query_str += sas_token
250255
elif is_credential_sastoken(credential):
@@ -261,6 +266,8 @@ def _configure_credential(self, credential):
261266
)
262267
elif isinstance(credential, SharedKeyCredentialPolicy):
263268
self._credential_policy = credential
269+
elif isinstance(credential, AzureSasCredential):
270+
self._credential_policy = AzureSasCredentialPolicy(credential)
264271
elif credential is not None:
265272
raise TypeError("Unsupported credential: {}".format(credential))
266273

sdk/tables/azure-data-tables/azure/data/tables/_deserialize.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
List,
3838
Type,
3939
Tuple,
40-
)
40+
)
4141

4242

4343
def url_quote(url):

sdk/tables/azure-data-tables/azure/data/tables/_shared_access_signature.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@
1111
from ._common_conversion import (
1212
_sign_string,
1313
_to_str,
14-
_to_utc_datetime,
1514
)
1615
from ._constants import DEFAULT_X_MS_VERSION
1716

1817

18+
def _to_utc_datetime(value):
19+
# This is for SAS where milliseconds are not supported
20+
return value.strftime("%Y-%m-%dT%H:%M:%SZ")
21+
22+
1923
class SharedAccessSignature(object):
2024
"""
2125
Provides a factory for creating account access

sdk/tables/azure-data-tables/azure/data/tables/aio/_base_client_async.py

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import logging
1919
from uuid import uuid4
2020

21+
from azure.core.credentials import AzureSasCredential
2122
from azure.core.exceptions import ResourceNotFoundError, ClientAuthenticationError
2223
from azure.core.pipeline.policies import (
2324
ContentDecodePolicy,
@@ -27,6 +28,7 @@
2728
HttpLoggingPolicy,
2829
UserAgentPolicy,
2930
ProxyPolicy,
31+
AzureSasCredentialPolicy
3032
)
3133
from azure.core.pipeline.transport import (
3234
AsyncHttpTransport,
@@ -86,6 +88,8 @@ def _configure_credential(self, credential):
8688
)
8789
elif isinstance(credential, SharedKeyCredentialPolicy):
8890
self._credential_policy = credential
91+
elif isinstance(credential, AzureSasCredential):
92+
self._credential_policy = AzureSasCredentialPolicy(credential)
8993
elif credential is not None:
9094
raise TypeError("Unsupported credential: {}".format(credential))
9195

sdk/tables/azure-data-tables/tests/recordings/test_table.test_account_sas.yaml

+24-24
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ interactions:
1515
DataServiceVersion:
1616
- '3.0'
1717
Date:
18-
- Fri, 18 Dec 2020 17:28:36 GMT
18+
- Thu, 11 Feb 2021 20:51:40 GMT
1919
User-Agent:
20-
- azsdk-python-data-tables/12.0.0b4 Python/3.9.0rc1 (Windows-10-10.0.19041-SP0)
20+
- azsdk-python-data-tables/12.0.0b5 Python/3.9.0rc1 (Windows-10-10.0.19041-SP0)
2121
x-ms-date:
22-
- Fri, 18 Dec 2020 17:28:36 GMT
22+
- Thu, 11 Feb 2021 20:51:40 GMT
2323
x-ms-version:
2424
- '2019-02-02'
2525
method: POST
@@ -33,7 +33,7 @@ interactions:
3333
content-type:
3434
- application/json;odata=minimalmetadata;streaming=true;charset=utf-8
3535
date:
36-
- Fri, 18 Dec 2020 17:28:37 GMT
36+
- Thu, 11 Feb 2021 20:51:46 GMT
3737
location:
3838
- https://fake_table_account.table.core.windows.net/Tables('pytablesync99dc0b08')
3939
server:
@@ -65,11 +65,11 @@ interactions:
6565
DataServiceVersion:
6666
- '3.0'
6767
Date:
68-
- Fri, 18 Dec 2020 17:28:37 GMT
68+
- Thu, 11 Feb 2021 20:51:47 GMT
6969
User-Agent:
70-
- azsdk-python-data-tables/12.0.0b4 Python/3.9.0rc1 (Windows-10-10.0.19041-SP0)
70+
- azsdk-python-data-tables/12.0.0b5 Python/3.9.0rc1 (Windows-10-10.0.19041-SP0)
7171
x-ms-date:
72-
- Fri, 18 Dec 2020 17:28:37 GMT
72+
- Thu, 11 Feb 2021 20:51:47 GMT
7373
x-ms-version:
7474
- '2019-02-02'
7575
method: PATCH
@@ -83,9 +83,9 @@ interactions:
8383
content-length:
8484
- '0'
8585
date:
86-
- Fri, 18 Dec 2020 17:28:37 GMT
86+
- Thu, 11 Feb 2021 20:51:46 GMT
8787
etag:
88-
- W/"datetime'2020-12-18T17%3A28%3A37.7170314Z'"
88+
- W/"datetime'2021-02-11T20%3A51%3A47.3343151Z'"
8989
server:
9090
- Windows-Azure-Table/1.0 Microsoft-HTTPAPI/2.0
9191
x-content-type-options:
@@ -113,11 +113,11 @@ interactions:
113113
DataServiceVersion:
114114
- '3.0'
115115
Date:
116-
- Fri, 18 Dec 2020 17:28:37 GMT
116+
- Thu, 11 Feb 2021 20:51:47 GMT
117117
User-Agent:
118-
- azsdk-python-data-tables/12.0.0b4 Python/3.9.0rc1 (Windows-10-10.0.19041-SP0)
118+
- azsdk-python-data-tables/12.0.0b5 Python/3.9.0rc1 (Windows-10-10.0.19041-SP0)
119119
x-ms-date:
120-
- Fri, 18 Dec 2020 17:28:37 GMT
120+
- Thu, 11 Feb 2021 20:51:47 GMT
121121
x-ms-version:
122122
- '2019-02-02'
123123
method: PATCH
@@ -131,9 +131,9 @@ interactions:
131131
content-length:
132132
- '0'
133133
date:
134-
- Fri, 18 Dec 2020 17:28:37 GMT
134+
- Thu, 11 Feb 2021 20:51:47 GMT
135135
etag:
136-
- W/"datetime'2020-12-18T17%3A28%3A37.8581334Z'"
136+
- W/"datetime'2021-02-11T20%3A51%3A47.4674095Z'"
137137
server:
138138
- Windows-Azure-Table/1.0 Microsoft-HTTPAPI/2.0
139139
x-content-type-options:
@@ -155,25 +155,25 @@ interactions:
155155
DataServiceVersion:
156156
- '3.0'
157157
Date:
158-
- Fri, 18 Dec 2020 17:28:37 GMT
158+
- Thu, 11 Feb 2021 20:52:42 GMT
159159
User-Agent:
160-
- azsdk-python-data-tables/12.0.0b4 Python/3.9.0rc1 (Windows-10-10.0.19041-SP0)
160+
- azsdk-python-data-tables/12.0.0b5 Python/3.9.0rc1 (Windows-10-10.0.19041-SP0)
161161
x-ms-date:
162-
- Fri, 18 Dec 2020 17:28:37 GMT
162+
- Thu, 11 Feb 2021 20:52:42 GMT
163163
x-ms-version:
164164
- '2019-02-02'
165165
method: GET
166-
uri: https://fake_table_account.table.core.windows.net/pytablesync99dc0b08()?st=2020-12-18T17%3A27%3A37Z&se=2020-12-18T18%3A28%3A37Z&sp=r&sv=2019-02-02&ss=t&srt=o&sig=549isvlvwOzIBJDkCaGWoDm91RaODe%2FdgTtIB55df28%3D
166+
uri: https://fake_table_account.table.core.windows.net/pytablesync99dc0b08()?st=2021-02-11T20%3A50%3A47Z&se=2021-02-11T21%3A51%3A47Z&sp=r&sv=2019-02-02&ss=t&srt=o&sig=J3HV5BKdOK0BuEAQ9BIlFe1EjIIA8gveOkl2WzsvfhY%3D
167167
response:
168168
body:
169-
string: '{"odata.metadata":"https://fake_table_account.table.core.windows.net/$metadata#pytablesync99dc0b08","value":[{"odata.etag":"W/\"datetime''2020-12-18T17%3A28%3A37.7170314Z''\"","PartitionKey":"test","RowKey":"test1","Timestamp":"2020-12-18T17:28:37.7170314Z","text":"hello"},{"odata.etag":"W/\"datetime''2020-12-18T17%3A28%3A37.8581334Z''\"","PartitionKey":"test","RowKey":"test2","Timestamp":"2020-12-18T17:28:37.8581334Z","text":"hello"}]}'
169+
string: '{"odata.metadata":"https://fake_table_account.table.core.windows.net/$metadata#pytablesync99dc0b08","value":[{"odata.etag":"W/\"datetime''2021-02-11T20%3A51%3A47.3343151Z''\"","PartitionKey":"test","RowKey":"test1","Timestamp":"2021-02-11T20:51:47.3343151Z","text":"hello"},{"odata.etag":"W/\"datetime''2021-02-11T20%3A51%3A47.4674095Z''\"","PartitionKey":"test","RowKey":"test2","Timestamp":"2021-02-11T20:51:47.4674095Z","text":"hello"}]}'
170170
headers:
171171
cache-control:
172172
- no-cache
173173
content-type:
174174
- application/json;odata=minimalmetadata;streaming=true;charset=utf-8
175175
date:
176-
- Fri, 18 Dec 2020 17:28:37 GMT
176+
- Thu, 11 Feb 2021 20:52:42 GMT
177177
server:
178178
- Windows-Azure-Table/1.0 Microsoft-HTTPAPI/2.0
179179
transfer-encoding:
@@ -197,11 +197,11 @@ interactions:
197197
Content-Length:
198198
- '0'
199199
Date:
200-
- Fri, 18 Dec 2020 17:28:38 GMT
200+
- Thu, 11 Feb 2021 20:52:43 GMT
201201
User-Agent:
202-
- azsdk-python-data-tables/12.0.0b4 Python/3.9.0rc1 (Windows-10-10.0.19041-SP0)
202+
- azsdk-python-data-tables/12.0.0b5 Python/3.9.0rc1 (Windows-10-10.0.19041-SP0)
203203
x-ms-date:
204-
- Fri, 18 Dec 2020 17:28:38 GMT
204+
- Thu, 11 Feb 2021 20:52:43 GMT
205205
x-ms-version:
206206
- '2019-02-02'
207207
method: DELETE
@@ -215,7 +215,7 @@ interactions:
215215
content-length:
216216
- '0'
217217
date:
218-
- Fri, 18 Dec 2020 17:28:38 GMT
218+
- Thu, 11 Feb 2021 20:52:43 GMT
219219
server:
220220
- Windows-Azure-Table/1.0 Microsoft-HTTPAPI/2.0
221221
x-content-type-options:

0 commit comments

Comments
 (0)