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-blob-preview] az storage blob filter: Add --container-name to support filter blobs in specific container #5481

Merged
merged 2 commits into from
Nov 2, 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
4 changes: 4 additions & 0 deletions src/storage-blob-preview/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

Release History
===============
0.6.2
++++++
* `az storage blob filter`: Add `--container-name` to support filter blobs in specific container

0.6.1
++++++
* `az storage blob immutability-policy set/delete`: Extend/Lock/Unlock/Delete blob's immutability policy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
class StorageCommandsLoader(AzCommandsLoader):
def __init__(self, cli_ctx=None):
from azure.cli.core.commands import CliCommandType
register_resource_type('latest', CUSTOM_DATA_STORAGE_BLOB, '2020-10-02')
register_resource_type('latest', CUSTOM_DATA_STORAGE_BLOB, '2021-04-10')
storage_custom = CliCommandType(operations_tmpl='azure.cli.command_modules.storage.custom#{}')
super(StorageCommandsLoader, self).__init__(cli_ctx=cli_ctx,
resource_type=CUSTOM_DATA_STORAGE_BLOB,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,11 @@
helps['storage blob filter'] = """
type: command
short-summary: List blobs across all containers whose tags match a given search expression.
long-summary: >
Filter blobs searches across all containers within a storage account but can be scoped within the expression to
a single container.
parameters:
- name: --tag-filter
short-summary: >
The expression to find blobs whose tags matches the specified condition.
eg. ""yourtagname"='firsttag' and "yourtagname2"='secondtag'"
To specify a container, eg. "@container='containerName' and "Name"='C'"
"""

helps['storage blob list'] = """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ def load_arguments(self, _): # pylint: disable=too-many-locals, too-many-statem

with self.argument_context('storage blob filter') as c:
c.argument('filter_expression', options_list=['--tag-filter'])
c.argument('container_name', container_name_type,
help='Used when you want to list blobs under a specified container')

with self.argument_context('storage blob generate-sas') as c:
from .completers import get_storage_acl_name_completion_list
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def get_custom_sdk(custom_module, client_factory, resource_type=ResourceType.DAT
with self.command_group('storage blob', blob_service_sdk, resource_type=CUSTOM_DATA_STORAGE_BLOB,
min_api='2019-12-12',
custom_command_type=blob_service_custom_sdk) as g:
g.storage_command_oauth('filter', 'find_blobs_by_tags', is_preview=True)
g.storage_custom_command_oauth('filter', 'find_blobs_by_tags', is_preview=True)

blob_lease_client_sdk = CliCommandType(
operations_tmpl='azure.multiapi.storagev2.blob._lease#BlobLeaseClient.{}',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -720,3 +720,9 @@ def query_blob(cmd, client, query_expression, input_config=None, output_config=N
return None

return reader.readall().decode("utf-8")


def find_blobs_by_tags(client, filter_expression, container_name=None):
if container_name:
client = client.get_container_client(container_name)
return client.find_blobs_by_tags(filter_expression=filter_expression)
Loading