Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
512d5a4
[File][RestParity]Rest Parity Sync
xiafu-msft Aug 29, 2019
8bed721
[File][RestParity]Rest Parity Async
xiafu-msft Aug 29, 2019
22b801a
[File][RestParity]Add Rest Parity Async Recording Files
xiafu-msft Aug 29, 2019
bfd3fbd
[File][RestParity]Fix CI
xiafu-msft Sep 6, 2019
7707acf
[File][RestParity]Recording again to fix CI
xiafu-msft Sep 6, 2019
e945a70
Add Generated Code
xiafu-msft Sep 6, 2019
8c821a6
Stylistic Things and Record
xiafu-msft Sep 6, 2019
8c5c22c
[Swagger][BugFix]workaround to fix swagger generated code
xiafu-msft Sep 9, 2019
d46e3dc
[File][RestParity]Add Create_Permission API and Test
xiafu-msft Sep 9, 2019
fcf0ec6
Fix Test
xiafu-msft Sep 9, 2019
3c6b3e0
Fix Pylint
xiafu-msft Sep 9, 2019
62dc377
Revert the workaround
xiafu-msft Sep 9, 2019
3d00c52
[File][RestParity]Tweak Documentation and Tests
xiafu-msft Sep 9, 2019
9afed1d
delete .dat file
xiafu-msft Sep 9, 2019
bd9f32e
[File][RestParity]Rest Parity Async
xiafu-msft Aug 29, 2019
99a07ad
[Blob][IdentitySAS]Add Identity SAS
xiafu-msft Aug 30, 2019
e7811c1
[Blob][IdentitySAS]Stylistic Things
xiafu-msft Sep 9, 2019
a565b90
[Blob][IdentitySAS]Stylistic Things
xiafu-msft Sep 9, 2019
aed02d4
[Blob][IdentitySAS]Add account_name parameter
xiafu-msft Sep 9, 2019
17540b4
Fix Pylint
xiafu-msft Sep 9, 2019
9c327cc
Merge branch 'feature/storage-preview3' into identity-sas
xiafu-msft Sep 9, 2019
450a66e
Merge branch 'feature/storage-preview3' into identity-sas
xiafu-msft Sep 9, 2019
969816b
Fix Pylint
xiafu-msft Sep 10, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[File][RestParity]Rest Parity Sync
Add Rest Parity Sync part(except create permission)
tweak _shared package a bit
  • Loading branch information
xiafu-msft committed Sep 9, 2019
commit 512d5a4444cbbf7c6390a99e868ed41fdf93f917
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import sys

if sys.version_info < (3,):
def _str(value):
if isinstance(value, unicode): # pylint: disable=undefined-variable
return value.encode('utf-8')

return str(value)
else:
_str = str


def _to_utc_datetime(value):
return value.strftime('%Y-%m-%dT%H:%M:%SZ')
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,13 @@
# license information.
# --------------------------------------------------------------------------

import sys
from datetime import date

from .parser import _str, _to_utc_datetime
from .constants import X_MS_VERSION
from . import sign_string, url_quote


if sys.version_info < (3,):
def _str(value):
if isinstance(value, unicode): # pylint: disable=undefined-variable
return value.encode('utf-8')

return str(value)
else:
_str = str


def _to_utc_datetime(value):
return value.strftime('%Y-%m-%dT%H:%M:%SZ')


class QueryStringConstants(object):
SIGNED_SIGNATURE = 'sig'
SIGNED_PERMISSION = 'sp'
Expand Down
Binary file not shown.
6 changes: 4 additions & 2 deletions sdk/storage/azure-storage-file/azure/storage/file/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
AccessPolicy,
FilePermissions,
SharePermissions,
ContentSettings)
ContentSettings,
NTFSAttributes)


__version__ = VERSION
Expand Down Expand Up @@ -60,5 +61,6 @@
'FileProperties',
'ContentSettings',
'Handle',
'HandlesPaged'
'HandlesPaged',
'NTFSAttributes'
]
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,11 @@ def deserialize_file_stream(response, obj, headers):
file_properties = deserialize_file_properties(response, obj, headers)
obj.properties = file_properties
return response.location_mode, obj


