Skip to content

Commit

Permalink
[Storage] az storage container policy create: No longer uses defaul…
Browse files Browse the repository at this point in the history
…t value for start and expiry time (#23259)

* storage container policy create no longer use default value

* lint

* make url get request live only
  • Loading branch information
calvinhzy authored Jul 21, 2022
1 parent 1236137 commit 59d05de
Show file tree
Hide file tree
Showing 9 changed files with 1,038 additions and 829 deletions.
12 changes: 6 additions & 6 deletions src/azure-cli/azure/cli/command_modules/storage/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,18 +490,18 @@ def get_custom_sdk(custom_module, client_factory, resource_type=ResourceType.DAT
g.storage_custom_command_oauth('generate-sas', 'generate_container_shared_access_signature')
g.storage_command_oauth('restore', 'undelete_container', min_api='2020-02-10')

with self.command_group('storage container', resource_type=ResourceType.DATA_STORAGE_BLOB,
with self.command_group('storage container policy', resource_type=ResourceType.DATA_STORAGE_BLOB,
custom_command_type=get_custom_sdk('access_policy', client_factory=cf_container_client,
resource_type=ResourceType.DATA_STORAGE_BLOB)) as g:
from ._transformers import transform_acl_list_output, transform_acl_edit, transform_acl_datetime
g.storage_custom_command_oauth('policy create', 'create_acl_policy', transform=transform_acl_edit)
g.storage_custom_command_oauth('policy delete', 'delete_acl_policy', transform=transform_acl_edit)
g.storage_custom_command_oauth('create', 'create_acl_policy', transform=transform_acl_edit)
g.storage_custom_command_oauth('delete', 'delete_acl_policy', transform=transform_acl_edit)
g.storage_custom_command_oauth(
'policy update', 'set_acl_policy', transform=transform_acl_edit)
'update', 'set_acl_policy', transform=transform_acl_edit)
g.storage_custom_command_oauth(
'policy show', 'get_acl_policy', transform=transform_acl_datetime, exception_handler=show_exception_handler)
'show', 'get_acl_policy', transform=transform_acl_datetime, exception_handler=show_exception_handler)
g.storage_custom_command_oauth(
'policy list', 'list_acl_policies', table_transformer=transform_acl_list_output)
'list', 'list_acl_policies', table_transformer=transform_acl_list_output)

blob_container_mgmt_sdk = CliCommandType(
operations_tmpl='azure.mgmt.storage.operations#BlobContainersOperations.{}',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from datetime import datetime
from azure.cli.core.profiles import ResourceType


def create_acl_policy(cmd, client, policy_name, start=None, expiry=None, permission=None, **kwargs):
"""Create a stored access policy on the containing object"""
t_access_policy = cmd.get_models('_models#AccessPolicy', resource_type=ResourceType.DATA_STORAGE_BLOB)
acl = _get_acl(cmd, client, **kwargs)
acl[policy_name] = t_access_policy(permission if permission else '',
expiry if expiry else datetime.max,
start if start else datetime.utcnow())
acl[policy_name] = t_access_policy(permission, expiry, start)
if hasattr(acl, 'public_access'):
kwargs['public_access'] = getattr(acl, 'public_access')

Expand All @@ -40,9 +37,13 @@ def set_acl_policy(cmd, client, policy_name, start=None, expiry=None, permission
acl = _get_acl(cmd, client, **kwargs)
try:
policy = acl[policy_name]
policy.start = start if start else policy.start
policy.expiry = expiry if expiry else policy.expiry
policy.permission = permission or policy.permission
if policy is None:
t_access_policy = cmd.get_models('_models#AccessPolicy', resource_type=ResourceType.DATA_STORAGE_BLOB)
acl[policy_name] = t_access_policy(permission, expiry, start)
else:
policy.start = start if start else policy.start
policy.expiry = expiry if expiry else policy.expiry
policy.permission = permission or policy.permission
if hasattr(acl, 'public_access'):
kwargs['public_access'] = getattr(acl, 'public_access')

Expand Down Expand Up @@ -99,6 +100,8 @@ def convert_acl_permissions(result):
signed_identifiers[identifier.id] = identifier.access_policy
result = signed_identifiers
for policy in sorted(result.keys()):
if result[policy] is None:
continue
if getattr(result[policy], 'permission') is None:
setattr(result[policy], 'permission', '')
return result
Expand Down
Loading

0 comments on commit 59d05de

Please sign in to comment.