Skip to content

Commit

Permalink
Share Lease Feature (#13567)
Browse files Browse the repository at this point in the history
* added needed parameters for shares

* added async methods

* added more methods for interacting with the API

* fixed small mistake with elif

* added tests and access conditions

* added more tests for leases

* fixed tests

* async changes

* added await

* corrected import

* fixed async imports and wrote all tests

* linting

* share renaming

* added file lease sample

* added sample for share

* fixed samples

* added docs

* removed checks

* lease change

* lease change

* added correct lease durations

* removed spacing

* version correction

* fixed snapshot

* added snapshot tests

* added snapshot tests

* changed version

* test

* test

* more docstrings

* fixed docstrings

* more docstring changes

* removed etag

* added exta check on test

* fixed tests

* added more tests for file

* added tests for list shares

* unused import

* changed method signitures

* fixed kwargs

* linter

Co-authored-by: Xiaoxi Fu <49707495+xiafu-msft@users.noreply.github.com>
  • Loading branch information
tasherif-msft and xiafu-msft committed Oct 1, 2020
1 parent afcfc3e commit 0a9c740
Show file tree
Hide file tree
Showing 46 changed files with 15,323 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ interactions:
Content-Length:
- '0'
User-Agent:
- azsdk-python-storage-blob/12.0.0b5 Python/3.6.3 (Windows-10-10.0.18362-SP0)
- azsdk-python-storage-blob/12.4.0 Python/3.8.5 (Windows-10-10.0.19041-SP0)
x-ms-date:
- Fri, 25 Oct 2019 17:59:36 GMT
- Mon, 28 Sep 2020 14:59:47 GMT
x-ms-version:
- '2019-02-02'
- '2020-02-10'
method: PUT
uri: https://storagename.blob.core.windows.net/container73941128?restype=container
response:
Expand All @@ -25,15 +25,15 @@ interactions:
content-length:
- '0'
date:
- Fri, 25 Oct 2019 17:59:35 GMT
- Mon, 28 Sep 2020 14:59:47 GMT
etag:
- '"0x8D7597518ECA775"'
- '"0x8D863BF24A1824F"'
last-modified:
- Fri, 25 Oct 2019 17:59:36 GMT
- Mon, 28 Sep 2020 14:59:47 GMT
server:
- Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
x-ms-version:
- '2019-02-02'
- '2020-02-10'
status:
code: 201
message: Created
Expand All @@ -53,13 +53,13 @@ interactions:
If-None-Match:
- '*'
User-Agent:
- azsdk-python-storage-blob/12.0.0b5 Python/3.6.3 (Windows-10-10.0.18362-SP0)
- azsdk-python-storage-blob/12.4.0 Python/3.8.5 (Windows-10-10.0.19041-SP0)
x-ms-blob-type:
- BlockBlob
x-ms-date:
- Fri, 25 Oct 2019 17:59:36 GMT
- Mon, 28 Sep 2020 14:59:47 GMT
x-ms-version:
- '2019-02-02'
- '2020-02-10'
method: PUT
uri: https://storagename.blob.core.windows.net/container73941128/blob1
response:
Expand All @@ -71,19 +71,19 @@ interactions:
content-md5:
- XrY7u+Ae7tCTyyK7j1rNww==
date:
- Fri, 25 Oct 2019 17:59:35 GMT
- Mon, 28 Sep 2020 14:59:47 GMT
etag:
- '"0x8D7597518F66CB6"'
- '"0x8D863BF24BA54AE"'
last-modified:
- Fri, 25 Oct 2019 17:59:36 GMT
- Mon, 28 Sep 2020 14:59:47 GMT
server:
- Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
x-ms-content-crc64:
- vo7q9sPVKY0=
x-ms-request-server-encrypted:
- 'true'
x-ms-version:
- '2019-02-02'
- '2020-02-10'
status:
code: 201
message: Created
Expand All @@ -99,17 +99,17 @@ interactions:
Content-Length:
- '0'
User-Agent:
- azsdk-python-storage-blob/12.0.0b5 Python/3.6.3 (Windows-10-10.0.18362-SP0)
- azsdk-python-storage-blob/12.4.0 Python/3.8.5 (Windows-10-10.0.19041-SP0)
x-ms-date:
- Fri, 25 Oct 2019 17:59:36 GMT
- Mon, 28 Sep 2020 14:59:47 GMT
x-ms-lease-action:
- acquire
x-ms-lease-duration:
- '-1'
x-ms-proposed-lease-id:
- 7c0a3856-5a7b-41a9-b2ea-46c007922f6c
- 7252b40b-7746-4557-be21-82f42dd16067
x-ms-version:
- '2019-02-02'
- '2020-02-10'
method: PUT
uri: https://storagename.blob.core.windows.net/container73941128/blob1?comp=lease
response:
Expand All @@ -119,17 +119,17 @@ interactions:
content-length:
- '0'
date:
- Fri, 25 Oct 2019 17:59:35 GMT
- Mon, 28 Sep 2020 14:59:48 GMT
etag:
- '"0x8D7597518F66CB6"'
- '"0x8D863BF24BA54AE"'
last-modified:
- Fri, 25 Oct 2019 17:59:36 GMT
- Mon, 28 Sep 2020 14:59:47 GMT
server:
- Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
x-ms-lease-id:
- 7c0a3856-5a7b-41a9-b2ea-46c007922f6c
- 7252b40b-7746-4557-be21-82f42dd16067
x-ms-version:
- '2019-02-02'
- '2020-02-10'
status:
code: 201
message: Created
Expand All @@ -143,33 +143,33 @@ 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.4.0 Python/3.8.5 (Windows-10-10.0.19041-SP0)
x-ms-date:
- Fri, 25 Oct 2019 17:59:36 GMT
- Mon, 28 Sep 2020 14:59:48 GMT
x-ms-version:
- '2019-02-02'
- '2020-02-10'
method: GET
uri: https://storagename.blob.core.windows.net/container73941128?restype=container&comp=list
response:
body:
string: "\uFEFF<?xml version=\"1.0\" encoding=\"utf-8\"?><EnumerationResults
ServiceEndpoint=\"https://storagename.blob.core.windows.net/\" ContainerName=\"container73941128\"><Blobs><Blob><Name>blob1</Name><Properties><Creation-Time>Fri,
25 Oct 2019 17:59:36 GMT</Creation-Time><Last-Modified>Fri, 25 Oct 2019 17:59:36
GMT</Last-Modified><Etag>0x8D7597518F66CB6</Etag><Content-Length>11</Content-Length><Content-Type>application/octet-stream</Content-Type><Content-Encoding
ServiceEndpoint=\"https://storagename.blob.core.windows.net/\" ContainerName=\"container73941128\"><Blobs><Blob><Name>blob1</Name><Properties><Creation-Time>Mon,
28 Sep 2020 14:59:47 GMT</Creation-Time><Last-Modified>Mon, 28 Sep 2020 14:59:47
GMT</Last-Modified><Etag>0x8D863BF24BA54AE</Etag><Content-Length>11</Content-Length><Content-Type>application/octet-stream</Content-Type><Content-Encoding
/><Content-Language /><Content-CRC64 /><Content-MD5>XrY7u+Ae7tCTyyK7j1rNww==</Content-MD5><Cache-Control
/><Content-Disposition /><BlobType>BlockBlob</BlobType><AccessTier>Hot</AccessTier><AccessTierInferred>true</AccessTierInferred><LeaseStatus>locked</LeaseStatus><LeaseState>leased</LeaseState><LeaseDuration>infinite</LeaseDuration><ServerEncrypted>true</ServerEncrypted></Properties></Blob></Blobs><NextMarker
/></EnumerationResults>"
/><Content-Disposition /><LastAccessTime>Mon, 28 Sep 2020 14:59:47 GMT</LastAccessTime><BlobType>BlockBlob</BlobType><AccessTier>Hot</AccessTier><AccessTierInferred>true</AccessTierInferred><LeaseStatus>locked</LeaseStatus><LeaseState>leased</LeaseState><LeaseDuration>infinite</LeaseDuration><ServerEncrypted>true</ServerEncrypted></Properties><OrMetadata
/></Blob></Blobs><NextMarker /></EnumerationResults>"
headers:
content-type:
- application/xml
date:
- Fri, 25 Oct 2019 17:59:35 GMT
- Mon, 28 Sep 2020 14:59:48 GMT
server:
- Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
transfer-encoding:
- chunked
x-ms-version:
- '2019-02-02'
- '2020-02-10'
status:
code: 200
message: OK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def from_connection_string(

@distributed_trace
def acquire_lease(self, lease_id=None, **kwargs):
# type: (int, Optional[str], **Any) -> BlobLeaseClient
# type: (Optional[str], **Any) -> ShareLeaseClient
"""Requests a new lease.
If the file does not have an active lease, the File
Expand All @@ -283,13 +283,14 @@ def acquire_lease(self, lease_id=None, **kwargs):
.. admonition:: Example:
.. literalinclude:: ../samples/blob_samples_common.py
:start-after: [START acquire_lease_on_blob]
:end-before: [END acquire_lease_on_blob]
.. literalinclude:: ../samples/file_samples_client.py
:start-after: [START acquire_and_release_lease_on_file]
:end-before: [END acquire_and_release_lease_on_file]
:language: python
:dedent: 8
:caption: Acquiring a lease on a blob.
:dedent: 12
:caption: Acquiring a lease on a file.
"""
kwargs['lease_duration'] = -1
lease = ShareLeaseClient(self, lease_id=lease_id) # type: ignore
lease.acquire(**kwargs)
return lease
Expand Down

0 comments on commit 0a9c740

Please sign in to comment.