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

[APIM] az apim deletedservice: Add command group to support managing soft-deleted azure API Management services #22716

Merged
merged 6 commits into from
Jun 30, 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
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,7 @@ def cf_apiversionset(cli_ctx, *_):

def cf_apischema(cli_ctx, *_):
return cf_apim(cli_ctx).api_schema


def cf_ds(cli_ctx, *_):
return cf_apim(cli_ctx).deleted_services
41 changes: 41 additions & 0 deletions src/azure-cli/azure/cli/command_modules/apim/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@
short-summary: Manage Azure API Management API Schema's.
"""

helps['apim deletedservice'] = """
type: group
short-summary: Manage soft-deleted Azure API Management services.
"""

helps['apim backup'] = """
type: command
short-summary: Creates a backup of the API Management service to the given Azure Storage Account. This is long running operation and could take several minutes to complete.
Expand Down Expand Up @@ -373,6 +378,15 @@
az apim nv update --service-name MyApim -g MyResourceGroup --named-value-id MyNamedValue --value foo
"""

helps['apim nv wait'] = """
type: command
short-summary: Place the CLI in a waiting state until a condition of an apim named value is met.
examples:
- name: Place the CLI in a waiting state until a condition of a apim api is met.
text: |
az apim nv wait --created --service-name MyApim -g MyResourceGroup --named-value-id MyNamedValue --resource-group MyResourceGroup
"""

helps['apim api operation list'] = """
type: command
short-summary: List a collection of the operations for the specified API.
Expand Down Expand Up @@ -612,3 +626,30 @@
az apim api schema wait --created --api-id MyApi --name MyApim --schema-id schemaId -g MyResourceGroup
crafted: true
"""

helps['apim deletedservice show'] = """
type: command
short-summary: Get soft-deleted Api Management service instances available for undelete by name.
examples:
- name: Get a soft-deleted services with its name.
text: |
az apim deletedservice show --service-name MyApim --location westus
"""

helps['apim deletedservice list'] = """
type: command
short-summary: List all soft-deleted Api Management services instances available for undelete for the given subscription.
examples:
- name: List all soft-deleted services in a subscription.
text: |
az apim deletedservice list
"""

helps['apim deletedservice purge'] = """
type: command
short-summary: Purge soft-deleted Api Management service instance (deletes it with no option to undelete)
examples:
- name: Purge a soft-deleted serivce.
text: |
az apim deletedservice purge --service-name MyApim --location westus
"""
11 changes: 11 additions & 0 deletions src/azure-cli/azure/cli/command_modules/apim/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,3 +400,14 @@ def load_arguments(self, _):
'version_header_name',
help="Name of HTTP header parameter that indicates the API Version if versioningScheme is set to `header`.")
c.argument('if_match', help='ETag of the Entity.')

with self.argument_context('apim deletedservice show') as c:
c.argument('location', arg_type=get_location_type(self.cli_ctx))
c.argument('service_name', options_list=['--service-name', '-n'],
help="The name of the soft deleted API Management service instance.")

with self.argument_context('apim deletedservice purge') as c:
c.argument('location', arg_type=get_location_type(self.cli_ctx))
c.argument(
'service_name', options_list=['--service-name', '-n'],
help="The name of the soft deleted API Management service instance.")
13 changes: 12 additions & 1 deletion src/azure-cli/azure/cli/command_modules/apim/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from azure.cli.command_modules.apim._format import (service_output_format)
from azure.cli.command_modules.apim._client_factory import (cf_service, cf_api, cf_product, cf_nv, cf_apiops,
cf_apirelease, cf_apirevision, cf_apiversionset,
cf_apischema)
cf_apischema, cf_ds)


def load_command_table(self, _):
Expand Down Expand Up @@ -59,6 +59,11 @@ def load_command_table(self, _):
client_factory=cf_apiversionset
)

apids_sdk = CliCommandType(
operations_tmpl='azure.mgmt.apimanagement.operations#DeletedServicesOperations.{}',
client_factory=cf_ds
)

# pylint: disable=line-too-long
with self.command_group('apim', service_sdk) as g:
g.custom_command('create', 'apim_create', supports_no_wait=True,
Expand Down Expand Up @@ -118,6 +123,7 @@ def load_command_table(self, _):
g.custom_command('delete', 'apim_nv_delete', confirmation=True)
g.custom_command('show-secret', 'apim_nv_show_secret')
g.generic_update_command('update', setter_name='begin_create_or_update', custom_func_name='apim_nv_update')
g.wait_command('wait')

with self.command_group('apim api operation', apiops_sdk) as g:
g.custom_command('list', 'apim_api_operation_list')
Expand All @@ -143,3 +149,8 @@ def load_command_table(self, _):
g.custom_command('create', 'apim_api_vs_create')
g.generic_update_command('update', custom_func_name='apim_api_vs_update')
g.custom_command('delete', 'apim_api_vs_delete')

with self.command_group('apim deletedservice', apids_sdk) as g:
g.custom_command('list', 'apim_ds_list')
g.custom_show_command('show', 'apim_ds_get')
g.custom_command('purge', 'apim_ds_purge')
22 changes: 22 additions & 0 deletions src/azure-cli/azure/cli/command_modules/apim/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -899,3 +899,25 @@ def apim_api_vs_delete(client, resource_group_name, service_name, version_set_id
service_name=service_name,
version_set_id=version_set_id,
if_match="*" if if_match is None else if_match)


def apim_ds_get(client, location, service_name):
"""Get specific soft-deleted Api Management Service."""

return client.deleted_services.get_by_name(service_name, location)


def apim_ds_list(client):
"""List soft-deleted Api Management Service."""

return client.deleted_services.list_by_subscription()


def apim_ds_purge(client, service_name, location, no_wait=False):
"""Purge soft-deleted Api Management Service."""

return sdk_no_wait(
no_wait,
client.deleted_services.begin_purge,
service_name=service_name,
location=location)
Loading