Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
02fbfe0
generated HNS soft delete
tasherif-msft Mar 27, 2021
19151c8
undelete_path
xiafu-msft Dec 9, 2020
b2c2f30
deleted list_paths and config_async
tasherif-msft Mar 27, 2021
cec6acd
lint
tasherif-msft Mar 27, 2021
d06f730
linter
tasherif-msft Mar 27, 2021
54fec42
Added get/set props
tasherif-msft Dec 10, 2020
2b58365
recorded tests and added models
tasherif-msft Dec 10, 2020
1bd0bd7
added async prefix
tasherif-msft Mar 27, 2021
be1ffa3
recorded async tests for get and set props
tasherif-msft Dec 10, 2020
3cdf4b0
removed preprod from yaml files
tasherif-msft Dec 10, 2020
6f272ec
removed preprod from yaml files
tasherif-msft Dec 10, 2020
2126c36
cleaned up model name
tasherif-msft Dec 10, 2020
11ff124
cleaned up model name
tasherif-msft Dec 10, 2020
f42c414
added path helpers
tasherif-msft Dec 11, 2020
c9aecb5
fixed preprod
tasherif-msft Dec 11, 2020
640f1b9
added the deserialize method for deleted paths
tasherif-msft Dec 13, 2020
c47006a
added get deleted Paths
tasherif-msft Dec 13, 2020
a48bb0d
renamed models
tasherif-msft Dec 13, 2020
4960e52
fixed delete directory failing tests
tasherif-msft Dec 13, 2020
0d84bc5
fixed recording for get_deleted_paths
tasherif-msft Dec 13, 2020
eb7b3a1
fixed tests
tasherif-msft Dec 13, 2020
177202a
fixed tests
tasherif-msft Dec 13, 2020
06b6645
rename
tasherif-msft Dec 13, 2020
f0f2787
linter
tasherif-msft Dec 14, 2020
5dfe7e7
linter
tasherif-msft Dec 14, 2020
ba998bb
typing
xiafu-msft Dec 14, 2020
3beb52b
cleaned up
tasherif-msft Dec 14, 2020
364753c
renamed and cleaned up
tasherif-msft Dec 14, 2020
78e0fdb
linter and rename
tasherif-msft Dec 14, 2020
9bf3d8b
linter
tasherif-msft Dec 14, 2020
ef01380
added test
tasherif-msft Dec 15, 2020
434c938
rename deleted_path_version to deletion_id
xiafu-msft Jan 13, 2021
5b703ec
Fixed dir prefix issue
tasherif-msft Jan 27, 2021
e51706b
Fixed directory prefix issue
tasherif-msft Jan 27, 2021
eb54d50
renamed deser
tasherif-msft Jan 27, 2021
05b2ccd
reset testcase
tasherif-msft Jan 27, 2021
d22a1b8
removed whl
tasherif-msft Jan 27, 2021
7fc7a09
fixed pos arg
tasherif-msft Mar 29, 2021
72bcb24
fixed retention
tasherif-msft Mar 29, 2021
1c099e9
fixed docstrings
tasherif-msft Mar 29, 2021
0f42518
fixed test failures
tasherif-msft Mar 29, 2021
0caf7dd
added new header to detect file or dir
tasherif-msft Apr 6, 2021
7efda6b
cleanup
tasherif-msft Apr 6, 2021
ff8c4b8
fixed tests
tasherif-msft Apr 6, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,23 @@ interactions:
Content-Type:
- application/xml; charset=utf-8
User-Agent:
- azsdk-python-storage-blob/12.0.0b5 Python/3.6.3 (Windows-10-10.0.18362-SP0)
- azsdk-python-storage-blob/12.6.1 Python/3.8.5 (Windows-10-10.0.19041-SP0)
x-ms-date:
- Fri, 25 Oct 2019 17:53:54 GMT
- Thu, 10 Dec 2020 17:24:15 GMT
x-ms-version:
- '2019-02-02'
- '2020-04-08'
method: PUT
uri: https://storagename.blob.core.windows.net/?restype=service&comp=properties
response:
body:
string: ''
headers:
content-length:
- '0'
date:
- Fri, 25 Oct 2019 17:53:53 GMT
server:
- Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
- Thu, 10 Dec 2020 17:24:19 GMT
transfer-encoding:
- chunked
x-ms-version:
- '2019-02-02'
- '2020-04-08'
status:
code: 202
message: Accepted
Expand All @@ -48,30 +46,28 @@ interactions:
Connection:
- keep-alive
User-Agent:
- azsdk-python-storage-blob/12.0.0b5 Python/3.6.3 (Windows-10-10.0.18362-SP0)
- azsdk-python-storage-blob/12.6.1 Python/3.8.5 (Windows-10-10.0.19041-SP0)
x-ms-date:
- Fri, 25 Oct 2019 17:53:54 GMT
- Thu, 10 Dec 2020 17:24:25 GMT
x-ms-version:
- '2019-02-02'
- '2020-04-08'
method: GET
uri: https://storagename.blob.core.windows.net/?restype=service&comp=properties
response:
body:
string: "\uFEFF<?xml version=\"1.0\" encoding=\"utf-8\"?><StorageServiceProperties><Logging><Version>1.0</Version><Read>true</Read><Write>true</Write><Delete>true</Delete><RetentionPolicy><Enabled>true</Enabled><Days>5</Days></RetentionPolicy></Logging><HourMetrics><Version>1.0</Version><Enabled>true</Enabled><IncludeAPIs>true</IncludeAPIs><RetentionPolicy><Enabled>true</Enabled><Days>5</Days></RetentionPolicy></HourMetrics><MinuteMetrics><Version>1.0</Version><Enabled>true</Enabled><IncludeAPIs>true</IncludeAPIs><RetentionPolicy><Enabled>true</Enabled><Days>5</Days></RetentionPolicy></MinuteMetrics><Cors><CorsRule><AllowedMethods>GET</AllowedMethods><AllowedOrigins>www.xyz.com</AllowedOrigins><AllowedHeaders
/><ExposedHeaders /><MaxAgeInSeconds>0</MaxAgeInSeconds></CorsRule><CorsRule><AllowedMethods>GET,PUT</AllowedMethods><AllowedOrigins>www.xyz.com,www.ab.com,www.bc.com</AllowedOrigins><AllowedHeaders>x-ms-meta-xyz,x-ms-meta-foo,x-ms-meta-data*,x-ms-meta-target*</AllowedHeaders><ExposedHeaders>x-ms-meta-abc,x-ms-meta-bcd,x-ms-meta-data*,x-ms-meta-source*</ExposedHeaders><MaxAgeInSeconds>500</MaxAgeInSeconds></CorsRule></Cors><DeleteRetentionPolicy><Enabled>false</Enabled></DeleteRetentionPolicy><StaticWebsite><Enabled>true</Enabled><IndexDocument>index.html</IndexDocument></StaticWebsite><DefaultServiceVersion>2014-02-14</DefaultServiceVersion></StorageServiceProperties>"
string: "\uFEFF<?xml version=\"1.0\" encoding=\"utf-8\"?><StorageServiceProperties><Logging><Version>1.0</Version><Read>false</Read><Write>false</Write><Delete>false</Delete><RetentionPolicy><Enabled>false</Enabled></RetentionPolicy></Logging><HourMetrics><Version>1.0</Version><Enabled>true</Enabled><IncludeAPIs>true</IncludeAPIs><RetentionPolicy><Enabled>true</Enabled><Days>7</Days></RetentionPolicy></HourMetrics><MinuteMetrics><Version>1.0</Version><Enabled>false</Enabled><RetentionPolicy><Enabled>false</Enabled></RetentionPolicy></MinuteMetrics><Cors><CorsRule><AllowedMethods>GET</AllowedMethods><AllowedOrigins>www.xyz.com</AllowedOrigins><AllowedHeaders
/><ExposedHeaders /><MaxAgeInSeconds>0</MaxAgeInSeconds></CorsRule><CorsRule><AllowedMethods>GET,PUT</AllowedMethods><AllowedOrigins>www.xyz.com,www.ab.com,www.bc.com</AllowedOrigins><AllowedHeaders>x-ms-meta-xyz,x-ms-meta-foo,x-ms-meta-data*,x-ms-meta-target*</AllowedHeaders><ExposedHeaders>x-ms-meta-abc,x-ms-meta-bcd,x-ms-meta-data*,x-ms-meta-source*</ExposedHeaders><MaxAgeInSeconds>500</MaxAgeInSeconds></CorsRule></Cors><DeleteRetentionPolicy><Enabled>false</Enabled><AllowPermanentDelete>false</AllowPermanentDelete></DeleteRetentionPolicy><StaticWebsite><Enabled>false</Enabled></StaticWebsite></StorageServiceProperties>"
headers:
content-type:
- application/xml
date:
- Fri, 25 Oct 2019 17:53:53 GMT
server:
- Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
- Thu, 10 Dec 2020 17:24:27 GMT
transfer-encoding:
- chunked
vary:
- Origin
x-ms-version:
- '2019-02-02'
- '2020-04-08'
status:
code: 200
message: OK
Expand All @@ -91,25 +87,23 @@ interactions:
Content-Type:
- application/xml; charset=utf-8
User-Agent:
- azsdk-python-storage-blob/12.0.0b5 Python/3.6.3 (Windows-10-10.0.18362-SP0)
- azsdk-python-storage-blob/12.6.1 Python/3.8.5 (Windows-10-10.0.19041-SP0)
x-ms-date:
- Fri, 25 Oct 2019 17:53:54 GMT
- Thu, 10 Dec 2020 17:46:46 GMT
x-ms-version:
- '2019-02-02'
- '2020-04-08'
method: PUT
uri: https://storagename.blob.core.windows.net/?restype=service&comp=properties
response:
body:
string: ''
headers:
content-length:
- '0'
date:
- Fri, 25 Oct 2019 17:53:54 GMT
server:
- Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
- Thu, 10 Dec 2020 17:46:49 GMT
transfer-encoding:
- chunked
x-ms-version:
- '2019-02-02'
- '2020-04-08'
status:
code: 202
message: Accepted
Expand All @@ -123,30 +117,28 @@ interactions:
Connection:
- keep-alive
User-Agent:
- azsdk-python-storage-blob/12.0.0b5 Python/3.6.3 (Windows-10-10.0.18362-SP0)
- azsdk-python-storage-blob/12.6.1 Python/3.8.5 (Windows-10-10.0.19041-SP0)
x-ms-date:
- Fri, 25 Oct 2019 17:53:54 GMT
- Thu, 10 Dec 2020 17:46:49 GMT
x-ms-version:
- '2019-02-02'
- '2020-04-08'
method: GET
uri: https://storagename.blob.core.windows.net/?restype=service&comp=properties
response:
body:
string: "\uFEFF<?xml version=\"1.0\" encoding=\"utf-8\"?><StorageServiceProperties><Logging><Version>1.0</Version><Read>true</Read><Write>true</Write><Delete>true</Delete><RetentionPolicy><Enabled>true</Enabled><Days>5</Days></RetentionPolicy></Logging><HourMetrics><Version>1.0</Version><Enabled>true</Enabled><IncludeAPIs>true</IncludeAPIs><RetentionPolicy><Enabled>true</Enabled><Days>5</Days></RetentionPolicy></HourMetrics><MinuteMetrics><Version>1.0</Version><Enabled>true</Enabled><IncludeAPIs>true</IncludeAPIs><RetentionPolicy><Enabled>true</Enabled><Days>5</Days></RetentionPolicy></MinuteMetrics><Cors><CorsRule><AllowedMethods>GET</AllowedMethods><AllowedOrigins>www.xyz.com</AllowedOrigins><AllowedHeaders
/><ExposedHeaders /><MaxAgeInSeconds>0</MaxAgeInSeconds></CorsRule><CorsRule><AllowedMethods>GET,PUT</AllowedMethods><AllowedOrigins>www.xyz.com,www.ab.com,www.bc.com</AllowedOrigins><AllowedHeaders>x-ms-meta-xyz,x-ms-meta-foo,x-ms-meta-data*,x-ms-meta-target*</AllowedHeaders><ExposedHeaders>x-ms-meta-abc,x-ms-meta-bcd,x-ms-meta-data*,x-ms-meta-source*</ExposedHeaders><MaxAgeInSeconds>500</MaxAgeInSeconds></CorsRule></Cors><DeleteRetentionPolicy><Enabled>false</Enabled></DeleteRetentionPolicy><StaticWebsite><Enabled>true</Enabled><IndexDocument>index.html</IndexDocument><ErrorDocument404Path>errors/error/404error.html</ErrorDocument404Path></StaticWebsite><DefaultServiceVersion>2014-02-14</DefaultServiceVersion></StorageServiceProperties>"
string: "\uFEFF<?xml version=\"1.0\" encoding=\"utf-8\"?><StorageServiceProperties><Logging><Version>1.0</Version><Read>false</Read><Write>false</Write><Delete>false</Delete><RetentionPolicy><Enabled>false</Enabled></RetentionPolicy></Logging><HourMetrics><Version>1.0</Version><Enabled>true</Enabled><IncludeAPIs>true</IncludeAPIs><RetentionPolicy><Enabled>true</Enabled><Days>7</Days></RetentionPolicy></HourMetrics><MinuteMetrics><Version>1.0</Version><Enabled>false</Enabled><RetentionPolicy><Enabled>false</Enabled></RetentionPolicy></MinuteMetrics><Cors><CorsRule><AllowedMethods>GET</AllowedMethods><AllowedOrigins>www.xyz.com</AllowedOrigins><AllowedHeaders
/><ExposedHeaders /><MaxAgeInSeconds>0</MaxAgeInSeconds></CorsRule><CorsRule><AllowedMethods>GET,PUT</AllowedMethods><AllowedOrigins>www.xyz.com,www.ab.com,www.bc.com</AllowedOrigins><AllowedHeaders>x-ms-meta-xyz,x-ms-meta-foo,x-ms-meta-data*,x-ms-meta-target*</AllowedHeaders><ExposedHeaders>x-ms-meta-abc,x-ms-meta-bcd,x-ms-meta-data*,x-ms-meta-source*</ExposedHeaders><MaxAgeInSeconds>500</MaxAgeInSeconds></CorsRule></Cors><DeleteRetentionPolicy><Enabled>false</Enabled><AllowPermanentDelete>false</AllowPermanentDelete></DeleteRetentionPolicy><StaticWebsite><Enabled>true</Enabled><IndexDocument>index.html</IndexDocument><ErrorDocument404Path>errors/error/404error.html</ErrorDocument404Path></StaticWebsite></StorageServiceProperties>"
headers:
content-type:
- application/xml
date:
- Fri, 25 Oct 2019 17:53:54 GMT
server:
- Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
- Thu, 10 Dec 2020 17:46:50 GMT
transfer-encoding:
- chunked
vary:
- Origin
x-ms-version:
- '2019-02-02'
- '2020-04-08'
status:
code: 200
message: OK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
AccessControlChangeCounters,
AccessControlChangeFailure,
AccessControlChanges,
AnalyticsLogging,
Metrics,
RetentionPolicy,
StaticWebsite,
CorsRule
)

