Skip to content

Commit d157fbe

Browse files
authored
[containerapp] Add new commands for httprouteconfig (#8302)
1 parent 308d211 commit d157fbe

File tree

8 files changed

+14277
-2
lines changed

8 files changed

+14277
-2
lines changed

src/containerapp/HISTORY.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ upcoming
88
* 'az containerapp connected-env certificate upload/remove': Support `--no-wait`.
99
* 'az containerapp connected-env dapr-component set/remove': Support `--no-wait`.
1010
* 'az containerapp connected-env storage set/remove': Support `--no-wait`.
11+
* 'az containerapp env http-route-config': Add commands for the http-route-config feature area.
1112

1213
1.1.0b1
1314
++++++
@@ -16,7 +17,7 @@ upcoming
1617
* 'az containerapp create/update': `--yaml` support property pollingInterval and cooldownPeriod
1718
* 'az containerapp session code-interpreter upload-file/list-files/show-file-content/show-file-metadata/delete-file': Support `--path` to specify the path of code interpreter session file resource
1819
* 'az containerapp session code-interpreter': Update response payload format for api-version 2024-10-02-preview
19-
* 'az containerapp env maintenance-config add/update/list/remove': Support environment maintenance config management
20+
* 'az containerapp env maintenance-config add/update/list/remove': Support environment maintenance config management
2021
* 'az containerapp sessionpool create': Support managed identity when create session pool with --mi-system-assigned --mi-user-assigned
2122

2223
1.0.0b4

src/containerapp/azext_containerapp/_clients.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,94 @@ def list_usages(cls, cmd, resource_group_name, name):
360360
return r.json()
361361

362362

363+
class HttpRouteConfigPreviewClient:
364+
api_version = PREVIEW_API_VERSION
365+
366+
@classmethod
367+
def create(cls, cmd, resource_group_name, name, http_route_config_name, http_route_config_envelope):
368+
management_hostname = cmd.cli_ctx.cloud.endpoints.resource_manager
369+
sub_id = get_subscription_id(cmd.cli_ctx)
370+
url_fmt = "{}/subscriptions/{}/resourceGroups/{}/providers/Microsoft.App/managedEnvironments/{}/httpRouteConfigs/{}?api-version={}"
371+
request_url = url_fmt.format(
372+
management_hostname.strip('/'),
373+
sub_id,
374+
resource_group_name,
375+
name,
376+
http_route_config_name,
377+
cls.api_version)
378+
379+
r = send_raw_request(cmd.cli_ctx, "PUT", request_url, body=json.dumps(http_route_config_envelope))
380+
return r.json()
381+
382+
@classmethod
383+
def update(cls, cmd, resource_group_name, name, http_route_config_name, http_route_config_envelope):
384+
management_hostname = cmd.cli_ctx.cloud.endpoints.resource_manager
385+
sub_id = get_subscription_id(cmd.cli_ctx)
386+
url_fmt = "{}/subscriptions/{}/resourceGroups/{}/providers/Microsoft.App/managedEnvironments/{}/httpRouteConfigs/{}?api-version={}"
387+
request_url = url_fmt.format(
388+
management_hostname.strip('/'),
389+
sub_id,
390+
resource_group_name,
391+
name,
392+
http_route_config_name,
393+
cls.api_version)
394+
395+
r = send_raw_request(cmd.cli_ctx, "PATCH", request_url, body=json.dumps(http_route_config_envelope))
396+
return r.json()
397+
398+
@classmethod
399+
def list(cls, cmd, resource_group_name, name):
400+
route_list = []
401+
management_hostname = cmd.cli_ctx.cloud.endpoints.resource_manager
402+
sub_id = get_subscription_id(cmd.cli_ctx)
403+
url_fmt = "{}/subscriptions/{}/resourceGroups/{}/providers/Microsoft.App/managedEnvironments/{}/httpRouteConfigs?api-version={}"
404+
request_url = url_fmt.format(
405+
management_hostname.strip('/'),
406+
sub_id,
407+
resource_group_name,
408+
name,
409+
cls.api_version)
410+
411+
r = send_raw_request(cmd.cli_ctx, "GET", request_url, body=None)
412+
j = r.json()
413+
for route in j["value"]:
414+
route_list.append(route)
415+
return route_list
416+
417+
@classmethod
418+
def show(cls, cmd, resource_group_name, name, http_route_config_name):
419+
management_hostname = cmd.cli_ctx.cloud.endpoints.resource_manager
420+
sub_id = get_subscription_id(cmd.cli_ctx)
421+
url_fmt = "{}/subscriptions/{}/resourceGroups/{}/providers/Microsoft.App/managedEnvironments/{}/httpRouteConfigs/{}?api-version={}"
422+
request_url = url_fmt.format(
423+
management_hostname.strip('/'),
424+
sub_id,
425+
resource_group_name,
426+
name,
427+
http_route_config_name,
428+
cls.api_version)
429+
430+
r = send_raw_request(cmd.cli_ctx, "GET", request_url, body=None)
431+
return r.json()
432+
433+
@classmethod
434+
def delete(cls, cmd, resource_group_name, name, http_route_config_name):
435+
management_hostname = cmd.cli_ctx.cloud.endpoints.resource_manager
436+
sub_id = get_subscription_id(cmd.cli_ctx)
437+
url_fmt = "{}/subscriptions/{}/resourceGroups/{}/providers/Microsoft.App/managedEnvironments/{}/httpRouteConfigs/{}?api-version={}"
438+
request_url = url_fmt.format(
439+
management_hostname.strip('/'),
440+
sub_id,
441+
resource_group_name,
442+
name,
443+
http_route_config_name,
444+
cls.api_version)
445+
446+
send_raw_request(cmd.cli_ctx, "DELETE", request_url, body=None)
447+
# API doesn't return JSON (it returns no content)
448+
return
449+
450+
363451
class AuthPreviewClient(AuthClient):
364452
api_version = PREVIEW_API_VERSION
365453

src/containerapp/azext_containerapp/_help.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2198,3 +2198,53 @@
21982198
text: |
21992199
az containerapp debug -n MyContainerapp -g MyResourceGroup --revision MyRevision --replica MyReplica --container MyContainer
22002200
"""
2201+
2202+
helps['containerapp env http-route-config'] = """
2203+
type: group
2204+
short-summary: Commands to manage environment level http routing.
2205+
"""
2206+
2207+
helps['containerapp env http-route-config list'] = """
2208+
type: command
2209+
short-summary: List the http route configs in the environment.
2210+
examples:
2211+
- name: List the http route configs in the environment.
2212+
text: |
2213+
az containerapp env http-route-config list -g MyResourceGroup -n MyEnvironment
2214+
"""
2215+
2216+
helps['containerapp env http-route-config create'] = """
2217+
type: command
2218+
short-summary: Create a new http route config.
2219+
examples:
2220+
- name: Create a new route from a yaml file.
2221+
text: |
2222+
az containerapp env http-route-config create -g MyResourceGroup -n MyEnvironment -r configname --yaml config.yaml
2223+
"""
2224+
2225+
helps['containerapp env http-route-config update'] = """
2226+
type: command
2227+
short-summary: Update a http route config.
2228+
examples:
2229+
- name: Update a route in the environment from a yaml file.
2230+
text: |
2231+
az containerapp env http-route-config update -g MyResourceGroup -n MyEnvironment -r configname --yaml config.yaml
2232+
"""
2233+
2234+
helps['containerapp env http-route-config show'] = """
2235+
type: command
2236+
short-summary: Show a http route config.
2237+
examples:
2238+
- name: Show a route in the environment.
2239+
text: |
2240+
az containerapp env http-route-config show -g MyResourceGroup -n MyEnvironment -r configname
2241+
"""
2242+
2243+
helps['containerapp env http-route-config delete'] = """
2244+
type: command
2245+
short-summary: Delete a http route config.
2246+
examples:
2247+
- name: Delete a route from the environment.
2248+
text: |
2249+
az containerapp env http-route-config delete -g MyResourceGroup -n MyEnvironment -r configname
2250+
"""

src/containerapp/azext_containerapp/_params.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ def load_arguments(self, _):
8383
c.argument('logs_dynamic_json_columns', options_list=['--logs-dynamic-json-columns', '-j'], arg_type=get_three_state_flag(),
8484
help='Boolean indicating whether to parse json string log into dynamic json columns. Only work for destination log-analytics.', is_preview=True)
8585

86+
# HttpRouteConfig
87+
with self.argument_context('containerapp env http-route-config') as c:
88+
c.argument('http_route_config_name', options_list=['--http-route-config-name', '-r'], help="The name of the http route configuration.")
89+
c.argument('yaml', help="The path to the YAML input file.")
90+
c.argument('name', id_part=None)
91+
8692
# Telemetry
8793
with self.argument_context('containerapp env telemetry') as c:
8894
c.argument('name', id_part=None)

src/containerapp/azext_containerapp/commands.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ def load_command_table(self, args):
3939
g.custom_command('delete', 'delete_managed_environment', supports_no_wait=True, confirmation=True, exception_handler=ex_handler_factory())
4040
g.custom_command('update', 'update_managed_environment', supports_no_wait=True, exception_handler=ex_handler_factory())
4141

42+
with self.command_group('containerapp env http-route-config', is_preview=True) as g:
43+
g.custom_show_command('show', 'show_http_route_config')
44+
g.custom_command('list', 'list_http_route_configs')
45+
g.custom_command('create', 'create_http_route_config', exception_handler=ex_handler_factory())
46+
g.custom_command('update', 'update_http_route_config', exception_handler=ex_handler_factory())
47+
g.custom_command('delete', 'delete_http_route_config', confirmation=True, exception_handler=ex_handler_factory())
48+
4249
with self.command_group('containerapp job') as g:
4350
g.custom_show_command('show', 'show_containerappsjob')
4451
g.custom_command('list', 'list_containerappsjob')

src/containerapp/azext_containerapp/custom.py

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@
106106
SessionPoolPreviewClient,
107107
SessionCodeInterpreterPreviewClient,
108108
DotNetComponentPreviewClient,
109-
MaintenanceConfigPreviewClient
109+
MaintenanceConfigPreviewClient,
110+
HttpRouteConfigPreviewClient
110111
)
111112
from ._dev_service_utils import DevServiceUtils
112113
from ._models import (
@@ -3360,3 +3361,57 @@ def containerapp_debug(cmd, resource_group_name, name, container=None, revision=
33603361
if conn.is_connected:
33613362
logger.info("Caught KeyboardInterrupt. Sending ctrl+c to server")
33623363
conn.send(SSH_CTRL_C_MSG)
3364+
3365+
3366+
def create_http_route_config(cmd, resource_group_name, name, http_route_config_name, yaml):
3367+
_validate_subscription_registered(cmd, CONTAINER_APPS_RP)
3368+
yaml_http_route_config = load_yaml_file(yaml)
3369+
# check if the type is dict
3370+
if not isinstance(yaml_http_route_config, dict):
3371+
raise ValidationError('Invalid YAML provided. Please see https://aka.ms/azure-container-apps-yaml for a valid YAML spec.')
3372+
3373+
http_route_config_envelope = {"properties": yaml_http_route_config}
3374+
3375+
try:
3376+
return HttpRouteConfigPreviewClient.create(cmd, resource_group_name, name, http_route_config_name, http_route_config_envelope)
3377+
except Exception as e:
3378+
handle_raw_exception(e)
3379+
3380+
3381+
def update_http_route_config(cmd, resource_group_name, name, http_route_config_name, yaml):
3382+
_validate_subscription_registered(cmd, CONTAINER_APPS_RP)
3383+
yaml_http_route_config = load_yaml_file(yaml)
3384+
# check if the type is dict
3385+
if not isinstance(yaml_http_route_config, dict):
3386+
raise ValidationError('Invalid YAML provided. Please see https://aka.ms/azure-container-apps-yaml for a valid YAML spec.')
3387+
3388+
http_route_config_envelope = {"properties": yaml_http_route_config}
3389+
3390+
try:
3391+
return HttpRouteConfigPreviewClient.update(cmd, resource_group_name, name, http_route_config_name, http_route_config_envelope)
3392+
except Exception as e:
3393+
handle_raw_exception(e)
3394+
3395+
3396+
def list_http_route_configs(cmd, resource_group_name, name):
3397+
_validate_subscription_registered(cmd, CONTAINER_APPS_RP)
3398+
try:
3399+
return HttpRouteConfigPreviewClient.list(cmd, resource_group_name, name)
3400+
except Exception as e:
3401+
handle_raw_exception(e)
3402+
3403+
3404+
def show_http_route_config(cmd, resource_group_name, name, http_route_config_name):
3405+
_validate_subscription_registered(cmd, CONTAINER_APPS_RP)
3406+
try:
3407+
return HttpRouteConfigPreviewClient.show(cmd, resource_group_name, name, http_route_config_name)
3408+
except Exception as e:
3409+
handle_raw_exception(e)
3410+
3411+
3412+
def delete_http_route_config(cmd, resource_group_name, name, http_route_config_name):
3413+
_validate_subscription_registered(cmd, CONTAINER_APPS_RP)
3414+
try:
3415+
return HttpRouteConfigPreviewClient.delete(cmd, resource_group_name, name, http_route_config_name)
3416+
except Exception as e:
3417+
handle_raw_exception(e)

0 commit comments

Comments
 (0)