Skip to content
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ __pycache__/
env/
env27/
venv/
.venv/
.python-version

# PTVS analysis
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,7 @@ def cf_graphqlapiresolver(cli_ctx, *_):

def cf_graphqlapiresolverpolicy(cli_ctx, *_):
return cf_apim(cli_ctx).graph_ql_api_resolver_policy


def cf_backend(cli_ctx, *_):
return cf_apim(cli_ctx).backend
68 changes: 68 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 @@ -88,6 +88,11 @@
short-summary: Manage soft-deleted Azure API Management services.
"""

helps['apim backend'] = """
type: group
short-summary: Manage Azure API Management Backends.
"""

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 @@ -749,3 +754,66 @@
text: |
az apim graphql resolver policy list --service-name MyApim -g MyResourceGroup --api-id MyApi --resolver-id MyResolverId
"""

helps['apim backend list'] = """
type: command
short-summary: List API Management Backends.
examples:
- name: List all Backends in an APIM instance.
text: |-
az apim backend list --resource-group MyResourceGroup --service-name MyServiceName
"""

helps['apim backend show'] = """
type: command
short-summary: Show details of an API Management Backend.
examples:
- name: Show details of a Backend in an APIM instance.
text: |-
az apim backend show --resource-group MyResourceGroup --service-name MyServiceName --backend-id MyBackendId
"""

helps['apim backend delete'] = """
type: command
short-summary: Delete an API Management Backend.
examples:
- name: Delete a Backend in an APIM instance.
text: |-
az apim backend delete --resource-group MyResourceGroup --service-name MyServiceName --backend-id MyBackendId
"""

helps['apim backend create'] = """
type: command
short-summary: Create or Update an API Management Backend.
parameters:
- name: --backend-id
type: string
short-summary: unique name for the Backend to be created or updated
long-summary: |
Must be unique in the current API Management service instance.
- name: --url
type: string
short-summary: The URL of the backend service.
- name: --protocol
type: string
short-summary: The protocol used to communicate with the backend service.
examples:
- name: Create a Backend.
text: |-
az apim backend create --service-name MyApim -g MyResourceGroup --backend-id MyBackendId --url https://mybackend.com --protocol http
"""

helps['apim backend update'] = """
type: command
short-summary: Update an API Management Backend.
parameters:
- name: --backend-id
type: string
short-summary: unique name of the Backend to be updated
long-summary: |
Must be unique in the current API Management service instance.
examples:
- name: Update a Backend.
text: |-
az apim backend update --service-name MyApim -g MyResourceGroup --backend-id MyBackendId --url https://mynewbackend.com
"""
39 changes: 38 additions & 1 deletion src/azure-cli/azure/cli/command_modules/apim/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
resource_group_name_type,
get_three_state_flag)

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


SKU_TYPES = SkuType
VNET_TYPES = VirtualNetworkType
API_PROTOCOLS = Protocol
API_TYPES = ApiType
BACKEND_PROTOCOLS = BackendProtocol


