Skip to content
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 @@ -267,3 +267,27 @@ def cf_adls_file(cli_ctx, kwargs):

def cf_or_policy(cli_ctx, _):
return storage_client_factory(cli_ctx).object_replication_policies


def cf_queue_service(cli_ctx, kwargs):
from knack.util import CLIError
t_queue_service = get_sdk(cli_ctx, ResourceType.DATA_STORAGE_QUEUE, '_queue_service_client#QueueServiceClient')
connection_string = kwargs.pop('connection_string', None)
account_name = kwargs.pop('account_name', None)
account_key = kwargs.pop('account_key', None)
token_credential = kwargs.pop('token_credential', None)
sas_token = kwargs.pop('sas_token', None)
if connection_string:
return t_queue_service.from_connection_string(conn_str=connection_string)

account_url = get_account_url(cli_ctx, account_name=account_name, service='queue')
credential = account_key or sas_token or token_credential

if account_url and credential:
return t_queue_service(account_url=account_url, credential=credential)
raise CLIError("Please provide valid connection string, or account name with account key, "
"sas token or login auth mode.")


def cf_queue_client(cli_ctx, kwargs):
return cf_queue_service(cli_ctx, kwargs).get_queue_client(queue=kwargs.pop('queue_name'))
12 changes: 3 additions & 9 deletions src/azure-cli/azure/cli/command_modules/storage/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -2028,6 +2028,9 @@
helps['storage queue list'] = """
type: command
short-summary: List queues in a storage account.
examples:
- name: List queues whose names begin with 'myprefix' under the storage account 'mystorageaccount'(account name)
text: az storage queue list --prefix myprefix --account-name mystorageaccount
"""

helps['storage queue metadata'] = """
Expand Down Expand Up @@ -2247,12 +2250,3 @@
type: group
short-summary: Manage shared access policies of a storage table.
"""

Comment thread
Juliehzl marked this conversation as resolved.
helps['storage queue'] = """
type: group
short-summary: Manage shared access policies of a storage table.
long-summary: >
Please specify one of the following authentication parameters for your commands: --auth-mode, --account-key,
--connection-string, --sas-token. You also can use corresponding environment variables to store your authentication
credentials, e.g. AZURE_STORAGE_KEY, AZURE_STORAGE_CONNECTION_STRING and AZURE_STORAGE_SAS_TOKEN.
"""
10 changes: 10 additions & 0 deletions src/azure-cli/azure/cli/command_modules/storage/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -1341,6 +1341,16 @@ def load_arguments(self, _): # pylint: disable=too-many-locals, too-many-statem
with self.argument_context('storage queue') as c:
c.argument('queue_name', queue_name_type, options_list=('--name', '-n'))

with self.argument_context('storage queue list') as c:
c.argument('include_metadata', help='Specify that queue metadata be returned in the response.')
c.argument('marker', arg_type=marker_type)
c.argument('num_results', arg_type=num_results_type)
c.argument('prefix', help='Filter the results to return only queues whose names '
'begin with the specified prefix.')
c.argument('show_next_marker', action='store_true',
help='Show nextMarker in result when specified.')
c.extra('timeout', help='Request timeout in seconds. Apply to each call to the service.', type=int)

with self.argument_context('storage queue create') as c:
c.argument('queue_name', queue_name_type, options_list=('--name', '-n'), completer=None)

Expand Down
15 changes: 12 additions & 3 deletions src/azure-cli/azure/cli/command_modules/storage/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
cf_adls_file_system, cf_adls_directory,
cf_adls_file, cf_adls_service,
cf_blob_client, cf_blob_lease_client,
cf_or_policy, cf_container_client)
cf_or_policy, cf_container_client,
cf_queue_service)

from azure.cli.command_modules.storage.sdkutil import cosmosdb_table_exists
from azure.cli.core.commands import CliCommandType
Expand Down Expand Up @@ -605,8 +606,6 @@ def get_custom_sdk(custom_module, client_factory, resource_type=ResourceType.DAT
from ._format import transform_boolean_for_table
from ._transformers import create_boolean_result_output_transformer

g.storage_command_oauth('list', 'list_queues',
transform=transform_storage_list_output)
g.storage_command_oauth('create', 'create_queue', transform=create_boolean_result_output_transformer('created'),
table_transformer=transform_boolean_for_table)
g.storage_command_oauth('delete', 'delete_queue', transform=create_boolean_result_output_transformer('deleted'),
Expand Down Expand Up @@ -646,6 +645,16 @@ def get_custom_sdk(custom_module, client_factory, resource_type=ResourceType.DAT
g.storage_command_oauth('clear', 'clear_messages')
g.storage_command_oauth('update', 'update_message')

queue_service_sdk = CliCommandType(
operations_tmpl='azure.multiapi.storagev2.queue._queue_service_client#QueueServiceClient.{}',
client_factory=cf_queue_service, resource_type=ResourceType.DATA_STORAGE_QUEUE)

with self.command_group('storage queue', queue_service_sdk,
resource_type=ResourceType.DATA_STORAGE_QUEUE, min_api='2018-03-28',
custom_command_type=get_custom_sdk('queue', client_factory=cf_queue_service,
resource_type=ResourceType.DATA_STORAGE_QUEUE)) as g:
g.storage_custom_command_oauth('list', 'list_queues', transform=transform_storage_list_output)

if cosmosdb_table_exists(self.cli_ctx):
table_sdk = CliCommandType(operations_tmpl='azure.multiapi.cosmosdb.table.tableservice#TableService.{}',
client_factory=table_data_service_factory,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from knack.log import get_logger

logger = get_logger(__name__)


def list_queues(client, include_metadata=False, marker=None, num_results=None,
prefix=None, show_next_marker=None, **kwargs):
from ..track2_util import list_generator
generator = client.list_queues(name_starts_with=prefix, include_metadata=include_metadata,
results_per_page=num_results, **kwargs)
pages = generator.by_page(continuation_token=marker)
result = list_generator(pages=pages, num_results=num_results)

if show_next_marker:
next_marker = {"nextMarker": pages.continuation_token}
result.append(next_marker)
else:
if pages.continuation_token:
logger.warning('Next Marker:')
logger.warning(pages.continuation_token)

return result
Loading