Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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