class ImportFormat(Enum):
Expand Down Expand Up @@ -51,6 +52,8 @@ def load_arguments(self, _):
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.')
schema_id = CLIArgumentType(arg_group='Schema',
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.')
backend_id = CLIArgumentType(arg_group='Backend',
help='Backend identifier. Must be unique in the current API Management service instance.')

from azure.cli.core.commands.parameters import tags_type
from azure.cli.core.commands.validators import get_default_location_from_resource_group
Expand Down Expand Up @@ -502,3 +505,37 @@ def load_arguments(self, _):
c.argument('api_id', arg_type=api_id)
c.argument('resolver_id', help='Resolver identifier within a GraphQL API. Must be unique in the current API Management service instance.')
c.argument('if_match', help='ETag of the Entity.')

with self.argument_context('apim backend create') as c:
c.argument('service_name', options_list=['--service-name', '-n'],
help='The name of the API Management service instance.')
c.argument('backend_id', arg_type=backend_id, help='Identifier of the Backend.')
c.argument('url', help='Required. Backend service URL.')
c.argument('protocol', arg_type=get_enum_type(BACKEND_PROTOCOLS),
help='Protocol used to communicate with the backend service. Possible values include: `http`, `soap`.')
c.argument('description', help='Description of the Backend. May include HTML formatting tags.')
c.argument('if_match', help='ETag of the Entity.')

with self.argument_context('apim backend update') as c:
c.argument('service_name', options_list=['--service-name', '-n'],
help='The name of the API Management service instance.')
c.argument('backend_id', arg_type=backend_id, help='Identifier of the Backend.')
c.argument('url', help='Required. Backend service URL.')
c.argument('protocol', arg_type=get_enum_type(BACKEND_PROTOCOLS),
help='Protocol used to communicate with the backend service. Possible values include: `http`, `soap`.')
c.argument('description', help='Description of the Backend. May include HTML formatting tags.')

with self.argument_context('apim backend delete') as c:
c.argument('service_name', options_list=['--service-name', '-n'],
help='The name of the API Management service instance.')
c.argument('backend_id', arg_type=backend_id, help='Identifier of the Backend.')
c.argument('if_match', help='ETag of the Entity.')

with self.argument_context('apim backend show') as c:
c.argument('service_name', options_list=['--service-name', '-n'],
help='The name of the API Management service instance.')
c.argument('backend_id', arg_type=backend_id, help='Identifier of the Backend.')

with self.argument_context('apim backend list') as c:
c.argument('service_name', options_list=['--service-name', '-n'],
help='The name of the API Management service instance.')
14 changes: 13 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 @@ -11,7 +11,7 @@
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_ds, cf_graphqlapiresolver,
cf_graphqlapiresolverpolicy)
cf_graphqlapiresolverpolicy, cf_backend)


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

backend_sdk = CliCommandType(
operations_tmpl='azure.mgmt.apimanagement.operations#BackendOperations.{}',
client_factory=cf_backend
)

# 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 @@ -178,3 +183,10 @@ def load_command_table(self, _):
g.custom_command('delete', 'apim_graphql_resolver_policy_delete', confirmation=True)
g.custom_show_command('show', 'apim_graphql_resolver_policy_show')
g.custom_command('list', 'apim_graphql_resolver_policy_list')

with self.command_group('apim backend', backend_sdk) as g:
g.custom_command('create', 'apim_backend_create')
g.custom_show_command('show', 'apim_backend_show')
g.custom_command('list', 'apim_backend_list')
g.custom_command('delete', 'apim_backend_delete', confirmation=True)
g.generic_update_command('update', custom_func_name='apim_backend_update')
62 changes: 61 additions & 1 deletion src/azure-cli/azure/cli/command_modules/apim/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
OpenIdAuthenticationSettingsContract, ProductContract, ProductState,
NamedValueCreateContract, VersioningScheme, ApiVersionSetContract,
OperationContract, ApiManagementServiceCheckNameAvailabilityParameters,
ApiReleaseContract, SchemaContract, ResolverContract, PolicyContract)
ApiReleaseContract, SchemaContract, ResolverContract, PolicyContract,
BackendContract)

logger = get_logger(__name__)

Expand Down Expand Up @@ -1165,3 +1166,62 @@ def apim_graphql_resolver_policy_delete(
resolver_id=resolver_id,
policy_id="policy",
if_match="*" if if_match is None else if_match)


def apim_backend_create(
client, resource_group_name, service_name, backend_id, url, protocol, description=None,
no_wait=False, if_match=None):

parameters = BackendContract(
url=url,
protocol=protocol,
description=description
)

return sdk_no_wait(no_wait, client.backend.create_or_update,
resource_group_name=resource_group_name,
service_name=service_name,
backend_id=backend_id,
parameters=parameters,
if_match="*" if if_match is None else if_match)


def apim_backend_delete(
client, resource_group_name, service_name, backend_id, if_match=None, no_wait=False):

return sdk_no_wait(no_wait,
client.backend.delete,
resource_group_name=resource_group_name,
service_name=service_name,
backend_id=backend_id,
if_match="*" if if_match is None else if_match)


def apim_backend_show(client, resource_group_name, service_name, backend_id):

return client.backend.get(
resource_group_name=resource_group_name,
service_name=service_name,
backend_id=backend_id)


def apim_backend_list(client, resource_group_name, service_name):

return client.backend.list_by_service(
resource_group_name=resource_group_name,
service_name=service_name)


def apim_backend_update(
instance, url=None, protocol=None, description=None):

if url is not None:
instance.url = url

if protocol is not None:
instance.protocol = protocol

if description is not None:
instance.description = description

return instance
Loading