Skip to content

Commit 3548859

Browse files
authored
[Storage] az storage entity: Support specifying EdmType for --entity (#22060)
* `az storage entity`: Support `EdmType` for `--entity` * fix azure_stack
1 parent efac3f9 commit 3548859

4 files changed

Lines changed: 230 additions & 222 deletions

File tree

src/azure-cli/azure/cli/command_modules/storage/_params_azure_stack.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from azure.cli.core.local_context import LocalContextAttribute, LocalContextAction, ALL
1111

1212
from ._validators import (get_datetime_type, validate_metadata, get_permission_validator, get_permission_help_string,
13-
resource_type_type, services_type, validate_entity, validate_select, validate_blob_type,
13+
resource_type_type, services_type, validate_select, validate_blob_type,
1414
validate_included_datasets, validate_custom_domain, validate_container_public_access,
1515
validate_table_payload_format, add_progress_callback, process_resource_group,
1616
storage_account_key_options, process_file_download_namespace, process_metric_update_namespace,
@@ -19,6 +19,7 @@
1919
validate_azcopy_remove_arguments, as_user_validator, parse_storage_account,
2020
validator_delete_retention_days, validate_delete_retention_days,
2121
validate_fs_public_access)
22+
from ._validators_azure_stack import validate_entity
2223

2324

2425
def load_arguments(self, _): # pylint: disable=too-many-locals, too-many-statements, too-many-lines

src/azure-cli/azure/cli/command_modules/storage/_validators.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,7 @@ def validate_entity(namespace):
676676
""" Converts a list of key value pairs into a dictionary. Ensures that required
677677
RowKey and PartitionKey are converted to the correct case and included. """
678678
values = dict(x.split('=', 1) for x in namespace.entity)
679+
edm_types = {}
679680
keys = values.keys()
680681
for key in list(keys):
681682
if key.lower() == 'rowkey':
@@ -686,6 +687,12 @@ def validate_entity(namespace):
686687
val = values[key]
687688
del values[key]
688689
values['PartitionKey'] = val
690+
elif key.endswith('@odata.type'):
691+
val = values[key]
692+
del values[key]
693+
real_key = key[0: key.index('@odata.type')]
694+
edm_types[real_key] = val
695+
689696
keys = values.keys()
690697
missing_keys = 'RowKey ' if 'RowKey' not in keys else ''
691698
missing_keys = '{}PartitionKey'.format(missing_keys) \
@@ -708,8 +715,12 @@ def try_cast(to_type):
708715

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

711-
# ensure numbers are converted from strings so querying will work correctly
712-
values = {key: cast_val(key, val) for key, val in values.items()}
718+
for key, val in values.items():
719+
if edm_types.get(key, None):
720+
values[key] = (val, edm_types[key])
721+
else:
722+
# ensure numbers are converted from strings so querying will work correctly
723+
values[key] = cast_val(key, val)
713724
namespace.entity = values
714725

715726

0 commit comments

Comments
 (0)