Skip to content

Commit ef2395c

Browse files
committed
Add soft delete feature for CosmosDB SQL API
- Implemented 12 soft delete commands (list, show, delete/purge, recover for accounts, databases, and collections) - Added soft delete configuration parameters to cosmosdb create/update commands - Added comprehensive test coverage with 6 test methods - Optimized test execution by removing unnecessary sleep statements - Added linter exclusions for framework-generated parameters - Updated HISTORY.rst and bumped version to 1.7.0
1 parent 59814d0 commit ef2395c

File tree

9 files changed

+926
-6
lines changed

9 files changed

+926
-6
lines changed

linter_exclusions.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3504,3 +3504,20 @@ neon postgres organization:
35043504
neon postgres project:
35053505
rule_exclusions:
35063506
- require_wait_command_if_no_wait
3507+
3508+
cosmosdb update:
3509+
parameters:
3510+
soft_deletion_retention_period_in_minutes:
3511+
rule_exclusions:
3512+
- unrecognized_help_parameter
3513+
min_minutes_before_permanent_deletion_allowed:
3514+
rule_exclusions:
3515+
- unrecognized_help_parameter
3516+
3517+
cosmosdb sql softdeleted-database list:
3518+
rule_exclusions:
3519+
- no_ids_for_list_commands
3520+
3521+
cosmosdb sql softdeleted-collection list:
3522+
rule_exclusions:
3523+
- no_ids_for_list_commands

src/cosmosdb-preview/HISTORY.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
Release History
33
===============
44

5+
1.7.0
6+
+++++
7+
* Add support for soft-deleted resource operations for SQL API
8+
* New command group `az cosmosdb sql softdeleted-account` to list, show, delete (purge), and recover soft-deleted accounts
9+
* New command group `az cosmosdb sql softdeleted-database` to list, show, delete (purge), and recover soft-deleted databases
10+
* New command group `az cosmosdb sql softdeleted-collection` to list, show, delete (purge), and recover soft-deleted containers
11+
512
1.6.1
613
+++++
714
* Fix SQL container throughput update to preserve existing throughput buckets when not explicitly specified.

src/cosmosdb-preview/azext_cosmosdb_preview/_client_factory.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,16 @@ def cf_fleetspace_account(cli_ctx, _):
119119

120120
def cf_fleet_analytics(cli_ctx, _):
121121
return cf_cosmosdb_preview(cli_ctx).fleet_analytics
122+
123+
124+
# soft-deleted resources
125+
def cf_softdeleted_database_accounts(cli_ctx, _):
126+
return cf_cosmosdb_preview(cli_ctx).soft_deleted_database_accounts
127+
128+
129+
def cf_softdeleted_sql_databases(cli_ctx, _):
130+
return cf_cosmosdb_preview(cli_ctx).soft_deleted_sql_databases
131+
132+
133+
def cf_softdeleted_sql_containers(cli_ctx, _):
134+
return cf_cosmosdb_preview(cli_ctx).soft_deleted_sql_containers

