Skip to content

Commit

Permalink
Hookup share client (#6000)
Browse files Browse the repository at this point in the history
* commit1

* Hook up Share Client
  • Loading branch information
Rakshith Bhyravabhotla authored Jun 20, 2019
1 parent f4d1a6d commit 6033e96
Show file tree
Hide file tree
Showing 7 changed files with 256 additions and 32 deletions.
20 changes: 20 additions & 0 deletions sdk/storage/azure-storage-file/azure/storage/file/_share_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------

from .models import ShareProperties


def deserialize_metadata(response, obj, headers):
raw_metadata = {k: v for k, v in response.headers.items() if k.startswith("x-ms-meta-")}
return {k[10:]: v for k, v in raw_metadata.items()}

def deserialize_share_properties(response, obj, headers):
metadata = deserialize_metadata(response, obj, headers)
share_properties = ShareProperties(
metadata=metadata,
**headers
)
return share_properties
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
from azure.core.exceptions import AzureError
from azure.core.pipeline.policies import SansIOHTTPPolicy

from .constants import DEV_ACCOUNT_NAME, DEV_ACCOUNT_SECONDARY_NAME

if sys.version_info < (3,):
_unicode_type = unicode # pylint: disable=undefined-variable
else:
Expand Down Expand Up @@ -82,13 +80,12 @@ class AzureSigningError(AzureError):


# pylint: disable=no-self-use
class SharedKeyCredentials(SansIOHTTPPolicy):
class SharedKeyCredentialPolicy(SansIOHTTPPolicy):

def __init__(self, account_name, account_key, is_emulated=False):
def __init__(self, account_name, account_key):
self.account_name = account_name
self.account_key = account_key
self.is_emulated = is_emulated
super(SharedKeyCredentials, self).__init__()
super(SharedKeyCredentialPolicy, self).__init__()

def _get_headers(self, request, headers_to_sign):
headers = dict((name.lower(), value) for name, value in request.http_request.headers.items() if value)
Expand All @@ -101,13 +98,6 @@ def _get_verb(self, request):

def _get_canonicalized_resource(self, request):
uri_path = urlparse(request.http_request.url).path

# for emulator, use the DEV_ACCOUNT_NAME instead of DEV_ACCOUNT_SECONDARY_NAME
# as this is how the emulator works
if self.is_emulated and uri_path.find(DEV_ACCOUNT_SECONDARY_NAME) == 1:
# only replace the first instance
uri_path = uri_path.replace(DEV_ACCOUNT_SECONDARY_NAME, DEV_ACCOUNT_NAME, 1)

return '/' + self.account_name + uri_path

def _get_canonicalized_headers(self, request):
Expand Down Expand Up @@ -141,7 +131,6 @@ def _add_authorization_header(self, request, string_to_sign):
except Exception as ex:
# Wrap any error that occurred as signing error
# Doing so will clarify/locate the source of problem
# TODO: AzureSigningError
raise _wrap_exception(ex, AzureSigningError)

def on_request(self, request, **kwargs):
Expand All @@ -160,4 +149,4 @@ def on_request(self, request, **kwargs):
self._get_canonicalized_resource_query(request)

self._add_authorization_header(request, string_to_sign)
logger.debug("String_to_sign=%s", string_to_sign)
#logger.debug("String_to_sign=%s", string_to_sign)
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,14 @@ def get(self, key, default=None):
if key in self.__dict__:
return self.__dict__[key]
return default


class LocationMode(object):
"""
Specifies the location the request should be sent to. This mode only applies
for RA-GRS accounts which allow secondary read access. All other account types
must use PRIMARY.
"""

PRIMARY = 'primary' #: Requests should be sent to the primary location.
SECONDARY = 'secondary' #: Requests should be sent to the secondary location, if possible.
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@
ClientAuthenticationError,
DecodeError)

from .constants import STORAGE_OAUTH_SCOPE, SERVICE_HOST_BASE, DEFAULT_SOCKET_TIMEOUT
from .models import LocationMode, StorageErrorCode
from .authentication import SharedKeyCredentialPolicy
from .policies import (
from azure.storage.file._shared.constants import STORAGE_OAUTH_SCOPE, SERVICE_HOST_BASE, DEFAULT_SOCKET_TIMEOUT
from azure.storage.file._shared.models import LocationMode, StorageErrorCode
from azure.storage.file._shared.authentication import SharedKeyCredentialPolicy
from azure.storage.file._shared.policies import (
StorageFileSettings,
StorageHeadersPolicy,
StorageContentValidation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class DirectoryClient():
def __init__(
self, share_name=None, # type: Optional[Union[str, ShareProperties]]
directory_path=None, # type: Optional[str]
credentials=None, # type: Optional[Any]
credential=None, # type: Optional[Any]
configuration=None # type: Optional[Configuration]
):
# type: (...) -> DirectoryClient
Expand Down
Loading

0 comments on commit 6033e96

Please sign in to comment.