From 202daffd60f59f4d8164ffa499015dd204ed29a5 Mon Sep 17 00:00:00 2001 From: Willie Xu Date: Tue, 24 Apr 2018 21:33:54 -0700 Subject: [PATCH] fixed --marker param for storage entity query (#6210) --- .../azure-cli-storage/HISTORY.rst | 1 + .../cli/command_modules/storage/_help.py | 9 ++++++++ .../cli/command_modules/storage/_params.py | 3 ++- .../command_modules/storage/_validators.py | 21 +++++++++++++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/command_modules/azure-cli-storage/HISTORY.rst b/src/command_modules/azure-cli-storage/HISTORY.rst index 0f8983f7270..13f6abc28df 100644 --- a/src/command_modules/azure-cli-storage/HISTORY.rst +++ b/src/command_modules/azure-cli-storage/HISTORY.rst @@ -9,6 +9,7 @@ Release History * Expose --socket-timeout for blob uploads and downloads. * Treat blob names that start with path separators as relative paths. * `storage blob copy` Allow --source-sas with starting query char, '?' +* `storage entity query` Fix --marker to accept list of key=values. 2.0.31 ++++++ diff --git a/src/command_modules/azure-cli-storage/azure/cli/command_modules/storage/_help.py b/src/command_modules/azure-cli-storage/azure/cli/command_modules/storage/_help.py index f185373a813..e5a6555e426 100644 --- a/src/command_modules/azure-cli-storage/azure/cli/command_modules/storage/_help.py +++ b/src/command_modules/azure-cli-storage/azure/cli/command_modules/storage/_help.py @@ -477,6 +477,15 @@ helps['storage entity query'] = """ type: command short-summary: List entities which satisfy a query. + parameters: + - name: --marker + type: list + short-summary: Space-separated list of key=value pairs. Must contain a nextpartitionkey and a nextrowkey. + long-summary: This value can be retrieved from the + next_marker field of a previous generator object if max_results was + specified and that generator has finished enumerating results. If + specified, this generator will begin returning results from the + point where the previous generator stopped. """ helps['storage file'] = """ diff --git a/src/command_modules/azure-cli-storage/azure/cli/command_modules/storage/_params.py b/src/command_modules/azure-cli-storage/azure/cli/command_modules/storage/_params.py index 9b60e61cc20..fe6707e9829 100644 --- a/src/command_modules/azure-cli-storage/azure/cli/command_modules/storage/_params.py +++ b/src/command_modules/azure-cli-storage/azure/cli/command_modules/storage/_params.py @@ -12,7 +12,7 @@ validate_included_datasets, validate_custom_domain, validate_container_public_access, validate_table_payload_format, validate_key, add_progress_callback, storage_account_key_options, process_file_download_namespace, process_metric_update_namespace, - get_char_options_validator, validate_bypass, validate_encryption_source) + get_char_options_validator, validate_bypass, validate_encryption_source, validate_marker) def load_arguments(self, _): # pylint: disable=too-many-locals, too-many-statements @@ -699,3 +699,4 @@ def load_arguments(self, _): # pylint: disable=too-many-locals, too-many-statem c.argument('accept', default='minimal', validator=validate_table_payload_format, arg_type=get_enum_type(['none', 'minimal', 'full']), help='Specifies how much metadata to include in the response payload.') + c.argument('marker', validator=validate_marker, nargs='+') diff --git a/src/command_modules/azure-cli-storage/azure/cli/command_modules/storage/_validators.py b/src/command_modules/azure-cli-storage/azure/cli/command_modules/storage/_validators.py index d27368d855e..e8bcb64f50c 100644 --- a/src/command_modules/azure-cli-storage/azure/cli/command_modules/storage/_validators.py +++ b/src/command_modules/azure-cli-storage/azure/cli/command_modules/storage/_validators.py @@ -435,6 +435,27 @@ def try_cast(to_type): namespace.entity = values +def validate_marker(namespace): + """ Converts a list of key value pairs into a dictionary. Ensures that required + nextrowkey and nextpartitionkey are included. """ + marker = dict(x.split('=', 1) for x in namespace.marker) + expected_keys = {'nextrowkey', 'nextpartitionkey'} + + for key in marker: + new_key = key.lower() + if new_key in expected_keys: + expected_keys.remove(key.lower()) + val = marker[key] + del marker[key] + marker[new_key] = val + if expected_keys: + import argparse + raise argparse.ArgumentError( + None, 'incorrect usage: marker requires: {}'.format(' '.join(expected_keys))) + + namespace.marker = marker + + def get_file_path_validator(default_file_param=None): """ Creates a namespace validator that splits out 'path' into 'directory_name' and 'file_name'. Allows another path-type parameter to be named which can supply a default filename. """