def _deserialize_permission(response):
'''
Extracts out file permission
'''

return response.body
41 changes: 41 additions & 0 deletions sdk/storage/azure-storage-file/azure/storage/file/_parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from datetime import datetime, timedelta

_ERROR_TOO_MANY_FILE_PERMISSIONS = 'file_permission and file_permission_key should not be set at the same time'
_FILE_PERMISSION_TOO_LONG = 'Size of file_permission is too large. file_permission should be <=8KB, else' \
'please use file_permission_key'


def _get_file_permission(file_permission, file_permission_key, default_permission):
# if file_permission and file_permission_key are both empty, then use the default_permission
# value as file permission, file_permission size should be <= 8KB, else file permission_key should be used
empty_file_permission = file_permission is None or len(file_permission) == 0
empty_file_permission_key = file_permission_key is None or len(file_permission_key) == 0
file_permission_size_too_big = False if file_permission is None \
else len(str(file_permission).encode('utf-8')) > 8 * 1024

if file_permission_size_too_big:
raise ValueError(_FILE_PERMISSION_TOO_LONG)

if empty_file_permission:
if empty_file_permission_key:
return default_permission
else:
return None

if empty_file_permission_key:
return file_permission

raise ValueError(_ERROR_TOO_MANY_FILE_PERMISSIONS)


def _parse_datetime_from_str(string_datetime):
dt, _, us = string_datetime.partition(".")
dt = datetime.strptime(dt, "%Y-%m-%dT%H:%M:%S")
us = int(us[:-2]) # microseconds
datetime_obj = dt + timedelta(microseconds=us)
return datetime_obj


def _datetime_to_str(datetime_obj):
return datetime_obj if isinstance(datetime_obj, str) else datetime_obj.isoformat() + '0Z'

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import sys


X_MS_VERSION = '2018-03-28'
X_MS_VERSION = '2019-02-02'

# Socket timeout in seconds
DEFAULT_SOCKET_TIMEOUT = 20
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import sys

if sys.version_info < (3,):
def _str(value):
if isinstance(value, unicode): # pylint: disable=undefined-variable
return value.encode('utf-8')

return str(value)
else:
_str = str


def _to_utc_datetime(value):
return value.strftime('%Y-%m-%dT%H:%M:%SZ')
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,13 @@
# license information.
# --------------------------------------------------------------------------

import sys
from datetime import date

from .parser import _str, _to_utc_datetime
from .constants import X_MS_VERSION
from . import sign_string, url_quote


if sys.version_info < (3,):
def _str(value):
if isinstance(value, unicode): # pylint: disable=undefined-variable
return value.encode('utf-8')

return str(value)
else:
_str = str


def _to_utc_datetime(value):
return value.strftime('%Y-%m-%dT%H:%M:%SZ')


class QueryStringConstants(object):
SIGNED_SIGNATURE = 'sig'
SIGNED_PERMISSION = 'sp'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
# license information.
# --------------------------------------------------------------------------

from azure.storage.file._shared import sign_string
from azure.storage.file._shared.constants import X_MS_VERSION
from azure.storage.file._shared.shared_access_signature import SharedAccessSignature, _str, _SharedAccessHelper, \
QueryStringConstants
from ._shared import sign_string
from ._shared.constants import X_MS_VERSION
from ._shared.shared_access_signature import SharedAccessSignature, _SharedAccessHelper, QueryStringConstants
from ._shared.parser import _str


class FileSharedAccessSignature(SharedAccessSignature):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
AccessPolicy,
FilePermissions,
SharePermissions,
ContentSettings)
ContentSettings,
NTFSAttributes)
from .models import (
HandlesPaged,
SharePropertiesPaged,
Expand Down Expand Up @@ -57,5 +58,6 @@
'DirectoryProperties',
'DirectoryPropertiesPaged',
'FileProperties',
'ContentSettings'
'ContentSettings',
'NTFSAttributes'
]
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
# --------------------------------------------------------------------------