src/cosmosdb-preview/azext_cosmosdb_preview/_help.py

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,11 +564,25 @@
564564
Default: single region account in the location of the specified resource group.
565565
Failover priority values are 0 for write regions and greater than 0 for read regions. A failover priority value must be unique and less than the total number of regions.
566566
Multiple locations can be specified by using more than one `--locations` argument.
567+
- name: --enabled-soft-deletion
568+
short-summary: Enable or disable soft deletion on the account
569+
long-summary: |
570+
When enabled, deleted databases and containers are retained for the configured retention period and can be recovered.
571+
- name: --sd-retention
572+
short-summary: Soft deletion retention period in minutes
573+
long-summary: |
574+
The retention period for soft-deleted resources. Must be at least equal to min-minutes-before-permanent-deletion-allowed.
575+
- name: --min-purge-minutes
576+
short-summary: Minimum minutes before permanent deletion is allowed
577+
long-summary: |
578+
The minimum time that must pass after soft-deletion before a resource can be permanently deleted (purged).
567579
examples:
568580
- name: Update an Azure Cosmos DB database account. (autogenerated)
569581
text: az cosmosdb update --capabilities EnableGremlin --name MyCosmosDBDatabaseAccount --resource-group MyResourceGroup
570582
- name: Update an Azure Cosmos DB database account to enable materialized views.
571583
text: az cosmosdb update --name MyCosmosDBDatabaseAccount --resource-group MyResourceGroup --enable-materialized-views true
584+
- name: Enable soft deletion with 1440 minutes (24 hours) retention.
585+
text: az cosmosdb update --name MyCosmosDBDatabaseAccount --resource-group MyResourceGroup --enabled-soft-deletion true --sd-retention 1440 --min-purge-minutes 60
572586
"""
573587

574588
# restore account
@@ -1844,3 +1858,126 @@
18441858
type: command
18451859
short-summary: Delete a Fleet Analytics resource from a Fleet.
18461860
"""
1861+
1862+
helps['cosmosdb sql softdeleted-account'] = """
1863+
type: group
1864+
short-summary: Manage soft-deleted Azure Cosmos DB accounts.
1865+
"""
1866+
1867+
helps['cosmosdb sql softdeleted-account list'] = """
1868+
type: command
1869+
short-summary: List all soft-deleted Azure Cosmos DB accounts in a subscription.
1870+
examples:
1871+
- name: List all soft-deleted Azure Cosmos DB accounts in a subscription.
1872+
text: |
1873+
az cosmosdb sql softdeleted-account list --location westus --resource-group MyResourceGroup
1874+
"""
1875+
1876+
helps['cosmosdb sql softdeleted-account show'] = """
1877+
type: command
1878+
short-summary: Show details of a soft-deleted Azure Cosmos DB account.
1879+
examples:
1880+
- name: Show details of a soft-deleted Azure Cosmos DB account.
1881+
text: |
1882+
az cosmosdb sql softdeleted-account show --location westus --account-name MyAccount --resource-group MyResourceGroup
1883+
"""
1884+
1885+
helps['cosmosdb sql softdeleted-account delete'] = """
1886+
type: command
1887+
short-summary: Permanently delete a soft-deleted Azure Cosmos DB account.
1888+
examples:
1889+
- name: Permanently delete a soft-deleted Azure Cosmos DB account.
1890+
text: |
1891+
az cosmosdb sql softdeleted-account delete --location westus --account-name MyAccount --resource-group MyResourceGroup
1892+
"""
1893+
1894+
helps['cosmosdb sql softdeleted-account recover'] = """
1895+
type: command
1896+
short-summary: Recover a soft-deleted Azure Cosmos DB account.
1897+
examples:
1898+
- name: Recover a soft-deleted Azure Cosmos DB account.
1899+
text: |
1900+
az cosmosdb sql softdeleted-account recover --location westus --account-name MyAccount --resource-group MyResourceGroup
1901+
"""
1902+
1903+
helps['cosmosdb sql softdeleted-database'] = """
1904+
type: group
1905+
short-summary: Manage soft-deleted databases for Azure Cosmos DB SQL API.
1906+
"""
1907+
1908+
helps['cosmosdb sql softdeleted-database list'] = """
1909+
type: command
1910+
short-summary: List all soft-deleted databases for an Azure Cosmos DB account.
1911+
examples:
1912+
- name: List all soft-deleted databases for an Azure Cosmos DB account.
1913+
text: |
1914+
az cosmosdb sql softdeleted-database list --location westus --account-name MyAccount --resource-group MyResourceGroup
1915+
"""
1916+
1917+
helps['cosmosdb sql softdeleted-database show'] = """
1918+
type: command
1919+
short-summary: Show details of a soft-deleted database.
1920+
examples:
1921+
- name: Show details of a soft-deleted database.
1922+
text: |
1923+
az cosmosdb sql softdeleted-database show --location westus --account-name MyAccount --name MyDatabase --resource-group MyResourceGroup
1924+
"""
1925+
1926+
helps['cosmosdb sql softdeleted-database delete'] = """
1927+
type: command
1928+
short-summary: Permanently delete a soft-deleted database.
1929+
examples:
1930+
- name: Permanently delete a soft-deleted database.
1931+
text: |
1932+
az cosmosdb sql softdeleted-database delete --location westus --account-name MyAccount --name MyDatabase --resource-group MyResourceGroup
1933+
"""
1934+
1935+
helps['cosmosdb sql softdeleted-database recover'] = """
1936+
type: command
1937+
short-summary: Recover a soft-deleted database.
1938+
examples:
1939+
- name: Recover a soft-deleted database.
1940+
text: |
1941+
az cosmosdb sql softdeleted-database recover --location westus --account-name MyAccount --name MyDatabase --resource-group MyResourceGroup
1942+
"""
1943+
1944+
helps['cosmosdb sql softdeleted-collection'] = """
1945+
type: group
1946+
short-summary: Manage soft-deleted collections for Azure Cosmos DB SQL API.
1947+
"""
1948+
1949+
helps['cosmosdb sql softdeleted-collection list'] = """
1950+
type: command
1951+
short-summary: List all soft-deleted collections in a database.
1952+
examples:
1953+
- name: List all soft-deleted collections in a database.
1954+
text: |
1955+
az cosmosdb sql softdeleted-collection list --location westus --account-name MyAccount --database-name MyDatabase --resource-group MyResourceGroup
1956+
"""
1957+
1958+
helps['cosmosdb sql softdeleted-collection show'] = """
1959+
type: command
1960+
short-summary: Show details of a soft-deleted collection.
1961+
examples:
1962+
- name: Show details of a soft-deleted collection.
1963+
text: |
1964+
az cosmosdb sql softdeleted-collection show --location westus --account-name MyAccount --database-name MyDatabase --name MyCollection --resource-group MyResourceGroup
1965+
"""
1966+
1967+
helps['cosmosdb sql softdeleted-collection delete'] = """
1968+
type: command
1969+
short-summary: Permanently delete a soft-deleted collection.
1970+
examples:
1971+
- name: Permanently delete a soft-deleted collection.
1972+
text: |
1973+
az cosmosdb sql softdeleted-collection delete --location westus --account-name MyAccount --database-name MyDatabase --name MyCollection --resource-group MyResourceGroup
1974+
"""
1975+
1976+
helps['cosmosdb sql softdeleted-collection recover'] = """
1977+
type: command
1978+
short-summary: Recover a soft-deleted collection.
1979+
examples:
1980+
- name: Recover a soft-deleted collection.
1981+
text: |
1982+
az cosmosdb sql softdeleted-collection recover --location westus --account-name MyAccount --database-name MyDatabase --name MyCollection --resource-group MyResourceGroup
1983+
"""

