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] az storage entity: Support specifying EdmType for --entity #22060

Merged
merged 2 commits into from
Apr 15, 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
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from azure.cli.core.local_context import LocalContextAttribute, LocalContextAction, ALL

from ._validators import (get_datetime_type, validate_metadata, get_permission_validator, get_permission_help_string,
resource_type_type, services_type, validate_entity, validate_select, validate_blob_type,
resource_type_type, services_type, validate_select, validate_blob_type,
validate_included_datasets, validate_custom_domain, validate_container_public_access,
validate_table_payload_format, add_progress_callback, process_resource_group,
storage_account_key_options, process_file_download_namespace, process_metric_update_namespace,
Expand All @@ -19,6 +19,7 @@
validate_azcopy_remove_arguments, as_user_validator, parse_storage_account,
validator_delete_retention_days, validate_delete_retention_days,
validate_fs_public_access)
from ._validators_azure_stack import validate_entity


def load_arguments(self, _): # pylint: disable=too-many-locals, too-many-statements, too-many-lines
Expand Down
15 changes: 13 additions & 2 deletions src/azure-cli/azure/cli/command_modules/storage/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,7 @@ def validate_entity(namespace):
""" Converts a list of key value pairs into a dictionary. Ensures that required
RowKey and PartitionKey are converted to the correct case and included. """
values = dict(x.split('=', 1) for x in namespace.entity)
edm_types = {}
keys = values.keys()
for key in list(keys):
if key.lower() == 'rowkey':
Expand All @@ -686,6 +687,12 @@ def validate_entity(namespace):
val = values[key]
del values[key]
values['PartitionKey'] = val
elif key.endswith('@odata.type'):
val = values[key]
del values[key]
real_key = key[0: key.index('@odata.type')]
edm_types[real_key] = val

keys = values.keys()
missing_keys = 'RowKey ' if 'RowKey' not in keys else ''
missing_keys = '{}PartitionKey'.format(missing_keys) \
Expand All @@ -708,8 +715,12 @@ def try_cast(to_type):

return try_cast(int) or try_cast(float) or val

# ensure numbers are converted from strings so querying will work correctly
values = {key: cast_val(key, val) for key, val in values.items()}
for key, val in values.items():
if edm_types.get(key, None):
values[key] = (val, edm_types[key])
else:
# ensure numbers are converted from strings so querying will work correctly
values[key] = cast_val(key, val)
namespace.entity = values


Expand Down
Loading