Skip to content

Commit

Permalink
[Storage] az storage entity: Support specifying EdmType for `--en…
Browse files Browse the repository at this point in the history
…tity` (#22060)

* `az storage entity`: Support `EdmType` for `--entity`

* fix azure_stack
  • Loading branch information
evelyn-ys authored Apr 15, 2022
1 parent efac3f9 commit 3548859
Show file tree
Hide file tree
Showing 4 changed files with 230 additions and 222 deletions.
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

0 comments on commit 3548859

Please sign in to comment.