src/cosmosdb-preview/azext_cosmosdb_preview/_params.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,78 @@ def load_arguments(self, _):
829829
c.argument('scope', options_list=['--scope', '-s'], help="Data plane resource path at which this Role Assignment is being granted.")
830830
c.argument('principal_id', options_list=['--principal-id', '-p'], help="AAD Object ID of the principal to which this Role Assignment is being granted.")
831831

832+
# Soft-deleted Account
833+
with self.argument_context('cosmosdb sql softdeleted-account list') as c:
834+
c.argument('location', options_list=['--location', '-l'], help="Location of the soft-deleted account.", required=False)
835+
c.argument('resource_group', options_list=['--resource-group', '-g'], help="Name of the resource group.", required=True)
836+
837+
with self.argument_context('cosmosdb sql softdeleted-account show') as c:
838+
c.argument('location', options_list=['--location', '-l'], help="Location of the soft-deleted account.", required=True)
839+
c.argument('account_name', options_list=['--account-name', '-n'], help="Name of the soft-deleted Cosmos DB account.", required=True)
840+
c.argument('resource_group', options_list=['--resource-group', '-g'], help="Name of the resource group.", required=True)
841+
842+
with self.argument_context('cosmosdb sql softdeleted-account delete') as c:
843+
c.argument('location', options_list=['--location', '-l'], help="Location of the soft-deleted account.", required=True)
844+
c.argument('account_name', options_list=['--account-name', '-n'], help="Name of the soft-deleted Cosmos DB account to purge.", required=True)
845+
c.argument('resource_group', options_list=['--resource-group', '-g'], help="Name of the resource group.", required=True)
846+
847+
with self.argument_context('cosmosdb sql softdeleted-account recover') as c:
848+
c.argument('location', options_list=['--location', '-l'], help="Location of the soft-deleted account.", required=True)
849+
c.argument('account_name', options_list=['--account-name', '-n'], help="Name of the soft-deleted Cosmos DB account to recover.", required=True)
850+
c.argument('resource_group', options_list=['--resource-group', '-g'], help="Name of the resource group.", required=True)
851+
852+
# Soft-deleted Database
853+
with self.argument_context('cosmosdb sql softdeleted-database list') as c:
854+
c.argument('location', options_list=['--location', '-l'], help="Location of the account.", required=True)
855+
c.argument('account_name', options_list=['--account-name', '-a'], help="Name of the Cosmos DB account.", required=True)
856+
c.argument('resource_group', options_list=['--resource-group', '-g'], help="Name of the resource group.", required=True)
857+
858+
with self.argument_context('cosmosdb sql softdeleted-database show') as c:
859+
c.argument('location', options_list=['--location', '-l'], help="Location of the account.", required=True)
860+
c.argument('account_name', options_list=['--account-name', '-a'], help="Name of the Cosmos DB account.", required=True)
861+
c.argument('database_name', options_list=['--name', '-n'], help="Name of the soft-deleted database.", required=True)
862+
c.argument('resource_group', options_list=['--resource-group', '-g'], help="Name of the resource group.", required=True)
863+
864+
with self.argument_context('cosmosdb sql softdeleted-database delete') as c:
865+
c.argument('location', options_list=['--location', '-l'], help="Location of the account.", required=True)
866+
c.argument('account_name', options_list=['--account-name', '-a'], help="Name of the Cosmos DB account.", required=True)
867+
c.argument('database_name', options_list=['--name', '-n'], help="Name of the soft-deleted database to purge.", required=True)
868+
c.argument('resource_group', options_list=['--resource-group', '-g'], help="Name of the resource group.", required=True)
869+
870+
with self.argument_context('cosmosdb sql softdeleted-database recover') as c:
871+
c.argument('location', options_list=['--location', '-l'], help="Location of the account.", required=True)
872+
c.argument('account_name', options_list=['--account-name', '-a'], help="Name of the Cosmos DB account.", required=True)
873+
c.argument('database_name', options_list=['--name', '-n'], help="Name of the soft-deleted database to recover.", required=True)
874+
c.argument('resource_group', options_list=['--resource-group', '-g'], help="Name of the resource group.", required=True)
875+
876+
# Soft-deleted Collection
877+
with self.argument_context('cosmosdb sql softdeleted-collection list') as c:
878+
c.argument('location', options_list=['--location', '-l'], help="Location of the account.", required=True)
879+
c.argument('account_name', options_list=['--account-name', '-a'], help="Name of the Cosmos DB account.", required=True)
880+
c.argument('database_name', options_list=['--database-name', '-d'], help="Name of the database.", required=True)
881+
c.argument('resource_group', options_list=['--resource-group', '-g'], help="Name of the resource group.", required=True)
882+
883+
with self.argument_context('cosmosdb sql softdeleted-collection show') as c:
884+
c.argument('location', options_list=['--location', '-l'], help="Location of the account.", required=True)
885+
c.argument('account_name', options_list=['--account-name', '-a'], help="Name of the Cosmos DB account.", required=True)
886+
c.argument('database_name', options_list=['--database-name', '-d'], help="Name of the database.", required=True)
887+
c.argument('container_name', options_list=['--name', '-n'], help="Name of the soft-deleted container.", required=True)
888+
c.argument('resource_group', options_list=['--resource-group', '-g'], help="Name of the resource group.", required=True)
889+
890+
with self.argument_context('cosmosdb sql softdeleted-collection delete') as c:
891+
c.argument('location', options_list=['--location', '-l'], help="Location of the account.", required=True)
892+
c.argument('account_name', options_list=['--account-name', '-a'], help="Name of the Cosmos DB account.", required=True)
893+
c.argument('database_name', options_list=['--database-name', '-d'], help="Name of the database.", required=True)
894+
c.argument('container_name', options_list=['--name', '-n'], help="Name of the soft-deleted container to purge.", required=True)
895+
c.argument('resource_group', options_list=['--resource-group', '-g'], help="Name of the resource group.", required=True)
896+
897+
with self.argument_context('cosmosdb sql softdeleted-collection recover') as c:
898+
c.argument('location', options_list=['--location', '-l'], help="Location of the account.", required=True)
899+
c.argument('account_name', options_list=['--account-name', '-a'], help="Name of the Cosmos DB account.", required=True)
900+
c.argument('database_name', options_list=['--database-name', '-d'], help="Name of the database.", required=True)
901+
c.argument('container_name', options_list=['--name', '-n'], help="Name of the soft-deleted container to recover.", required=True)
902+
c.argument('resource_group', options_list=['--resource-group', '-g'], help="Name of the resource group.", required=True)
903+
832904
# Cosmos DB Fleet
833905
with self.argument_context('cosmosdb fleet') as c:
834906
c.argument('resource_group', options_list=['--resource-group', '-g'], help='Name of the resource group.', required=True)

