Skip to content

Commit

Permalink
Added new parameters for account blob service properties to manage de…
Browse files Browse the repository at this point in the history
…lete retention policy (#11660)
  • Loading branch information
zhoxing-ms authored and Juliehzl committed Jan 3, 2020
1 parent c8b028d commit 585eb06
Show file tree
Hide file tree
Showing 7 changed files with 512 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/azure-cli/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Release History

* `az storage account create`: Remove preview flag for --enable-hierarchical-namespace parameter
* Update azure-mgmt-storage version to 7.0.0 to use api version 2019-06-01
* Add new parameters `--enable-delete-retention` and `--delete-retention-days` to support managing delete retention policy for storage account blob-service-properties.

2.0.78
++++++
Expand Down
8 changes: 7 additions & 1 deletion src/azure-cli/azure/cli/command_modules/storage/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,19 @@
long-summary: >
Update the properties of a storage account's blob service, including
properties for Storage Analytics and CORS (Cross-Origin Resource
Sharing) rules. But currently we only support enabling or disabling change feed for a storage account's blob service.
Sharing) rules.
parameters:
- name: --enable-change-feed
short-summary: 'Indicate whether change feed event logging is enabled. If it is true, you enable the storage account to begin capturing changes. The default value is true. You can see more details in https://docs.microsoft.com/en-us/azure/storage/blobs/storage-blob-change-feed?tabs=azure-portal#register-by-using-azure-cli'
- name: --enable-delete-retention
short-summary: 'Indicate whether delete retention policy is enabled for the blob service.'
- name: --delete-retention-days
short-summary: 'Indicate the number of days that the deleted blob should be retained. The value must be in range [1,365]. It must be provided when `--enable-delete-retention` is true.'
examples:
- name: Enable the change feed for the storage account 'MyStorageAccount' in resource group 'MyResourceGroup'.
text: az storage account blob-service-properties update --enable-change-feed true -n MyStorageAccount -g MyResourceGroup
- name: Enable delete retention policy and set delete retention days to 100 for the storage account 'MyStorageAccount' in resource group 'MyResourceGroup'.
text: az storage account blob-service-properties update --enable-delete-retention true --delete-retention-days 100 -n MyStorageAccount -g MyResourceGroup
"""

helps['storage account create'] = """
Expand Down
5 changes: 5 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 @@ -247,9 +247,14 @@ def load_arguments(self, _): # pylint: disable=too-many-locals, too-many-statem

with self.argument_context('storage account blob-service-properties update',
resource_type=ResourceType.MGMT_STORAGE) as c:
from ._validators import validator_delete_retention_days
c.argument('account_name', acct_name_type, id_part=None)
c.argument('resource_group_name', required=False, validator=process_resource_group)
c.argument('enable_change_feed', arg_type=get_three_state_flag(), min_api='2019-04-01')
c.argument('enable_delete_retention', arg_type=get_three_state_flag(), arg_group='Delete Retention Policy',
min_api='2018-07-01')
c.argument('delete_retention_days', type=int, arg_group='Delete Retention Policy',
validator=validator_delete_retention_days, min_api='2018-07-01')

with self.argument_context('storage account generate-sas') as c:
t_account_permissions = self.get_sdk('common.models#AccountPermissions')
Expand Down
24 changes: 24 additions & 0 deletions src/azure-cli/azure/cli/command_modules/storage/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -1121,3 +1121,27 @@ def as_user_validator(namespace):
import argparse
raise argparse.ArgumentError(
None, "incorrect usage: specify '--auth-mode login' when as-user is enabled")


def validator_delete_retention_days(namespace):
if namespace.enable_delete_retention is True and namespace.delete_retention_days is None:
raise ValueError(
"incorrect usage: you have to provide value for '--delete-retention-days' when '--enable-delete-retention' "
"is set to true")

if namespace.enable_delete_retention is False and namespace.delete_retention_days is not None:
raise ValueError(
"incorrect usage: '--delete-retention-days' is invalid when '--enable-delete-retention' is set to false")

if namespace.enable_delete_retention is None and namespace.delete_retention_days is not None:
raise ValueError(
"incorrect usage: please specify '--enable-delete-retention true' if you want to set the value for "
"'--delete-retention-days'")

if namespace.delete_retention_days or namespace.delete_retention_days == 0:
if namespace.delete_retention_days < 1:
raise ValueError(
"incorrect usage: '--delete-retention-days' must be greater than or equal to 1")
if namespace.delete_retention_days > 365:
raise ValueError(
"incorrect usage: '--delete-retention-days' must be less than or equal to 365")
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,16 @@ def update_management_policies(client, resource_group_name, account_name, parame
return client.create_or_update(resource_group_name, account_name, policy=parameters)


# TODO: support updating other properties besides 'enable_change_feed'
def update_blob_service_properties(cmd, instance, enable_change_feed=None):
# TODO: support updating other properties besides 'enable_change_feed,delete_retention_policy'
def update_blob_service_properties(cmd, instance, enable_change_feed=None, enable_delete_retention=None,
delete_retention_days=None):
if enable_change_feed is not None:
instance.change_feed = cmd.get_models('ChangeFeed')(enabled=enable_change_feed)

if enable_delete_retention is not None:
if enable_delete_retention is False:
delete_retention_days = None
instance.delete_retention_policy = cmd.get_models('DeleteRetentionPolicy')(
enabled=enable_delete_retention, days=delete_retention_days)

return instance
Loading

0 comments on commit 585eb06

Please sign in to comment.