import functools
from typing import ( # pylint: disable=unused-import
from typing import ( # pylint: disable=unused-import
Optional, Union, Any, Dict, TYPE_CHECKING
)

from ._parser import _get_file_permission, _datetime_to_str
from ._shared.parser import _str

try:
from urllib.parse import urlparse, quote, unquote
except ImportError:
Expand All @@ -28,12 +32,13 @@
from ._deserialize import deserialize_directory_properties
from ._polling import CloseHandles
from .file_client import FileClient
from .models import DirectoryPropertiesPaged, HandlesPaged
from .models import DirectoryPropertiesPaged, HandlesPaged, NTFSAttributes

if TYPE_CHECKING:
from .models import SharePermissions, ShareProperties, DirectoryProperties, ContentSettings
from .models import ShareProperties, DirectoryProperties, ContentSettings
from ._generated.models import HandleItem


class DirectoryClient(StorageAccountHostsMixin):
"""A client to interact with a specific directory, although it may not yet exist.

Expand Down Expand Up @@ -422,13 +427,64 @@ def set_directory_metadata(self, metadata, timeout=None, **kwargs): # type: igno
except StorageErrorException as error:
process_storage_error(error)

@distributed_trace
def set_http_headers(self, file_attributes="none", # type: Union[str, NTFSAttributes]
file_creation_time="preserve", # type: Union[str, datetime]
file_last_write_time="preserve", # type: Union[str, datetime]
timeout=None, # type: Optional[int]
file_permission=None, # type: Optional[str]
file_permission_key=None, # type: Optional[str]
**kwargs): # type: ignore
# type: (...) -> Dict[str, Any]
"""Sets HTTP headers on the directory.

:param int timeout:
The timeout parameter is expressed in seconds.
:param file_attributes:
The file system attributes for files and directories.
If not set, indicates preservation of existing values.
Here is an example for when the var type is str: 'Temporary|Archive'
:type file_attributes: str or :class:`~azure.storage.file.models.NTFSAttributes`
:param file_creation_time: Creation time for the file
Default value: Now.
:type file_creation_time: str or datetime
:param file_last_write_time: Last write time for the file
Default value: Now.
:type file_last_write_time: str or datetime
:param file_permission: If specified the permission (security
descriptor) shall be set for the directory/file. This header can be
used if Permission size is <= 8KB, else x-ms-file-permission-key
header shall be used. Default value: Inherit. If SDDL is specified as
input, it must have owner, group and dacl. Note: Only one of the
x-ms-file-permission or x-ms-file-permission-key should be specified.
:type file_permission: str
:param file_permission_key: Key of the permission to be set for the
directory/file. Note: Only one of the x-ms-file-permission or
x-ms-file-permission-key should be specified.
:type file_permission_key: str
:returns: File-updated property dict (Etag and last modified).
:rtype: dict(str, Any)
"""
file_permission = _get_file_permission(file_permission, file_permission_key, 'preserve')
try:
return self._client.directory.set_properties( # type: ignore
file_attributes=_str(file_attributes),
file_creation_time=_datetime_to_str(file_creation_time),
file_last_write_time=_datetime_to_str(file_last_write_time),
file_permission=file_permission,
file_permission_key=file_permission_key,
timeout=timeout,
cls=return_response_headers,
**kwargs)
except StorageErrorException as error:
process_storage_error(error)

@distributed_trace
def create_subdirectory(
self, directory_name, # type: str
metadata=None, #type: Optional[Dict[str, Any]]
timeout=None, # type: Optional[int]
**kwargs
):
metadata=None, # type: Optional[Dict[str, Any]]
timeout=None, # type: Optional[int]
**kwargs):
# type: (...) -> DirectoryClient
"""Creates a new subdirectory and returns a client to interact
with the subdirectory.
Expand Down
Loading