src/cosmosdb-preview/azext_cosmosdb_preview/commands.py

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@
3131
cf_fleet,
3232
cf_fleetspace,
3333
cf_fleetspace_account,
34-
cf_fleet_analytics
34+
cf_fleet_analytics,
35+
cf_softdeleted_database_accounts,
36+
cf_softdeleted_sql_databases,
37+
cf_softdeleted_sql_containers
3538
)
3639

3740

@@ -220,6 +223,19 @@ def load_command_table(self, _):
220223
operations_tmpl='azure.mgmt.cosmosdb.operations#RestorableDatabaseAccountsOperations.{}',
221224
client_factory=cf_restorable_database_accounts)
222225

226+
# Soft-deleted resources SDK types
227+
cosmosdb_softdeleted_accounts_sdk = CliCommandType(
228+
operations_tmpl='azext_cosmosdb_preview.vendored_sdks.azure_mgmt_cosmosdb.operations#SoftDeletedDatabaseAccountsOperations.{}',
229+
client_factory=cf_softdeleted_database_accounts)
230+
231+
cosmosdb_softdeleted_sql_databases_sdk = CliCommandType(
232+
operations_tmpl='azext_cosmosdb_preview.vendored_sdks.azure_mgmt_cosmosdb.operations#SoftDeletedSqlDatabasesOperations.{}',
233+
client_factory=cf_softdeleted_sql_databases)
234+
235+
cosmosdb_softdeleted_sql_containers_sdk = CliCommandType(
236+
operations_tmpl='azext_cosmosdb_preview.vendored_sdks.azure_mgmt_cosmosdb.operations#SoftDeletedSqlContainersOperations.{}',
237+
client_factory=cf_softdeleted_sql_containers)
238+
223239
# define commands
224240
# Restorable apis for sql,mongodb,gremlin and table
225241
# Provisioning/migrate Continuous 7 days accounts
@@ -367,6 +383,36 @@ def load_command_table(self, _):
367383
with self.command_group('cosmosdb table', cosmosdb_table_sdk, client_factory=cf_table_resources) as g:
368384
g.custom_command('restore', 'cli_cosmosdb_table_restore', is_preview=True)
369385

