Skip to content

Commit 604b8f3

Browse files
feat: added new subcommand for apim [backend]
1 parent dc07baf commit 604b8f3

File tree

10 files changed

+4391
-4826
lines changed

10 files changed

+4391
-4826
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ __pycache__/
66
env/
77
env27/
88
venv/
9+
.venv/
910
.python-version
1011

1112
# PTVS analysis

src/azure-cli/azure/cli/command_modules/apim/_client_factory.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,6 @@ def cf_graphqlapiresolver(cli_ctx, *_):
5656

5757
def cf_graphqlapiresolverpolicy(cli_ctx, *_):
5858
return cf_apim(cli_ctx).graph_ql_api_resolver_policy
59+
60+
def cf_backend(cli_ctx, *_):
61+
return cf_apim(cli_ctx).backend

src/azure-cli/azure/cli/command_modules/apim/_help.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@
8888
short-summary: Manage soft-deleted Azure API Management services.
8989
"""
9090

91+
helps['apim backend'] = """
92+
type: group
93+
short-summary: Manage Azure API Management Backends.
94+
"""
95+
9196
helps['apim backup'] = """
9297
type: command
9398
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.
@@ -749,3 +754,69 @@
749754
text: |
750755
az apim graphql resolver policy list --service-name MyApim -g MyResourceGroup --api-id MyApi --resolver-id MyResolverId
751756
"""
757+
758+
helps['apim backend list'] = """
759+
type: command
760+
short-summary: List API Management Backends.
761+
examples:
762+
- name: List all Backends in an APIM instance.
763+
text: |-
764+
az apim backend list --resource-group MyResourceGroup --service-name MyServiceName
765+
"""
766+
767+
helps['apim backend show'] = """
768+
type: command
769+
short-summary: Show details of an API Management Backend.
770+
examples:
771+
- name: Show details of a Backend in an APIM instance.
772+
text: |-
773+
az apim backend show --resource-group MyResourceGroup --service-name MyServiceName --backend-id MyBackendId
774+
"""
775+
776+
helps['apim backend delete'] = """
777+
type: command
778+
short-summary: Delete an API Management Backend.
779+
examples:
780+
- name: Delete a Backend in an APIM instance.
781+
text: |-
782+
az apim backend delete --resource-group MyResourceGroup --service-name MyServiceName --backend-id MyBackendId
783+
"""
784+
785+
helps['apim backend create'] = """
786+
type: command
787+
short-summary: Create or Update an API Management Backend.
788+
parameters:
789+
- name: --backend-id
790+
type: string
791+
short-summary: unique name for the Backend to be created or updated
792+
long-summary: |
793+
Must be unique in the current API Management service instance.
794+
- name: --url
795+
type: string
796+
short-summary: The URL of the backend service.
797+
- name: --protocol
798+
type: string
799+
short-summary: The protocol used to communicate with the backend service.
800+
examples:
801+
- name: Create a Backend.
802+
text: |-
803+
az apim backend create --service-name MyApim -g MyResourceGroup --backend-id MyBackendId --url https://mybackend.com --protocol http
804+
"""
805+
806+
helps['apim backend update'] = """
807+
type: command
808+
short-summary: Update an API Management Backend.
809+
parameters:
810+
- name: --backend-id
811+
type: string
812+
short-summary: unique name of the Backend to be updated
813+
long-summary: |
814+
Must be unique in the current API Management service instance.
815+
- name: --if-match
816+
type: string
817+
short-summary: ETag of the Backend entity. ETag should match the current entity state from the service to perform an update. Use "*" for unconditional update.
818+
examples:
819+
- name: Update a Backend.
820+
text: |-
821+
az apim backend update --service-name MyApim -g MyResourceGroup --backend-id MyBackendId --if-match "*"
822+
"""

src/azure-cli/azure/cli/command_modules/apim/_params.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
resource_group_name_type,
1313
get_three_state_flag)
1414

15-
from azure.mgmt.apimanagement.models import (SkuType, VirtualNetworkType, Protocol, ApiType, ProductState)
15+
from azure.mgmt.apimanagement.models import (SkuType, VirtualNetworkType, Protocol, ApiType, ProductState, BackendProtocol)
1616
from azure.cli.command_modules.apim.actions import (TemplateParameter)
1717

1818

1919
SKU_TYPES = SkuType
2020
VNET_TYPES = VirtualNetworkType
2121
API_PROTOCOLS = Protocol
2222
API_TYPES = ApiType
23-
23+
BACKEND_PROTOCOLS = BackendProtocol
2424

2525
class ImportFormat(Enum):
2626
Wadl = "Wadl"
@@ -51,6 +51,8 @@ def load_arguments(self, _):
5151
help='API identifier. Must be unique in the current API Management service instance. Non-current revision has ;rev=n as a suffix where n is the revision number.')
5252
schema_id = CLIArgumentType(arg_group='Schema',
5353
help='Schema identifier. Must be unique in the current API Management service instance. Non-current revision has ;rev=n as a suffix where n is the revision number.')
54+
backend_id = CLIArgumentType(arg_group='Backend',
55+
help='Backend identifier. Must be unique in the current API Management service instance. Non-current revision has ;rev=n as a suffix where n is the revision number.')
5456

5557
from azure.cli.core.commands.parameters import tags_type
5658
from azure.cli.core.commands.validators import get_default_location_from_resource_group
@@ -502,3 +504,15 @@ def load_arguments(self, _):
502504
c.argument('api_id', arg_type=api_id)
503505
c.argument('resolver_id', help='Resolver identifier within a GraphQL API. Must be unique in the current API Management service instance.')
504506
c.argument('if_match', help='ETag of the Entity.')
507+
508+
with self.argument_context('apim backend') as c:
509+
c.argument('service_name', options_list=['--service-name', '-n'],
510+
help='The name of the API Management service instance.')
511+
c.argument('backend_id', arg_type=backend_id, help='Identifier of the Backend.')
512+
c.argument('url', help='Required. Backend service URL.')
513+
c.argument('protocol', arg_type=get_enum_type(BACKEND_PROTOCOLS),
514+
help='Protocol used to communicate with the backend service. Possible values include: `http`, `soap`.')
515+
c.argument('title', help='Backend title.')
516+
c.argument('description', help='Description of the Backend. May include HTML formatting tags.')
517+
c.argument('resource_id', help='Resource ID of the backend service.')
518+
c.argument('if_match', help='ETag of the Entity.')

src/azure-cli/azure/cli/command_modules/apim/commands.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from azure.cli.command_modules.apim._client_factory import (cf_service, cf_api, cf_product, cf_nv, cf_apiops,
1212
cf_apirelease, cf_apirevision, cf_apiversionset,
1313
cf_apischema, cf_ds, cf_graphqlapiresolver,
14-
cf_graphqlapiresolverpolicy)
14+
cf_graphqlapiresolverpolicy, cf_backend)
1515

1616

1717
def load_command_table(self, _):
@@ -75,6 +75,11 @@ def load_command_table(self, _):
7575
client_factory=cf_graphqlapiresolverpolicy
7676
)
7777

78+
backend_sdk = CliCommandType(
79+
operations_tmpl='azure.mgmt.apimanagement.operations#BackendOperations.{}',
80+
client_factory=cf_backend
81+
)
82+
7883
# pylint: disable=line-too-long
7984
with self.command_group('apim', service_sdk) as g:
8085
g.custom_command('create', 'apim_create', supports_no_wait=True,
@@ -178,3 +183,12 @@ def load_command_table(self, _):
178183
g.custom_command('delete', 'apim_graphql_resolver_policy_delete', confirmation=True)
179184
g.custom_show_command('show', 'apim_graphql_resolver_policy_show')
180185
g.custom_command('list', 'apim_graphql_resolver_policy_list')
186+
187+
with self.command_group('apim backend', backend_sdk) as g:
188+
g.custom_command('create', 'apim_backend_create', supports_no_wait=True)
189+
g.custom_show_command('show', 'apim_backend_show')
190+
g.custom_command('list', 'apim_backend_list')
191+
g.custom_command('delete', 'apim_backend_delete', confirmation=True, supports_no_wait=True)
192+
g.generic_update_command('update', custom_func_name='apim_backend_update',
193+
setter_name='update', getter_name='get', supports_no_wait=True)
194+
g.wait_command('wait')

src/azure-cli/azure/cli/command_modules/apim/custom.py

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
OpenIdAuthenticationSettingsContract, ProductContract, ProductState,
3939
NamedValueCreateContract, VersioningScheme, ApiVersionSetContract,
4040
OperationContract, ApiManagementServiceCheckNameAvailabilityParameters,
41-
ApiReleaseContract, SchemaContract, ResolverContract, PolicyContract)
41+
ApiReleaseContract, SchemaContract, ResolverContract, PolicyContract,
42+
BackendContract)
4243

4344
logger = get_logger(__name__)
4445

@@ -1165,3 +1166,70 @@ def apim_graphql_resolver_policy_delete(
11651166
resolver_id=resolver_id,
11661167
policy_id="policy",
11671168
if_match="*" if if_match is None else if_match)
1169+
1170+
def apim_backend_create(
1171+
client, resource_group_name, service_name, backend_id, url, protocol, description=None,
1172+
title=None, resource_id=None, properties=None, if_match=None, no_wait=False):
1173+
1174+
parameters = BackendContract(
1175+
url=url,
1176+
protocol=protocol,
1177+
description=description,
1178+
title=title,
1179+
resource_id=resource_id,
1180+
properties=properties
1181+
)
1182+
1183+
return sdk_no_wait(no_wait, client.backend.create_or_update,
1184+
resource_group_name=resource_group_name,
1185+
service_name=service_name,
1186+
backend_id=backend_id,
1187+
parameters=parameters,
1188+
if_match="*" if if_match is None else if_match)
1189+
1190+
def apim_backend_delete(
1191+
client, resource_group_name, service_name, backend_id, if_match=None, no_wait=False):
1192+
1193+
return sdk_no_wait(no_wait,
1194+
client.backend.delete,
1195+
resource_group_name=resource_group_name,
1196+
service_name=service_name,
1197+
backend_id=backend_id,
1198+
if_match="*" if if_match is None else if_match)
1199+
1200+
def apim_backend_show(client, resource_group_name, service_name, backend_id):
1201+
1202+
return client.backend.get(
1203+
resource_group_name=resource_group_name,
1204+
service_name=service_name,
1205+
backend_id=backend_id)
1206+
1207+
def apim_backend_list(client, resource_group_name, service_name):
1208+
1209+
return client.backend.list_by_service(
1210+
resource_group_name=resource_group_name,
1211+
service_name=service_name)
1212+
1213+
def apim_backend_update(
1214+
instance, url=None, protocol=None, description=None,
1215+
title=None, resource_id=None, properties=None):
1216+
1217+
if url is not None:
1218+
instance.url = url
1219+
1220+
if protocol is not None:
1221+
instance.protocol = protocol
1222+
1223+
if description is not None:
1224+
instance.description = description
1225+
1226+
if title is not None:
1227+
instance.title = title
1228+
1229+
if resource_id is not None:
1230+
instance.resource_id = resource_id
1231+
1232+
if properties is not None:
1233+
instance.properties = properties
1234+
1235+
return instance

0 commit comments

Comments
 (0)