from ._shared_access_signature import generate_account_sas, generate_file_system_sas, generate_directory_sas, \
Expand Down Expand Up @@ -87,5 +92,10 @@
'DataLakeFileQueryError',
'ArrowDialect',
'ArrowType',
'DataLakeFileQueryError'
'DataLakeFileQueryError',
'AnalyticsLogging',
'Metrics',
'RetentionPolicy',
'StaticWebsite',
'CorsRule'
]
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
from typing import Any
from typing import Optional, List, Dict, Any

try:
from urllib.parse import urlparse
Expand All @@ -15,10 +15,12 @@

from azure.storage.blob import BlobServiceClient
from ._shared.base_client import TransportWrapper, StorageAccountHostsMixin, parse_query, parse_connection_str
from ._deserialize import get_datalake_service_properties
from ._file_system_client import FileSystemClient
from ._data_lake_directory_client import DataLakeDirectoryClient
from ._data_lake_file_client import DataLakeFileClient
from ._models import UserDelegationKey, FileSystemPropertiesPaged, LocationMode
from ._models import UserDelegationKey, FileSystemPropertiesPaged, LocationMode, AnalyticsLogging, \
CorsRule, RetentionPolicy, StaticWebsite, Metrics
from ._serialize import convert_dfs_url_to_blob_url