386+
# Soft-deleted Account commands
387+
with self.command_group('cosmosdb sql softdeleted-account',
388+
cosmosdb_softdeleted_accounts_sdk,
389+
client_factory=cf_softdeleted_database_accounts,
390+
is_preview=True) as g:
391+
g.custom_command('list', 'cli_cosmosdb_sql_softdeleted_account_list')
392+
g.custom_show_command('show', 'cli_cosmosdb_sql_softdeleted_account_show')
393+
g.custom_command('delete', 'cli_cosmosdb_sql_softdeleted_account_delete', confirmation=True)
394+
g.custom_command('recover', 'cli_cosmosdb_sql_softdeleted_account_recover')
395+
396+
# Soft-deleted Database commands
397+
with self.command_group('cosmosdb sql softdeleted-database',
398+
cosmosdb_softdeleted_sql_databases_sdk,
399+
client_factory=cf_softdeleted_sql_databases,
400+
is_preview=True) as g:
401+
g.custom_command('list', 'cli_cosmosdb_sql_softdeleted_database_list')
402+
g.custom_show_command('show', 'cli_cosmosdb_sql_softdeleted_database_show')
403+
g.custom_command('delete', 'cli_cosmosdb_sql_softdeleted_database_delete', confirmation=True)
404+
g.custom_command('recover', 'cli_cosmosdb_sql_softdeleted_database_recover')
405+
406+
# Soft-deleted Collection commands
407+
with self.command_group('cosmosdb sql softdeleted-collection',
408+
cosmosdb_softdeleted_sql_containers_sdk,
409+
client_factory=cf_softdeleted_sql_containers,
410+
is_preview=True) as g:
411+
g.custom_command('list', 'cli_cosmosdb_sql_softdeleted_collection_list')
412+
g.custom_show_command('show', 'cli_cosmosdb_sql_softdeleted_collection_show')
413+
g.custom_command('delete', 'cli_cosmosdb_sql_softdeleted_collection_delete', confirmation=True)
414+
g.custom_command('recover', 'cli_cosmosdb_sql_softdeleted_collection_recover')
415+
370416
setup_mongocluster_commands(self)
371417

372418
setup_fleet_commands(self)

0 commit comments

Comments
 (0)