Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Storage] Fix #20452: az storage container policy create\update\list\show\delete: Add new permissions, currently racwdxyltmei, Migrate to track2 sdk #21917

Merged
merged 24 commits into from
Jun 7, 2022
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
11 changes: 6 additions & 5 deletions src/azure-cli/azure/cli/command_modules/storage/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -1436,8 +1436,8 @@ def load_arguments(self, _): # pylint: disable=too-many-locals, too-many-statem

with self.argument_context('storage container policy') as c:
from .completers import get_storage_acl_name_completion_list
t_container_permissions = self.get_sdk('blob.models#ContainerPermissions')

t_container_permissions = self.get_sdk('_models#ContainerSasPermissions',
resource_type=ResourceType.DATA_STORAGE_BLOB)
c.argument('container_name', container_name_type)
c.argument('policy_name', options_list=('--name', '-n'), help='The stored access policy name.',
completer=get_storage_acl_name_completion_list(t_base_blob_service, 'container_name',
Expand All @@ -1446,13 +1446,14 @@ def load_arguments(self, _): # pylint: disable=too-many-locals, too-many-statem
c.argument('permission', options_list='--permissions', help=help_str,
validator=get_permission_validator(t_container_permissions))

c.argument('start', type=get_datetime_type(True),
c.argument('start', type=get_datetime_type(False),
help='start UTC datetime (Y-m-d\'T\'H:M:S\'Z\'). Defaults to time of request.')
c.argument('expiry', type=get_datetime_type(True), help='expiration UTC datetime in (Y-m-d\'T\'H:M:S\'Z\')')
c.argument('expiry', type=get_datetime_type(False), help='expiration UTC datetime in (Y-m-d\'T\'H:M:S\'Z\')')

for item in ['create', 'delete', 'list', 'show', 'update']:
with self.argument_context('storage container policy {}'.format(item)) as c:
c.extra('lease_id', options_list='--lease-id', help='The container lease ID.')
c.extra('container_name', container_name_type, required=True)
c.extra('lease', options_list='--lease-id', help='The container lease ID.')

with self.argument_context('storage container generate-sas', resource_type=ResourceType.DATA_STORAGE_BLOB) as c:
from .completers import get_storage_acl_name_completion_list
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,21 @@ def transform_acl_list_output(result):
return new_result


def transform_acl_edit(result):
if "last_modified" in result.keys():
result["lastModified"] = result.pop("last_modified")
return result


def transform_acl_datetime(result):
result = todict(result)
if result['start']:
result['start'] = result["start"].split('.')[0] + '+00:00'
if result['expiry']:
result['expiry'] = result["expiry"].split('.')[0] + '+00:00'
return result


def transform_container_permission_output(result):
return {'publicAccess': result.get('public_access', None) or 'off'}

Expand Down
15 changes: 8 additions & 7 deletions src/azure-cli/azure/cli/command_modules/storage/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,15 +510,16 @@ 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', command_type=block_blob_sdk,
custom_command_type=get_custom_sdk('acl', blob_data_service_factory)) as g:
from azure.cli.command_modules.storage._transformers import transform_acl_list_output
g.storage_custom_command_oauth('policy create', 'create_acl_policy')
g.storage_custom_command_oauth('policy delete', 'delete_acl_policy')
with self.command_group('storage container', 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(
'policy update', 'set_acl_policy', min_api='2017-04-17')
'policy update', 'set_acl_policy', transform=transform_acl_edit)
g.storage_custom_command_oauth(
'policy show', 'get_acl_policy', exception_handler=show_exception_handler)
'policy 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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ 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 or policy.start
policy.expiry = expiry or policy.expiry
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 @@ -93,6 +93,11 @@ def _get_acl(cmd, client, **kwargs):
def convert_acl_permissions(result):
if result is None:
return None
if 'signed_identifiers' in result:
signed_identifiers = {}
for identifier in result["signed_identifiers"]:
signed_identifiers[identifier.id] = identifier.access_policy
result = signed_identifiers
for policy in sorted(result.keys()):
if getattr(result[policy], 'permission') is None:
setattr(result[policy], 'permission', '')
Expand Down

Large diffs are not rendered by default.

Loading