Skip to content

Commit

Permalink
Storage POC WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
lmazuel committed Sep 19, 2019
1 parent 24300fd commit c3e170b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,11 @@ def _format_query_string(self, sas_token, credential, snapshot=None, share_snaps

def _create_pipeline(self, credential, **kwargs):
# type: (Any, **Any) -> Tuple[Configuration, Pipeline]
credential_policy = None
self._credential_policy = None
if hasattr(credential, "get_token"):
credential_policy = BearerTokenCredentialPolicy(credential, STORAGE_OAUTH_SCOPE)
self._credential_policy = BearerTokenCredentialPolicy(credential, STORAGE_OAUTH_SCOPE)
elif isinstance(credential, SharedKeyCredentialPolicy):
credential_policy = credential
self._credential_policy = credential
elif credential is not None:
raise TypeError("Unsupported credential: {}".format(credential))

Expand All @@ -169,7 +169,7 @@ def _create_pipeline(self, credential, **kwargs):
config.user_agent_policy,
StorageContentValidation(),
StorageRequestHook(**kwargs),
credential_policy,
self._credential_policy,
ContentDecodePolicy(),
RedirectPolicy(**kwargs),
StorageHosts(hosts=self._hosts, **kwargs),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1003,10 +1003,17 @@ def delete_blobs(
:rtype: None
"""
from azure.core.pipeline.transport import HttpRequest, HttpResponse, RequestsTransport
from azure.core.exceptions import map_error
from azure.core.pipeline.policies import HeadersPolicy
from azure.core.exceptions import map_error, HttpResponseError
reqs = []
for blob in blobs:
reqs.append(HttpRequest("DELETE", blob))
reqs.append(HttpRequest(
"DELETE",
"/{}/{}".format(self.container_name, blob),
headers={
'Content-Length': '0'
}
))

request = self._client._client.post(
url='https://{}/?comp=batch'.format(self.primary_hostname),
Expand All @@ -1015,22 +1022,40 @@ def delete_blobs(
}
#params={'comp': 'batch'}
)

from wsgiref.handlers import format_date_time
from time import time
class LocalStorageHeadersPolicy(HeadersPolicy):

def on_request(self, request):
# type: (PipelineRequest, Any) -> None
super(LocalStorageHeadersPolicy, self).on_request(request)
current_time = format_date_time(time())
request.http_request.headers['x-ms-date'] = current_time


request.set_multipart_mixed(
*reqs,
policies=[]
policies=[
LocalStorageHeadersPolicy(),
self._credential_policy
]
)

response = self._pipeline.run(
pipeline_response = self._pipeline.run(
request,
)
response = response.http_response
response = pipeline_response.http_response

try:
if response.status_code not in [200]:
from ._generated import models
error_map = kwargs.pop('error_map', None)
map_error(status_code=response.status_code, response=response, error_map=error_map)
raise models.StorageErrorException(response, self._client.container._deserialize)
if response.status_code not in [202]:
raise HttpResponseError(response=response)
# This scenario to be discussed
if len(pipeline_response.context['MULTIPART_RESPONSE']) != len(reqs):
raise HttpResponseError(
message="Didn't receive the same number of parts",
response=response
)
except StorageErrorException as error:
process_storage_error(error)

Expand Down

0 comments on commit c3e170b

Please sign in to comment.