Skip to content

Commit c6a8d7d

Browse files
committed
use datalake set_expiry operation
1 parent 9bc70d4 commit c6a8d7d

13 files changed

+129
-107
lines changed

sdk/storage/azure-storage-blob/azure/storage/blob/_blob_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ def _download_blob_options(self, offset=None, length=None, **kwargs):
577577
'lease_access_conditions': access_conditions,
578578
'modified_access_conditions': mod_conditions,
579579
'cpk_info': cpk_info,
580-
'cls': deserialize_blob_stream,
580+
'cls': kwargs.pop('cls', None) or deserialize_blob_stream,
581581
'max_concurrency':kwargs.pop('max_concurrency', 1),
582582
'encoding': kwargs.pop('encoding', None),
583583
'timeout': kwargs.pop('timeout', None),

sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
DirectoryProperties,
1919
FileProperties,
2020
PathProperties,
21-
PathPropertiesPaged,
2221
LeaseProperties,
2322
ContentSettings,
2423
AccountSasPermissions,
@@ -32,6 +31,7 @@
3231
DelimitedJsonDialect,
3332
DataLakeFileQueryError
3433
)
34+
from ._list_paths_helper import PathPropertiesPaged
3535
from ._shared_access_signature import generate_account_sas, generate_file_system_sas, generate_directory_sas, \
3636
generate_file_sas
3737

@@ -60,7 +60,6 @@
6060
'DirectoryProperties',
6161
'FileProperties',
6262
'PathProperties',
63-
'PathPropertiesPaged',
6463
'LeaseProperties',
6564
'ContentSettings',
6665
'AccountSasPermissions',

sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_data_lake_directory_client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# Licensed under the MIT License. See License.txt in the project root for
44
# license information.
55
# --------------------------------------------------------------------------
6+
from ._deserialize import deserialize_dir_properties
67
from ._shared.base_client import parse_connection_str
78
from ._data_lake_file_client import DataLakeFileClient
89
from ._models import DirectoryProperties
@@ -230,7 +231,7 @@ def get_directory_properties(self, **kwargs):
230231
:dedent: 4
231232
:caption: Getting the properties for a file/directory.
232233
"""
233-
return self._get_path_properties(cls=DirectoryProperties._deserialize_dir_properties, **kwargs) # pylint: disable=protected-access
234+
return self._get_path_properties(cls=deserialize_dir_properties, **kwargs) # pylint: disable=protected-access
234235

235236
def rename_directory(self, new_name, # type: str
236237
**kwargs):

sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_data_lake_file_client.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from ._download import StorageStreamDownloader
1717
from ._path_client import PathClient
1818
from ._serialize import get_mod_conditions, get_path_http_headers, get_access_conditions, add_metadata_headers
19-
from ._deserialize import process_storage_error
19+
from ._deserialize import process_storage_error, deserialize_file_properties
2020
from ._models import FileProperties, DataLakeFileQueryError
2121

2222

@@ -240,7 +240,7 @@ def get_file_properties(self, **kwargs):
240240
:dedent: 4
241241
:caption: Getting the properties for a file.
242242
"""
243-
return self._get_path_properties(cls=FileProperties._deserialize_file_properties, **kwargs) # pylint: disable=protected-access
243+
return self._get_path_properties(cls=deserialize_file_properties, **kwargs) # pylint: disable=protected-access
244244