Expand Down Expand Up @@ -462,7 +464,7 @@ def get_file_client(self, file_system, # type: Union[FileSystemProperties, str]
or an instance of FileProperties. eg. directory/subdirectory/file
:type file_path: str or ~azure.storage.filedatalake.FileProperties
:returns: A DataLakeFileClient.
:rtype: ~azure.storage.filedatalake..DataLakeFileClient
:rtype: ~azure.storage.filedatalake.DataLakeFileClient

.. admonition:: Example:

Expand Down Expand Up @@ -492,3 +494,80 @@ def get_file_client(self, file_system, # type: Union[FileSystemProperties, str]
require_encryption=self.require_encryption,
key_encryption_key=self.key_encryption_key,
key_resolver_function=self.key_resolver_function)

def set_service_properties(
self, analytics_logging=None, # type: Optional[AnalyticsLogging]
hour_metrics=None, # type: Optional[Metrics]
minute_metrics=None, # type: Optional[Metrics]
cors=None, # type: Optional[List[CorsRule]]
target_version=None, # type: Optional[str]
delete_retention_policy=None, # type: Optional[RetentionPolicy]
static_website=None, # type: Optional[StaticWebsite]
**kwargs
):
# type: (...) -> None
"""Sets the properties of a storage account's Datalake service, including
Azure Storage Analytics.

.. versionadded:: 12.4.0
This operation was introduced in API version '2020-06-12'.

If an element (e.g. analytics_logging) is left as None, the
existing settings on the service for that functionality are preserved.

:param analytics_logging:
Groups the Azure Analytics Logging settings.
:type analytics_logging: ~azure.storage.filedatalake.AnalyticsLogging
:param hour_metrics:
The hour metrics settings provide a summary of request
statistics grouped by API in hourly aggregates.
:type hour_metrics: ~azure.storage.filedatalake.Metrics
:param minute_metrics:
The minute metrics settings provide request statistics
for each minute.
:type minute_metrics: ~azure.storage.filedatalake.Metrics
:param cors:
You can include up to five CorsRule elements in the
list. If an empty list is specified, all CORS rules will be deleted,
and CORS will be disabled for the service.
:type cors: list[~azure.storage.filedatalake.CorsRule]
:param str target_version:
Indicates the default version to use for requests if an incoming
request's version is not specified.
:param delete_retention_policy:
The delete retention policy specifies whether to retain deleted files/directories.
It also specifies the number of days and versions of file/directory to keep.
:type delete_retention_policy: ~azure.storage.filedatalake.RetentionPolicy
:param static_website:
Specifies whether the static website feature is enabled,
and if yes, indicates the index document and 404 error document to use.
:type static_website: ~azure.storage.filedatalake.StaticWebsite
:keyword int timeout:
The timeout parameter is expressed in seconds.
:rtype: None
"""
return self._blob_service_client.set_service_properties(analytics_logging=analytics_logging,
hour_metrics=hour_metrics,
minute_metrics=minute_metrics,
cors=cors,
target_version=target_version,
delete_retention_policy=delete_retention_policy,
static_website=static_website,
**kwargs) # pylint: disable=protected-access

def get_service_properties(self, **kwargs):
# type: (Any) -> Dict[str, Any]
"""Gets the properties of a storage account's datalake service, including
Azure Storage Analytics.

.. versionadded:: 12.4.0
This operation was introduced in API version '2020-06-12'.

:keyword int timeout:
The timeout parameter is expressed in seconds.
:returns: An object containing datalake service properties such as
analytics logging, hour/minute metrics, cors rules, etc.
:rtype: Dict[str, Any]
"""
props = self._blob_service_client.get_service_properties(**kwargs) # pylint: disable=protected-access
return get_datalake_service_properties(props)
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
from azure.core.pipeline.policies import ContentDecodePolicy
from azure.core.exceptions import HttpResponseError, DecodeError, ResourceModifiedError, ClientAuthenticationError, \
ResourceNotFoundError, ResourceExistsError
from ._models import FileProperties, DirectoryProperties, LeaseProperties, PathProperties
from ._models import FileProperties, DirectoryProperties, LeaseProperties, DeletedPathProperties, StaticWebsite, \
RetentionPolicy, Metrics, AnalyticsLogging, PathProperties # pylint: disable=protected-access
from ._shared.models import StorageErrorCode

if TYPE_CHECKING:
Expand Down Expand Up @@ -48,6 +49,34 @@ def deserialize_path_properties(path_list):
return [PathProperties._from_generated(path) for path in path_list] # pylint: disable=protected-access


def get_deleted_path_properties_from_generated_code(generated):
deleted_path = DeletedPathProperties()
deleted_path.name = generated.name
deleted_path.deleted_time = generated.properties.deleted_time
deleted_path.remaining_retention_days = generated.properties.remaining_retention_days
deleted_path.deletion_id = generated.deletion_id
return deleted_path


def is_file_path(_, __, headers):
if headers['x-ms-resource-type'] == "file":
return True
return False


def get_datalake_service_properties(datalake_properties):
datalake_properties["analytics_logging"] = AnalyticsLogging._from_generated( # pylint: disable=protected-access
datalake_properties["analytics_logging"])
datalake_properties["hour_metrics"] = Metrics._from_generated(datalake_properties["hour_metrics"]) # pylint: disable=protected-access
datalake_properties["minute_metrics"] = Metrics._from_generated( # pylint: disable=protected-access
datalake_properties["minute_metrics"])
datalake_properties["delete_retention_policy"] = RetentionPolicy._from_generated( # pylint: disable=protected-access
datalake_properties["delete_retention_policy"])
datalake_properties["static_website"] = StaticWebsite._from_generated( # pylint: disable=protected-access
datalake_properties["static_website"])
return datalake_properties


def from_blob_properties(blob_properties):
file_props = FileProperties()
file_props.name = blob_properties.name
Expand All @@ -64,6 +93,7 @@ def from_blob_properties(blob_properties):
file_props.content_settings = blob_properties.content_settings
return file_props


def normalize_headers(headers):
normalized = {}
for key, value in headers.items():
Expand Down
Loading