Skip to content

Commit 8de385c

Browse files
Merge pull request #3 from LibbaLawrence/creating_client_for_pipeline
Creating client for pipeline
2 parents 025ee58 + 4a0bdd4 commit 8de385c

Some content is hidden

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

55 files changed

+964
-448
lines changed
File renamed without changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
__all__ = [
2+
'generate_account_sas',
3+
]
4+
5+
from azure.table import generate_account_sas
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# coding=utf-8
2+
# --------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
# Licensed under the MIT License. See License.txt in the project root for
5+
# license information.
6+
#
7+
# Code generated by Microsoft (R) AutoRest Code Generator.
8+
# Changes may cause incorrect behavior and will be lost if the code is
9+
# regenerated.
10+
# --------------------------------------------------------------------------
11+
12+
VERSION = "2019-07-07"
13+

sdk/Table/azure/storage/tables/_shared/_common_conversion.py renamed to sdk/Table/azure/azure_table/_shared/_common_conversion.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from io import (SEEK_SET)
1212

1313
from dateutil.tz import tzutc
14+
from pyparsing import unicode
1415

1516
from ._error import (
1617
_ERROR_VALUE_SHOULD_BE_BYTES_OR_STREAM,
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# -------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for
4+
# license information.
5+
# --------------------------------------------------------------------------
6+
import platform
7+
import sys
8+
9+
__author__ = 'Microsoft Corp. <[email protected]>'
10+
__version__ = '1.4.2'
11+
12+
# UserAgent string sample: 'Azure-Storage/0.37.0-0.38.0 (Python CPython 3.4.2; Windows 8)'
13+
# First version(0.37.0) is the common package, and the second version(0.38.0) is the service package
14+
USER_AGENT_STRING_PREFIX = 'Azure-Storage/{}-'.format(__version__)
15+
USER_AGENT_STRING_SUFFIX = '(Python {} {}; {} {})'.format(platform.python_implementation(),
16+
platform.python_version(), platform.system(),
17+
platform.release())
18+
19+
# default values for common package, in case it is used directly
20+
DEFAULT_X_MS_VERSION = '2018-03-28'
21+
DEFAULT_USER_AGENT_STRING = '{}None {}'.format(USER_AGENT_STRING_PREFIX, USER_AGENT_STRING_SUFFIX)
22+
23+
# Live ServiceClient URLs
24+
SERVICE_HOST_BASE = 'core.windows.net'
25+
DEFAULT_PROTOCOL = 'https'
26+
27+
# Development ServiceClient URLs
28+
DEV_BLOB_HOST = '127.0.0.1:10000'
29+
DEV_QUEUE_HOST = '127.0.0.1:10001'
30+
31+
# Default credentials for Development Storage Service
32+
DEV_ACCOUNT_NAME = 'devstoreaccount1'
33+
DEV_ACCOUNT_SECONDARY_NAME = 'devstoreaccount1-secondary'
34+
DEV_ACCOUNT_KEY = 'Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=='
35+
36+
# Socket timeout in seconds
37+
DEFAULT_SOCKET_TIMEOUT = 20
38+
39+
# for python 3.5+, there was a change to the definition of the socket timeout (as far as socket.sendall is concerned)
40+
# The socket timeout is now the maximum total duration to send all data.
41+
if sys.version_info >= (3, 5):
42+
# the timeout to connect is 20 seconds, and the read timeout is 2000 seconds
43+
# the 2000 seconds was calculated with: 100MB (max block size)/ 50KB/s (an arbitrarily chosen minimum upload speed)
44+
DEFAULT_SOCKET_TIMEOUT = (20, 2000)
45+
46+
# Encryption constants
47+
_ENCRYPTION_PROTOCOL_V1 = '1.0'
48+
49+
_AUTHORIZATION_HEADER_NAME = 'Authorization'
50+
_COPY_SOURCE_HEADER_NAME = 'x-ms-copy-source'
51+
_REDACTED_VALUE = 'REDACTED'

sdk/Table/azure/storage/tables/_shared/_error.py renamed to sdk/Table/azure/azure_table/_shared/_error.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
# --------------------------------------------------------------------------
66
from sys import version_info
77

8+
from pyparsing import unicode
9+
810
if version_info < (3,):
911
def _str(value):
1012
if isinstance(value, unicode):

sdk/Table/azure/storage/tables/_shared/authentication.py renamed to sdk/Table/azure/azure_table/_shared/authentication.py

Lines changed: 48 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
import sys
99

1010
try:
11-
from urllib.parse import urlparse, unquote
11+
from urllib.parse import urlparse, unquote, parse_qsl
1212
except ImportError:
13-
from urlparse import urlparse # type: ignore
14-
from urllib2 import unquote # type: ignore
13+
from urlparse import urlparse # type: ignore
14+
from urllib2 import unquote # type: ignore
1515

1616
try:
1717
from yarl import URL
@@ -26,11 +26,21 @@
2626
from azure.core.exceptions import ClientAuthenticationError
2727
from azure.core.pipeline.policies import SansIOHTTPPolicy
2828

29-
from . import sign_string
29+
from ._common_conversion import (
30+
_sign_string,
31+
)
3032

33+
from azure.table import (
34+
DEV_ACCOUNT_NAME,
35+
DEV_ACCOUNT_SECONDARY_NAME
36+
)
3137

32-
logger = logging.getLogger(__name__)
38+
from ._error import (
39+
AzureSigningError,
40+
_wrap_exception,
41+
)
3342

43+
logger = logging.getLogger(__name__)
3444

3545

3646
# wraps a given exception with the desired exception type
@@ -59,35 +69,36 @@ class AzureSigningError(ClientAuthenticationError):
5969
# pylint: disable=no-self-use
6070
class SharedKeyCredentialPolicy(SansIOHTTPPolicy):
6171

62-
def __init__(self, account_name, account_key):
72+
def __init__(self, account_name, account_key, is_emulated=False):
6373
self.account_name = account_name
6474
self.account_key = account_key
65-
super(SharedKeyCredentialPolicy, self).__init__()
75+
self.is_emulated = is_emulated
6676

6777
def _get_headers(self, request, headers_to_sign):
68-
headers = dict((name.lower(), value) for name, value in request.http_request.headers.items() if value)
78+
headers = dict((name.lower(), value) for name, value in request.headers.items() if value)
6979
if 'content-length' in headers and headers['content-length'] == '0':
7080
del headers['content-length']
7181
return '\n'.join(headers.get(x, '') for x in headers_to_sign) + '\n'
7282

7383
def _get_verb(self, request):
74-
return request.http_request.method + '\n'
84+
return request.method + '\n'
7585

7686
def _get_canonicalized_resource(self, request):
77-
uri_path = urlparse(request.http_request.url).path
78-
try:
79-
if isinstance(request.context.transport, AioHttpTransport) or \
80-
isinstance(getattr(request.context.transport, "_transport", None), AioHttpTransport):
81-
uri_path = URL(uri_path)
82-
return '/' + self.account_name + str(uri_path)
83-
except TypeError:
84-
pass
87+
#uri_path = request.path.split('?')[0]
88+
uri_path = urlparse(request.url).path
89+
90+
# for emulator, use the DEV_ACCOUNT_NAME instead of DEV_ACCOUNT_SECONDARY_NAME
91+
# as this is how the emulator works
92+
if self.is_emulated and uri_path.find(DEV_ACCOUNT_SECONDARY_NAME) == 1:
93+
# only replace the first instance
94+
uri_path = uri_path.replace(DEV_ACCOUNT_SECONDARY_NAME, DEV_ACCOUNT_NAME, 1)
95+
8596
return '/' + self.account_name + uri_path
8697

8798
def _get_canonicalized_headers(self, request):
8899
string_to_sign = ''
89100
x_ms_headers = []
90-
for name, value in request.http_request.headers.items():
101+
for name, value in request.headers.items():
91102
if name.startswith('x-ms-'):
92103
x_ms_headers.append((name.lower(), value))
93104
x_ms_headers.sort()
@@ -96,41 +107,39 @@ def _get_canonicalized_headers(self, request):
96107
string_to_sign += ''.join([name, ':', value, '\n'])
97108
return string_to_sign
98109

99-
def _get_canonicalized_resource_query(self, request):
100-
sorted_queries = [(name, value) for name, value in request.http_request.query.items()]
101-
sorted_queries.sort()
102-
103-
string_to_sign = ''
104-
for name, value in sorted_queries:
105-
if value is not None:
106-
string_to_sign += '\n' + name.lower() + ':' + unquote(value)
107-
108-
return string_to_sign
109-
110110
def _add_authorization_header(self, request, string_to_sign):
111111
try:
112-
signature = sign_string(self.account_key, string_to_sign)
112+
signature = _sign_string(self.account_key, string_to_sign)
113113
auth_string = 'SharedKey ' + self.account_name + ':' + signature
114-
request.http_request.headers['Authorization'] = auth_string
114+
request.headers['Authorization'] = auth_string
115115
except Exception as ex:
116116
# Wrap any error that occurred as signing error
117117
# Doing so will clarify/locate the source of problem
118118
raise _wrap_exception(ex, AzureSigningError)
119119

120-
def on_request(self, request):
120+
def on_request(self, request): # type: (PipelineRequest) -> Union[None, Awaitable[None]]
121+
self.sign_request(request.http_request)
122+
123+
def sign_request(self, request):
121124
string_to_sign = \
122125
self._get_verb(request) + \
123126
self._get_headers(
124127
request,
125-
[
126-
'content-encoding', 'content-language', 'content-length',
127-
'content-md5', 'content-type', 'date', 'if-modified-since',
128-
'if-match', 'if-none-match', 'if-unmodified-since', 'byte_range'
129-
]
128+
['content-md5', 'content-type', 'x-ms-date'],
130129
) + \
131-
self._get_canonicalized_headers(request) + \
132130
self._get_canonicalized_resource(request) + \
133131
self._get_canonicalized_resource_query(request)
134132

135133
self._add_authorization_header(request, string_to_sign)
136-
#logger.debug("String_to_sign=%s", string_to_sign)
134+
logger.debug("String_to_sign=%s", string_to_sign)
135+
136+
def _get_canonicalized_resource_query(self, request):
137+
sorted_queries = [(name, value) for name, value in request.query.items()]
138+
sorted_queries.sort()
139+
140+
string_to_sign = ''
141+
for name, value in sorted_queries:
142+
if value is not None:
143+
string_to_sign += '\n' + name.lower() + ':' + value
144+
145+
return string_to_sign

sdk/Table/azure/storage/tables/_shared/base_client.py renamed to sdk/Table/azure/azure_table/_shared/base_client.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,10 @@
5050
StorageResponseHook,
5151
StorageLoggingPolicy,
5252
StorageHosts,
53-
QueueMessagePolicy,
5453
ExponentialRetry,
5554
)
5655
from .._version import VERSION
57-
from .._generated.models import StorageErrorException
56+
# from .._generated.models import StorageErrorException
5857
from .response_handlers import process_storage_error, PartialBatchErrorException
5958

