Skip to content

Commit 59d05de

Browse files
authored
[Storage] az storage container policy create: No longer uses default value for start and expiry time (#23259)
* storage container policy create no longer use default value * lint * make url get request live only
1 parent 1236137 commit 59d05de

9 files changed

+1038
-829
lines changed

src/azure-cli/azure/cli/command_modules/storage/commands.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -490,18 +490,18 @@ def get_custom_sdk(custom_module, client_factory, resource_type=ResourceType.DAT
490490
g.storage_custom_command_oauth('generate-sas', 'generate_container_shared_access_signature')
491491
g.storage_command_oauth('restore', 'undelete_container', min_api='2020-02-10')
492492

493-
with self.command_group('storage container', resource_type=ResourceType.DATA_STORAGE_BLOB,
493+
with self.command_group('storage container policy', resource_type=ResourceType.DATA_STORAGE_BLOB,
494494
custom_command_type=get_custom_sdk('access_policy', client_factory=cf_container_client,
495495
resource_type=ResourceType.DATA_STORAGE_BLOB)) as g:
496496
from ._transformers import transform_acl_list_output, transform_acl_edit, transform_acl_datetime
497-
g.storage_custom_command_oauth('policy create', 'create_acl_policy', transform=transform_acl_edit)
498-
g.storage_custom_command_oauth('policy delete', 'delete_acl_policy', transform=transform_acl_edit)
497+
g.storage_custom_command_oauth('create', 'create_acl_policy', transform=transform_acl_edit)
498+
g.storage_custom_command_oauth('delete', 'delete_acl_policy', transform=transform_acl_edit)
499499
g.storage_custom_command_oauth(
500-
'policy update', 'set_acl_policy', transform=transform_acl_edit)
500+
'update', 'set_acl_policy', transform=transform_acl_edit)
501501
g.storage_custom_command_oauth(
502-
'policy show', 'get_acl_policy', transform=transform_acl_datetime, exception_handler=show_exception_handler)
502+
'show', 'get_acl_policy', transform=transform_acl_datetime, exception_handler=show_exception_handler)
503503
g.storage_custom_command_oauth(
504-
'policy list', 'list_acl_policies', table_transformer=transform_acl_list_output)
504+
'list', 'list_acl_policies', table_transformer=transform_acl_list_output)
505505

506506
blob_container_mgmt_sdk = CliCommandType(
507507
operations_tmpl='azure.mgmt.storage.operations#BlobContainersOperations.{}',

src/azure-cli/azure/cli/command_modules/storage/operations/access_policy.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,14 @@
33
# Licensed under the MIT License. See License.txt in the project root for license information.
44
# --------------------------------------------------------------------------------------------
55

6-
from datetime import datetime
76
from azure.cli.core.profiles import ResourceType
87

98

109
def create_acl_policy(cmd, client, policy_name, start=None, expiry=None, permission=None, **kwargs):
1110
"""Create a stored access policy on the containing object"""
1211
t_access_policy = cmd.get_models('_models#AccessPolicy', resource_type=ResourceType.DATA_STORAGE_BLOB)
1312
acl = _get_acl(cmd, client, **kwargs)
14-
acl[policy_name] = t_access_policy(permission if permission else '',
15-
expiry if expiry else datetime.max,
16-
start if start else datetime.utcnow())
13+
acl[policy_name] = t_access_policy(permission, expiry, start)
1714
if hasattr(acl, 'public_access'):
1815
kwargs['public_access'] = getattr(acl, 'public_access')
1916

@@ -40,9 +37,13 @@ def set_acl_policy(cmd, client, policy_name, start=None, expiry=None, permission
4037
acl = _get_acl(cmd, client, **kwargs)
4138
try:
4239
policy = acl[policy_name]
43-
policy.start = start if start else policy.start
44-
policy.expiry = expiry if expiry else policy.expiry
45-
policy.permission = permission or policy.permission
40+
if policy is None:
41+
t_access_policy = cmd.get_models('_models#AccessPolicy', resource_type=ResourceType.DATA_STORAGE_BLOB)
42+
acl[policy_name] = t_access_policy(permission, expiry, start)
43+
else:
44+
policy.start = start if start else policy.start
45+
policy.expiry = expiry if expiry else policy.expiry
46+
policy.permission = permission or policy.permission
4647
if hasattr(acl, 'public_access'):
4748
kwargs['public_access'] = getattr(acl, 'public_access')
4849

@@ -99,6 +100,8 @@ def convert_acl_permissions(result):
99100
signed_identifiers[identifier.id] = identifier.access_policy
100101
result = signed_identifiers
101102
for policy in sorted(result.keys()):
103+
if result[policy] is None:
104+
continue
102105
if getattr(result[policy], 'permission') is None:
103106
setattr(result[policy], 'permission', '')
104107
return result

0 commit comments

Comments
 (0)