Skip to content

Commit

Permalink
[Tables] Add SAS to tables (#16717)
Browse files Browse the repository at this point in the history
  • Loading branch information
seankane-msft committed Mar 3, 2021
1 parent 66c78c2 commit 5b06b6e
Show file tree
Hide file tree
Showing 30 changed files with 54 additions and 2,956 deletions.
2 changes: 1 addition & 1 deletion sdk/tables/azure-data-tables/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Release History

## 12.0.0b5 (Unreleased)

* Adds SAS credential as an authentication option
* Bumped minimum requirement of msrest from `0.6.10` to `0.6.19`.
* Added support for datetime entities with milliseconds

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from urllib2 import quote # type: ignore

from azure.core.configuration import Configuration
from azure.core.credentials import AzureSasCredential
from azure.core.exceptions import ClientAuthenticationError, ResourceNotFoundError
from azure.core.pipeline import Pipeline
from azure.core.pipeline.transport import (
Expand All @@ -32,6 +33,7 @@
DistributedTracingPolicy,
HttpLoggingPolicy,
UserAgentPolicy,
AzureSasCredentialPolicy
)

from ._common_conversion import _to_utc_datetime
Expand Down Expand Up @@ -245,6 +247,9 @@ def _format_query_string(
query_str += "snapshot={}&".format(self.snapshot)
if share_snapshot:
query_str += "sharesnapshot={}&".format(self.snapshot)
if sas_token and isinstance(credential, AzureSasCredential):
raise ValueError(
"You cannot use AzureSasCredential when the resource URI also contains a Shared Access Signature.")
if sas_token and not credential:
query_str += sas_token
elif is_credential_sastoken(credential):
Expand All @@ -261,6 +266,8 @@ def _configure_credential(self, credential):
)
elif isinstance(credential, SharedKeyCredentialPolicy):
self._credential_policy = credential
elif isinstance(credential, AzureSasCredential):
self._credential_policy = AzureSasCredentialPolicy(credential)
elif credential is not None:
raise TypeError("Unsupported credential: {}".format(credential))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
List,
Type,
Tuple,
)
)


def url_quote(url):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@
from ._common_conversion import (
_sign_string,
_to_str,
_to_utc_datetime,
)
from ._constants import DEFAULT_X_MS_VERSION


def _to_utc_datetime(value):
# This is for SAS where milliseconds are not supported
return value.strftime("%Y-%m-%dT%H:%M:%SZ")