6059

@@ -63,6 +62,7 @@
6362
"blob": {"primary": "BlobEndpoint", "secondary": "BlobSecondaryEndpoint"},
6463
"queue": {"primary": "QueueEndpoint", "secondary": "QueueSecondaryEndpoint"},
6564
"file": {"primary": "FileEndpoint", "secondary": "FileSecondaryEndpoint"},
65+
"table": {"primary": "TableEndpoint", "secondary": "TableSecondaryEndpoint"},
6666
"dfs": {"primary": "BlobEndpoint", "secondary": "BlobEndpoint"},
6767
}
6868

@@ -80,7 +80,7 @@ def __init__(
8080
self._hosts = kwargs.get("_hosts")
8181
self.scheme = parsed_url.scheme
8282

83-
if service not in ["blob", "queue", "file-share", "dfs"]:
83+
if service not in ["blob", "queue", "file-share", "dfs", "table"]:
8484
raise ValueError("Invalid service: {}".format(service))
8585
service_name = service.split('-')[0]
8686
account = parsed_url.netloc.split(".{}.core.".format(service_name))
@@ -230,19 +230,17 @@ def _create_pipeline(self, credential, **kwargs):
230230
if not config.transport:
231231
config.transport = RequestsTransport(**kwargs)
232232
policies = [
233-
QueueMessagePolicy(),
234233
config.headers_policy,
235234
config.proxy_policy,
236235
config.user_agent_policy,
237-
StorageContentValidation(),
238-
StorageRequestHook(**kwargs),
236+
# StorageRequestHook(**kwargs),
239237
self._credential_policy,
240238
ContentDecodePolicy(response_encoding="utf-8"),
241239
RedirectPolicy(**kwargs),
242-
StorageHosts(hosts=self._hosts, **kwargs),
240+
# StorageHosts(hosts=self._hosts, **kwargs),
243241
config.retry_policy,
244242
config.logging_policy,
245-
StorageResponseHook(**kwargs),
243+
# StorageResponseHook(**kwargs),
246244
DistributedTracingPolicy(**kwargs),
247245
HttpLoggingPolicy(**kwargs)
248246
]
@@ -291,7 +289,7 @@ def _batch_send(
291289
raise error
292290
return iter(parts)
293291
return parts
294-
except StorageErrorException as error:
292+
except HttpResponseError as error:
295293
process_storage_error(error)
296294

297295
class TransportWrapper(HttpTransport):
@@ -328,7 +326,9 @@ def format_shared_key_credential(account, credential):
328326
raise ValueError("Shared key credential missing 'account_name")
329327
if "account_key" not in credential:
330328
raise ValueError("Shared key credential missing 'account_key")
329+
print('SharedKey ', credential)
331330
return SharedKeyCredentialPolicy(**credential)
331+
print(credential)
332332
return credential
333333

334334

@@ -386,6 +386,7 @@ def create_configuration(**kwargs):
386386
config.logging_policy = StorageLoggingPolicy(**kwargs)
387387
config.proxy_policy = ProxyPolicy(**kwargs)
388388

389+
# all can be ignored
389390
# Storage settings
390391
config.max_single_put_size = kwargs.get("max_single_put_size", 64 * 1024 * 1024)
391392
config.copy_polling_interval = 15
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# -------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for
4+
# license information.
5+
# --------------------------------------------------------------------------
6+
7+
import sys
8+
from .._generated.version import VERSION
9+
10+
11+
X_MS_VERSION = VERSION
12+
13+
# Socket timeout in seconds
14+
CONNECTION_TIMEOUT = 20
15+
READ_TIMEOUT = 20
16+
17+
# for python 3.5+, there was a change to the definition of the socket timeout (as far as socket.sendall is concerned)
18+
# The socket timeout is now the maximum total duration to send all data.
19+
if sys.version_info >= (3, 5):
20+
# the timeout to connect is 20 seconds, and the read timeout is 2000 seconds
21+
# the 2000 seconds was calculated with: 100MB (max block size)/ 50KB/s (an arbitrarily chosen minimum upload speed)
22+
READ_TIMEOUT = 2000
23+
24+
STORAGE_OAUTH_SCOPE = "https://storage.azure.com/.default"
25+
26+
SERVICE_HOST_BASE = 'core.windows.net'

sdk/Table/azure/storage/tables/_shared/models.py renamed to sdk/Table/azure/azure_table/_shared/models.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,20 @@
33
# Licensed under the MIT License. See License.txt in the project root for
44
# license information.
55
# --------------------------------------------------------------------------
6-
6+
import sys
77
from enum import Enum
88

9+
from pyparsing import unicode
10+
11+
if sys.version_info < (3,):
12+
from collections import Iterable
13+
14+
_unicode_type = unicode
15+
else:
16+
from collections.abc import Iterable
17+
18+
_unicode_type = str
19+
920

1021
def get_enum_value(value):
1122
if value is None or value in ["None", ""]:

0 commit comments

Comments
 (0)