245245
def set_file_expiry(self, expiry_options, # type: str
246246
expires_on=None, # type: Optional[Union[datetime, int]]
@@ -258,7 +258,8 @@ def set_file_expiry(self, expiry_options, # type: str
258258
The timeout parameter is expressed in seconds.
259259
:rtype: None
260260
"""
261-
return self._blob_client._client.blob.set_expiry(expiry_options, expires_on=expires_on, **kwargs) # pylint: disable=protected-access
261+
return self._datalake_client_for_blob_operation.path\
262+
.set_expiry(expiry_options, expires_on=expires_on, **kwargs) # pylint: disable=protected-access
262263

263264
def _upload_options( # pylint:disable=too-many-statements
264265
self, data, # type: Union[Iterable[AnyStr], IO[AnyStr]]

sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_deserialize.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from azure.core.pipeline.policies import ContentDecodePolicy
1313
from azure.core.exceptions import HttpResponseError, DecodeError, ResourceModifiedError, ClientAuthenticationError, \
1414
ResourceNotFoundError, ResourceExistsError
15+
from ._models import FileProperties, DirectoryProperties, LeaseProperties
1516
from ._shared.models import StorageErrorCode
1617

1718
if TYPE_CHECKING:
@@ -20,6 +21,45 @@
2021
_LOGGER = logging.getLogger(__name__)
2122

2223

24+
def deserialize_dir_properties(response, obj, headers):
25+
metadata = deserialize_metadata(response, obj, headers)
26+
dir_properties = DirectoryProperties(
27+
metadata=metadata,
28+
**headers
29+
)
30+
return dir_properties
31+
32+
33+
def deserialize_file_properties(response, obj, headers):
34+
metadata = deserialize_metadata(response, obj, headers)
35+
file_properties = FileProperties(
36+
metadata=metadata,
37+
**headers
38+
)
39+
if 'Content-Range' in headers:
40+
if 'x-ms-blob-content-md5' in headers:
41+
file_properties.content_settings.content_md5 = headers['x-ms-blob-content-md5']
42+
else:
43+
file_properties.content_settings.content_md5 = None
44+
return file_properties
45+
46+
47+
def from_blob_properties(blob_properties):
48+
file_props = FileProperties()
49+
file_props.name = blob_properties.name
50+
file_props.etag = blob_properties.etag
51+
file_props.deleted = blob_properties.deleted
52+
file_props.metadata = blob_properties.metadata
53+
file_props.lease = blob_properties.lease
54+
file_props.lease.__class__ = LeaseProperties
55+
file_props.last_modified = blob_properties.last_modified
56+
file_props.creation_time = blob_properties.creation_time
57+
file_props.size = blob_properties.size
58+
file_props.deleted_time = blob_properties.deleted_time
59+
file_props.remaining_retention_days = blob_properties.remaining_retention_days
60+
file_props.content_settings = blob_properties.content_settings
61+
return file_props
62+
2363
def normalize_headers(headers):
2464
normalized = {}
2565
for key, value in headers.items():

sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_download.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
# Licensed under the MIT License. See License.txt in the project root for
44
# license information.
55
# --------------------------------------------------------------------------
6-
7-
from ._models import FileProperties
6+
from ._deserialize import from_blob_properties
87

98

109
class StorageStreamDownloader(object):
@@ -23,7 +22,7 @@ class StorageStreamDownloader(object):
2322
def __init__(self, downloader):
2423
self._downloader = downloader
2524
self.name = self._downloader.name
26-
self.properties = FileProperties._from_blob_properties(self._downloader.properties) # pylint: disable=protected-access
25+
self.properties = from_blob_properties(self._downloader.properties) # pylint: disable=protected-access
2726
self.size = self._downloader.size
2827

2928
def __len__(self):

sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_file_system_client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
from azure.storage.blob import ContainerClient
1717
from ._shared.base_client import StorageAccountHostsMixin, parse_query, parse_connection_str
1818
from ._serialize import convert_dfs_url_to_blob_url
19-
from ._models import LocationMode, FileSystemProperties, PathPropertiesPaged, PublicAccess
19+
from ._models import LocationMode, FileSystemProperties, PublicAccess
20+
from ._list_paths_helper import PathPropertiesPaged
2021
from ._data_lake_file_client import DataLakeFileClient
2122
from ._data_lake_directory_client import DataLakeDirectoryClient
2223
from ._data_lake_lease import DataLakeLeaseClient
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
from azure.core.paging import PageIterator
2+
from ._generated.models import StorageErrorException
3+
from ._models import PathProperties
4+
from ._deserialize import return_headers_and_deserialized_path_list
5+
from ._generated.models import Path
6+
from ._shared.response_handlers import process_storage_error
7+
8+
9+
class PathPropertiesPaged(PageIterator):
10+
"""An Iterable of Path properties.
11+
12+
:ivar str path: Filters the results to return only paths under the specified path.
13+
:ivar int results_per_page: The maximum number of results retrieved per API call.
14+
:ivar str continuation_token: The continuation token to retrieve the next page of results.
15+
:ivar list(~azure.storage.filedatalake.PathProperties) current_page: The current page of listed results.
16+
17+
:param callable command: Function to retrieve the next page of items.
18+
:param str path: Filters the results to return only paths under the specified path.
19+
:param int max_results: The maximum number of psths to retrieve per
20+
call.
21+
:param str continuation_token: An opaque continuation token.
22+
"""
23+
def __init__(
24+
self, command,
25+
recursive,
26+
path=None,
27+
max_results=None,
28+
continuation_token=None,
29+
upn=None):
30+
super(PathPropertiesPaged, self).__init__(
31+
get_next=self._get_next_cb,
32+
extract_data=self._extract_data_cb,
33+
continuation_token=continuation_token or ""
34+
)
35+
self._command = command
36+
self.recursive = recursive
37+
self.results_per_page = max_results
38+
self.path = path
39+
self.upn = upn
40+
self.current_page = None
41+
self.path_list = None
42+
43+
def _get_next_cb(self, continuation_token):
44+
try:
45+
return self._command(
46+
self.recursive,
47+
continuation=continuation_token or None,
48+
path=self.path,
49+
max_results=self.results_per_page,
50+
upn=self.upn,
51+
cls=return_headers_and_deserialized_path_list)
52+
except StorageErrorException as error:
53+
process_storage_error(error)
54+
55+
def _extract_data_cb(self, get_next_return):
56+
self.path_list, self._response = get_next_return
57+
self.current_page = [self._build_item(item) for item in self.path_list]
58+
59+
return self._response['continuation'] or None, self.current_page
60+
61+
@staticmethod
62+
def _build_item(item):
63+
if isinstance(item, PathProperties):
64+
return item
65+
if isinstance(item, Path):
66+
path = PathProperties._from_generated(item) # pylint: disable=protected-access
67+
return path
68+
return item

sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_models.py

Lines changed: 0 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
# pylint: disable=super-init-not-called, too-many-lines
88
from enum import Enum
99

10-
from azure.core.paging import PageIterator
1110
from azure.storage.blob import LeaseProperties as BlobLeaseProperties
1211
from azure.storage.blob import AccountSasPermissions as BlobAccountSasPermissions
1312
from azure.storage.blob import ResourceTypes as BlobResourceTypes
@@ -17,12 +16,8 @@
1716
from azure.storage.blob import AccessPolicy as BlobAccessPolicy
1817
from azure.storage.blob import DelimitedTextDialect as BlobDelimitedTextDialect
1918
from azure.storage.blob import DelimitedJsonDialect as BlobDelimitedJSON
20-
from azure.storage.blob._generated.models import StorageErrorException
2119
from azure.storage.blob._models import ContainerPropertiesPaged
22-
from ._deserialize import return_headers_and_deserialized_path_list, deserialize_metadata
23-
from ._generated.models import Path
2420
from ._shared.models import DictMixin
25-
from ._shared.response_handlers import process_storage_error
2621

2722

2823
class FileSystemProperties(object):
@@ -141,15 +136,6 @@ def __init__(self, **kwargs):
141136
self.deleted_time = None
142137
self.remaining_retention_days = None
143138

144-
@classmethod
145-
def _deserialize_dir_properties(cls, response, obj, headers):
146-
metadata = deserialize_metadata(response, obj, headers)
147-
dir_properties = cls(
148-
metadata=metadata,
149-
**headers
150-
)
151-
return dir_properties
152-
153139

154140
class FileProperties(DictMixin):
155141
"""
@@ -183,20 +169,6 @@ def __init__(self, **kwargs):
183169
self.remaining_retention_days = None
184170
self.content_settings = ContentSettings(**kwargs)
185171

186-
@classmethod
187-
def _deserialize_file_properties(cls, response, obj, headers):
188-
metadata = deserialize_metadata(response, obj, headers)
189-
file_properties = cls(
190-
metadata=metadata,
191-
**headers
192-
)
193-
if 'Content-Range' in headers:
194-
if 'x-ms-blob-content-md5' in headers:
195-
file_properties.content_settings.content_md5 = headers['x-ms-blob-content-md5']
196-
else:
197-
file_properties.content_settings.content_md5 = None
198-
return file_properties
199-
200172

201173
class PathProperties(object):
202174
"""Path properties listed by get_paths api.
@@ -242,68 +214,6 @@ def _from_generated(cls, generated):
242214
return path_prop
243215

244216

245-
class PathPropertiesPaged(PageIterator):
246-
"""An Iterable of Path properties.
247-
248-
:ivar str path: Filters the results to return only paths under the specified path.
249-
:ivar int results_per_page: The maximum number of results retrieved per API call.
250-
:ivar str continuation_token: The continuation token to retrieve the next page of results.
251-
:ivar list(~azure.storage.filedatalake.PathProperties) current_page: The current page of listed results.
252-
253-
:param callable command: Function to retrieve the next page of items.
254-
:param str path: Filters the results to return only paths under the specified path.
255-
:param int max_results: The maximum number of psths to retrieve per
256-
call.
257-
:param str continuation_token: An opaque continuation token.
258-
"""
259-
def __init__(
260-
self, command,
261-
recursive,
262-
path=None,
263-
max_results=None,
264-
continuation_token=None,
265-
upn=None):
266-
super(PathPropertiesPaged, self).__init__(
267-
get_next=self._get_next_cb,
268-
extract_data=self._extract_data_cb,
269-
continuation_token=continuation_token or ""
270-
)
271-
self._command = command
272-
self.recursive = recursive
273-
self.results_per_page = max_results
274-
self.path = path
275-
self.upn = upn
276-
self.current_page = None
277-
self.path_list = None
278-
279-
def _get_next_cb(self, continuation_token):
280-
try:
281-
return self._command(
282-
self.recursive,
283-
continuation=continuation_token or None,
284-
path=self.path,
285-
max_results=self.results_per_page,
286-
upn=self.upn,
287-
cls=return_headers_and_deserialized_path_list)
288-
except StorageErrorException as error:
289-
process_storage_error(error)
290-
291-
def _extract_data_cb(self, get_next_return):
292-
self.path_list, self._response = get_next_return
293-
self.current_page = [self._build_item(item) for item in self.path_list]
294-
295-
return self._response['continuation'] or None, self.current_page
296-
297-
@staticmethod
298-
def _build_item(item):
299-
if isinstance(item, PathProperties):
300-
return item
301-
if isinstance(item, Path):
302-
path = PathProperties._from_generated(item) # pylint: disable=protected-access
303-
return path
304-
return item
305-
306-
307217
class LeaseProperties(BlobLeaseProperties):
308218
"""DataLake Lease Properties.
309219

sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/_path_client.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ def __init__(
7979
# ADLS doesn't support secondary endpoint, make sure it's empty
8080
self._hosts[LocationMode.SECONDARY] = ""
8181
self._client = DataLakeStorageClient(self.url, file_system_name, path_name, pipeline=self._pipeline)
82+
self._datalake_client_for_blob_operation = DataLakeStorageClient(self._blob_client.url,
83+
file_system_name, path_name,
84+
pipeline=self._pipeline)
8285

8386
def __exit__(self, *args):
8487
self._blob_client.close()

sdk/storage/azure-storage-file-datalake/azure/storage/filedatalake/aio/_data_lake_directory_client_async.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from ._data_lake_file_client_async import DataLakeFileClient
99
from .._data_lake_directory_client import DataLakeDirectoryClient as DataLakeDirectoryClientBase
1010
from .._models import DirectoryProperties
11+
from .._deserialize import deserialize_dir_properties
1112
from ._path_client_async import PathClient
1213

1314

@@ -200,7 +201,7 @@ async def get_directory_properties(self, **kwargs):
200201
:dedent: 4
201202
:caption: Getting the properties for a file/directory.
202203
"""
203-
return await self._get_path_properties(cls=DirectoryProperties._deserialize_dir_properties, **kwargs) # pylint: disable=protected-access
204+
return await self._get_path_properties(cls=deserialize_dir_properties, **kwargs) # pylint: disable=protected-access
204205

205206
async def rename_directory(self, new_name, # type: str
206207
**kwargs):

0 commit comments

Comments
 (0)