Skip to content

Commit

Permalink
[STG78]Address comments (#20539)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiafu-msft authored Sep 8, 2021
1 parent e089b1b commit 8be2477
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
)
from ._generated.models import (
RehydratePriority,
BlobImmutabilityPolicyMode
)
from ._models import (
BlobType,
BlockState,
StandardBlobTier,
PremiumPageBlobTier,
BlobImmutabilityPolicyMode,
SequenceNumberAction,
PublicAccess,
BlobAnalyticsLogging,
Expand Down
21 changes: 16 additions & 5 deletions sdk/storage/azure-storage-blob/azure/storage/blob/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,17 @@ class PublicAccess(str, Enum):
"""


class BlobImmutabilityPolicyMode(str, Enum):
"""
Specifies the immutability policy mode to set on the blob.
"Mutable" can only be returned by service, don't set to "Mutable".
"""

Unlocked = "Unlocked"
Locked = "Locked"
Mutable = "Mutable"


class BlobAnalyticsLogging(GeneratedLogging):
"""Azure Analytics Logging settings.
Expand Down Expand Up @@ -441,17 +452,17 @@ class ImmutabilityPolicy(DictMixin):
.. versionadded:: 12.10.0
This was introduced in API version '2020-10-02'.
:param ~datetime.datetime expiry_time:
:keyword ~datetime.datetime expiry_time:
Specifies the date time when the blobs immutability policy is set to expire.
:param str or ~azure.storage.blob.BlobImmutabilityPolicyMode policy_mode:
:keyword str or ~azure.storage.blob.BlobImmutabilityPolicyMode policy_mode:
Specifies the immutability policy mode to set on the blob.
Possible values to set include: "Locked", "Unlocked".
"Mutable" can only be returned by service, don't set to "Mutable".
"""

def __init__(self, expiry_time=None, policy_mode=None):
self.expiry_time = expiry_time
self.policy_mode = policy_mode
def __init__(self, **kwargs):
self.expiry_time = kwargs.pop('expiry_time', None)
self.policy_mode = kwargs.pop('policy_mode', None)

@classmethod
def _from_generated(cls, generated):
Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/azure-storage-blob/tests/test_append_blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -1363,7 +1363,7 @@ def test_create_append_blob_with_immutability_policy(self, resource_group, locat
blob = bsc.get_blob_client(container_name, blob_name)

immutability_policy = ImmutabilityPolicy(expiry_time=datetime.utcnow() + timedelta(seconds=5),
policy_mode=BlobImmutabilityPolicyMode.UNLOCKED)
policy_mode=BlobImmutabilityPolicyMode.Unlocked)
blob.create_append_blob(immutability_policy=immutability_policy,
legal_hold=True)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1446,7 +1446,7 @@ async def test_create_append_blob_with_immutability_policy_async(self, resource_
blob = bsc.get_blob_client(container_name, blob_name)

immutability_policy = ImmutabilityPolicy(expiry_time=datetime.utcnow() + timedelta(seconds=5),
policy_mode=BlobImmutabilityPolicyMode.UNLOCKED)
policy_mode=BlobImmutabilityPolicyMode.Unlocked)
await blob.create_append_blob(immutability_policy=immutability_policy,
legal_hold=True)

Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/azure-storage-blob/tests/test_block_blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ def test_put_block_with_immutability_policy(self, resource_group, location, stor
# Act
block_list = [BlobBlock(block_id='1'), BlobBlock(block_id='2'), BlobBlock(block_id='3')]
immutability_policy = ImmutabilityPolicy(expiry_time=datetime.utcnow() + timedelta(seconds=5),
policy_mode=BlobImmutabilityPolicyMode.UNLOCKED)
policy_mode=BlobImmutabilityPolicyMode.Unlocked)
put_block_list_resp = blob.commit_block_list(block_list,
immutability_policy=immutability_policy,
legal_hold=True,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ async def test_put_block_with_immutability_policy(self, resource_group, location
# Act
block_list = [BlobBlock(block_id='1'), BlobBlock(block_id='2'), BlobBlock(block_id='3')]
immutability_policy = ImmutabilityPolicy(expiry_time=datetime.utcnow() + timedelta(seconds=5),
policy_mode=BlobImmutabilityPolicyMode.UNLOCKED)
policy_mode=BlobImmutabilityPolicyMode.Unlocked)
put_block_list_resp = await blob.commit_block_list(block_list,
immutability_policy=immutability_policy,
legal_hold=True,
Expand Down
14 changes: 7 additions & 7 deletions sdk/storage/azure-storage-blob/tests/test_common_blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,7 @@ def test_copy_blob_with_immutability_policy(self, resource_group, location, stor

copyblob = self.bsc.get_blob_client(container_name, 'blob1copy')
immutability_policy = ImmutabilityPolicy(expiry_time=datetime.utcnow() + timedelta(seconds=5),
policy_mode=BlobImmutabilityPolicyMode.UNLOCKED)
policy_mode=BlobImmutabilityPolicyMode.Unlocked)
copy = copyblob.start_copy_from_url(sourceblob, immutability_policy=immutability_policy,
legal_hold=True,
)
Expand Down Expand Up @@ -1837,7 +1837,7 @@ def test_set_immutability_policy_using_sas(self, resource_group, location, stora
blob = BlobClient(
self.bsc.url, container_name= container_name, blob_name=blob_name, credential=account_sas_token)
immutability_policy = ImmutabilityPolicy(expiry_time=datetime.utcnow() + timedelta(seconds=5),
policy_mode=BlobImmutabilityPolicyMode.UNLOCKED)
policy_mode=BlobImmutabilityPolicyMode.Unlocked)
resp_with_account_sas = blob.set_immutability_policy(immutability_policy=immutability_policy)
blob_response = requests.get(blob.url)

Expand All @@ -1858,7 +1858,7 @@ def test_set_immutability_policy_using_sas(self, resource_group, location, stora
self.bsc.url, container_name=container_name, blob_name=blob_name, credential=container_sas_token)

immutability_policy = ImmutabilityPolicy(expiry_time=datetime.utcnow() + timedelta(seconds=5),
policy_mode=BlobImmutabilityPolicyMode.UNLOCKED)
policy_mode=BlobImmutabilityPolicyMode.Unlocked)
resp_with_container_sas = blob1.set_immutability_policy(immutability_policy=immutability_policy)
# Assert response using container sas
self.assertIsNotNone(resp_with_container_sas['immutability_policy_until_date'])
Expand All @@ -1876,7 +1876,7 @@ def test_set_immutability_policy_using_sas(self, resource_group, location, stora
blob2 = BlobClient(
self.bsc.url, container_name=container_name, blob_name=blob_name, credential=blob_sas_token)
immutability_policy = ImmutabilityPolicy(expiry_time=datetime.utcnow() + timedelta(seconds=5),
policy_mode=BlobImmutabilityPolicyMode.UNLOCKED)
policy_mode=BlobImmutabilityPolicyMode.Unlocked)
resp_with_blob_sas = blob2.set_immutability_policy(immutability_policy=immutability_policy)

# Assert response using blob sas
Expand Down Expand Up @@ -2586,7 +2586,7 @@ def test_blob_immutability_policy(self, resource_group, location, storage_accoun
blob = self.bsc.get_blob_client(container_name, blob_name)
blob.upload_blob(b"abc", overwrite=True)
immutability_policy = ImmutabilityPolicy(expiry_time=datetime.utcnow() + timedelta(seconds=5),
policy_mode=BlobImmutabilityPolicyMode.UNLOCKED)
policy_mode=BlobImmutabilityPolicyMode.Unlocked)
resp = blob.set_immutability_policy(immutability_policy=immutability_policy)

# Assert
Expand Down Expand Up @@ -2668,7 +2668,7 @@ def test_download_blob_with_immutability_policy(self, resource_group, location,
content = b"abcedfg"

immutability_policy = ImmutabilityPolicy(expiry_time=datetime.utcnow() + timedelta(seconds=5),
policy_mode=BlobImmutabilityPolicyMode.UNLOCKED)
policy_mode=BlobImmutabilityPolicyMode.Unlocked)
blob.upload_blob(content,
immutability_policy=immutability_policy,
legal_hold=True,
Expand Down Expand Up @@ -2710,7 +2710,7 @@ def test_list_blobs_with_immutability_policy(self, resource_group, location, sto
content = b"abcedfg"

immutability_policy = ImmutabilityPolicy(expiry_time=datetime.utcnow() + timedelta(seconds=5),
policy_mode=BlobImmutabilityPolicyMode.UNLOCKED)
policy_mode=BlobImmutabilityPolicyMode.Unlocked)
blob.upload_blob(content,immutability_policy=immutability_policy,
legal_hold=True,
overwrite=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1497,7 +1497,7 @@ async def test_copy_blob_with_immutability_policy(self, resource_group, location
copyblob = self.bsc.get_blob_client(container_name, 'blob1copy')

immutability_policy = ImmutabilityPolicy(expiry_time=datetime.utcnow() + timedelta(seconds=5),
policy_mode=BlobImmutabilityPolicyMode.UNLOCKED)
policy_mode=BlobImmutabilityPolicyMode.Unlocked)

copy = await copyblob.start_copy_from_url(sourceblob, immutability_policy=immutability_policy,
legal_hold=True,
Expand Down Expand Up @@ -2594,7 +2594,7 @@ async def test_blob_immutability_policy(self, resource_group, location, storage_
await blob.upload_blob(b"abc", overwrite=True)

immutability_policy = ImmutabilityPolicy(expiry_time=datetime.utcnow() + timedelta(seconds=5),
policy_mode=BlobImmutabilityPolicyMode.UNLOCKED)
policy_mode=BlobImmutabilityPolicyMode.Unlocked)
resp = await blob.set_immutability_policy(
immutability_policy=immutability_policy)

Expand Down Expand Up @@ -2677,7 +2677,7 @@ async def test_download_blob_with_immutability_policy(self, resource_group, loca
content = b"abcedfg"

immutability_policy = ImmutabilityPolicy(expiry_time=datetime.utcnow() + timedelta(seconds=5),
policy_mode=BlobImmutabilityPolicyMode.UNLOCKED)
policy_mode=BlobImmutabilityPolicyMode.Unlocked)
await blob.upload_blob(content,
immutability_policy=immutability_policy,
legal_hold=True,
Expand Down Expand Up @@ -2722,7 +2722,7 @@ async def test_list_blobs_with_immutability_policy(self, resource_group, locatio
content = b"abcedfg"

immutability_policy = ImmutabilityPolicy(expiry_time=datetime.utcnow() + timedelta(seconds=5),
policy_mode=BlobImmutabilityPolicyMode.UNLOCKED)
policy_mode=BlobImmutabilityPolicyMode.Unlocked)
await blob.upload_blob(content,
immutability_policy=immutability_policy,
legal_hold=True,
Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/azure-storage-blob/tests/test_page_blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def test_create_blob_with_immutability_policy(self, resource_group, location, st

# Act
immutability_policy = ImmutabilityPolicy(expiry_time=datetime.utcnow() + timedelta(seconds=5),
policy_mode=BlobImmutabilityPolicyMode.UNLOCKED)
policy_mode=BlobImmutabilityPolicyMode.Unlocked)
resp = blob.create_page_blob(1024, immutability_policy=immutability_policy,
legal_hold=True)
props = blob.get_blob_properties()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ async def test_create_blob_with_immutability_policy(self, resource_group, locati

# Act
immutability_policy = ImmutabilityPolicy(expiry_time=datetime.utcnow() + timedelta(seconds=5),
policy_mode=BlobImmutabilityPolicyMode.UNLOCKED)
policy_mode=BlobImmutabilityPolicyMode.Unlocked)
resp = await blob.create_page_blob(1024,
immutability_policy=immutability_policy,
legal_hold=True)
Expand Down

0 comments on commit 8be2477

Please sign in to comment.