class SharedAccessSignature(object):
"""
Provides a factory for creating account access
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import logging
from uuid import uuid4

from azure.core.credentials import AzureSasCredential
from azure.core.exceptions import ResourceNotFoundError, ClientAuthenticationError
from azure.core.pipeline.policies import (
ContentDecodePolicy,
Expand All @@ -27,6 +28,7 @@
HttpLoggingPolicy,
UserAgentPolicy,
ProxyPolicy,
AzureSasCredentialPolicy
)
from azure.core.pipeline.transport import (
AsyncHttpTransport,
Expand Down Expand Up @@ -86,6 +88,8 @@ def _configure_credential(self, credential):
)
elif isinstance(credential, SharedKeyCredentialPolicy):
self._credential_policy = credential
elif isinstance(credential, AzureSasCredential):
self._credential_policy = AzureSasCredentialPolicy(credential)
elif credential is not None:
raise TypeError("Unsupported credential: {}".format(credential))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ interactions:
DataServiceVersion:
- '3.0'
Date:
- Fri, 18 Dec 2020 17:28:36 GMT
- Thu, 11 Feb 2021 20:51:40 GMT
User-Agent:
- azsdk-python-data-tables/12.0.0b4 Python/3.9.0rc1 (Windows-10-10.0.19041-SP0)
- azsdk-python-data-tables/12.0.0b5 Python/3.9.0rc1 (Windows-10-10.0.19041-SP0)
x-ms-date:
- Fri, 18 Dec 2020 17:28:36 GMT
- Thu, 11 Feb 2021 20:51:40 GMT
x-ms-version:
- '2019-02-02'
method: POST
Expand All @@ -33,7 +33,7 @@ interactions:
content-type:
- application/json;odata=minimalmetadata;streaming=true;charset=utf-8
date:
- Fri, 18 Dec 2020 17:28:37 GMT
- Thu, 11 Feb 2021 20:51:46 GMT
location:
- https://fake_table_account.table.core.windows.net/Tables('pytablesync99dc0b08')
server:
Expand Down Expand Up @@ -65,11 +65,11 @@ interactions:
DataServiceVersion:
- '3.0'
Date:
- Fri, 18 Dec 2020 17:28:37 GMT
- Thu, 11 Feb 2021 20:51:47 GMT
User-Agent:
- azsdk-python-data-tables/12.0.0b4 Python/3.9.0rc1 (Windows-10-10.0.19041-SP0)
- azsdk-python-data-tables/12.0.0b5 Python/3.9.0rc1 (Windows-10-10.0.19041-SP0)
x-ms-date:
- Fri, 18 Dec 2020 17:28:37 GMT
- Thu, 11 Feb 2021 20:51:47 GMT
x-ms-version:
- '2019-02-02'
method: PATCH
Expand All @@ -83,9 +83,9 @@ interactions:
content-length:
- '0'
date:
- Fri, 18 Dec 2020 17:28:37 GMT
- Thu, 11 Feb 2021 20:51:46 GMT
etag:
- W/"datetime'2020-12-18T17%3A28%3A37.7170314Z'"
- W/"datetime'2021-02-11T20%3A51%3A47.3343151Z'"
server:
- Windows-Azure-Table/1.0 Microsoft-HTTPAPI/2.0
x-content-type-options:
Expand Down Expand Up @@ -113,11 +113,11 @@ interactions:
DataServiceVersion:
- '3.0'
Date:
- Fri, 18 Dec 2020 17:28:37 GMT
- Thu, 11 Feb 2021 20:51:47 GMT
User-Agent:
- azsdk-python-data-tables/12.0.0b4 Python/3.9.0rc1 (Windows-10-10.0.19041-SP0)
- azsdk-python-data-tables/12.0.0b5 Python/3.9.0rc1 (Windows-10-10.0.19041-SP0)
x-ms-date:
- Fri, 18 Dec 2020 17:28:37 GMT
- Thu, 11 Feb 2021 20:51:47 GMT
x-ms-version:
- '2019-02-02'
method: PATCH
Expand All @@ -131,9 +131,9 @@ interactions:
content-length:
- '0'
date:
- Fri, 18 Dec 2020 17:28:37 GMT
- Thu, 11 Feb 2021 20:51:47 GMT
etag:
- W/"datetime'2020-12-18T17%3A28%3A37.8581334Z'"
- W/"datetime'2021-02-11T20%3A51%3A47.4674095Z'"
server:
- Windows-Azure-Table/1.0 Microsoft-HTTPAPI/2.0
x-content-type-options:
Expand All @@ -155,25 +155,25 @@ interactions:
DataServiceVersion:
- '3.0'
Date:
- Fri, 18 Dec 2020 17:28:37 GMT
- Thu, 11 Feb 2021 20:52:42 GMT
User-Agent:
- azsdk-python-data-tables/12.0.0b4 Python/3.9.0rc1 (Windows-10-10.0.19041-SP0)
- azsdk-python-data-tables/12.0.0b5 Python/3.9.0rc1 (Windows-10-10.0.19041-SP0)
x-ms-date:
- Fri, 18 Dec 2020 17:28:37 GMT
- Thu, 11 Feb 2021 20:52:42 GMT
x-ms-version:
- '2019-02-02'
method: GET
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
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
response:
body:
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"}]}'
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"}]}'
headers:
cache-control:
- no-cache
content-type:
- application/json;odata=minimalmetadata;streaming=true;charset=utf-8
date:
- Fri, 18 Dec 2020 17:28:37 GMT
- Thu, 11 Feb 2021 20:52:42 GMT
server:
- Windows-Azure-Table/1.0 Microsoft-HTTPAPI/2.0
transfer-encoding:
Expand All @@ -197,11 +197,11 @@ interactions:
Content-Length:
- '0'
Date:
- Fri, 18 Dec 2020 17:28:38 GMT
- Thu, 11 Feb 2021 20:52:43 GMT
User-Agent:
- azsdk-python-data-tables/12.0.0b4 Python/3.9.0rc1 (Windows-10-10.0.19041-SP0)
- azsdk-python-data-tables/12.0.0b5 Python/3.9.0rc1 (Windows-10-10.0.19041-SP0)
x-ms-date:
- Fri, 18 Dec 2020 17:28:38 GMT
- Thu, 11 Feb 2021 20:52:43 GMT
x-ms-version:
- '2019-02-02'
method: DELETE
Expand All @@ -215,7 +215,7 @@ interactions:
content-length:
- '0'
date:
- Fri, 18 Dec 2020 17:28:38 GMT
- Thu, 11 Feb 2021 20:52:43 GMT
server:
- Windows-Azure-Table/1.0 Microsoft-HTTPAPI/2.0
x-content-type-options:
Expand Down
Loading

0 comments on commit 5b06b6e

Please sign in to comment.