Skip to content

Commit 3f4f4cf

Browse files
committed
Add httprouteconfig crud commands with yaml
1 parent 6a1c3ca commit 3f4f4cf

File tree

4 files changed

+165
-1
lines changed

4 files changed

+165
-1
lines changed

src/azure-cli/azure/cli/command_modules/containerapp/_clients.py

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
logger = get_logger(__name__)
1818

19-
CURRENT_API_VERSION = "2024-03-01"
19+
CURRENT_API_VERSION = "2024-10-02-preview" # "2024-03-01"
2020
POLLING_TIMEOUT = 1200 # how many seconds before exiting
2121
POLLING_SECONDS = 2 # how many seconds between requests
2222
POLLING_TIMEOUT_FOR_MANAGED_CERTIFICATE = 1500 # how many seconds before exiting
@@ -772,6 +772,73 @@ def delete_managed_certificate(cls, cmd, resource_group_name, name, certificate_
772772

773773
return send_raw_request(cmd.cli_ctx, "DELETE", request_url, body=None)
774774

775+
@classmethod
776+
def update_httprouteconfig(cls, cmd, resource_group_name, name, httprouteconfig_name, httprouteconfig_envelope):
777+
management_hostname = cmd.cli_ctx.cloud.endpoints.resource_manager
778+
sub_id = get_subscription_id(cmd.cli_ctx)
779+
url_fmt = "{}/subscriptions/{}/resourceGroups/{}/providers/Microsoft.App/managedEnvironments/{}/httpRouteConfigs/{}?api-version={}"
780+
request_url = url_fmt.format(
781+
management_hostname.strip('/'),
782+
sub_id,
783+
resource_group_name,
784+
name,
785+
httprouteconfig_name,
786+
cls.api_version)
787+
788+
r = send_raw_request(cmd.cli_ctx, "PUT", request_url, body=json.dumps(httprouteconfig_envelope))
789+
return r.json()
790+
791+
@classmethod
792+
def list_httprouteconfigs(cls, cmd, resource_group_name, name, formatter=lambda x: x):
793+
route_list = []
794+
management_hostname = cmd.cli_ctx.cloud.endpoints.resource_manager
795+
sub_id = get_subscription_id(cmd.cli_ctx)
796+
url_fmt = "{}/subscriptions/{}/resourceGroups/{}/providers/Microsoft.App/managedEnvironments/{}/httpRouteConfigs?api-version={}"
797+
request_url = url_fmt.format(
798+
management_hostname.strip('/'),
799+
sub_id,
800+
resource_group_name,
801+
name,
802+
cls.api_version)
803+
804+
r = send_raw_request(cmd.cli_ctx, "GET", request_url, body=None)
805+
j = r.json()
806+
for route in j["value"]:
807+
formatted = formatter(route)
808+
route_list.append(formatted)
809+
return route_list
810+
811+
@classmethod
812+
def show_httprouteconfig(cls, cmd, resource_group_name, name, httprouteconfig_name):
813+
management_hostname = cmd.cli_ctx.cloud.endpoints.resource_manager
814+
sub_id = get_subscription_id(cmd.cli_ctx)
815+
url_fmt = "{}/subscriptions/{}/resourceGroups/{}/providers/Microsoft.App/managedEnvironments/{}/httpRouteConfigs/{}?api-version={}"
816+
request_url = url_fmt.format(
817+
management_hostname.strip('/'),
818+
sub_id,
819+
resource_group_name,
820+
name,
821+
httprouteconfig_name,
822+
cls.api_version)
823+
824+
r = send_raw_request(cmd.cli_ctx, "GET", request_url, body=None)
825+
return r.json()
826+
827+
@classmethod
828+
def delete_httprouteconfig(cls, cmd, resource_group_name, name, httprouteconfig_name):
829+
management_hostname = cmd.cli_ctx.cloud.endpoints.resource_manager
830+
sub_id = get_subscription_id(cmd.cli_ctx)
831+
url_fmt = "{}/subscriptions/{}/resourceGroups/{}/providers/Microsoft.App/managedEnvironments/{}/httpRouteConfigs/{}?api-version={}"
832+
request_url = url_fmt.format(
833+
management_hostname.strip('/'),
834+
sub_id,
835+
resource_group_name,
836+
name,
837+
httprouteconfig_name,
838+
cls.api_version)
839+
840+
return send_raw_request(cmd.cli_ctx, "DELETE", request_url, body=None)
841+
775842
@classmethod
776843
def check_name_availability(cls, cmd, resource_group_name, name, name_availability_request):
777844
management_hostname = cmd.cli_ctx.cloud.endpoints.resource_manager

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,56 @@
498498
az containerapp env dapr-component remove -g MyResourceGroup --dapr-component-name MyDaprComponentName --name MyEnvironment
499499
"""
500500

501+
helps['containerapp env httprouteconfig'] = """
502+
type: group
503+
short-summary: Commands to manage environment level http routing.
504+
"""
505+
506+
helps['containerapp env httprouteconfig list'] = """
507+
type: command
508+
short-summary: List the http route configs in the environment.
509+
examples:
510+
- name: List the http route configs in the environment.
511+
text: |
512+
az containerapp env httprouteconfig list -g MyResourceGroup -n MyEnvironment
513+
"""
514+
515+
helps['containerapp env httprouteconfig create'] = """
516+
type: command
517+
short-summary: Create a new http route config.
518+
examples:
519+
- name: Create a new route from a yaml file.
520+
text: |
521+
az containerapp env httprouteconfig create -g MyResourceGroup -n MyEnvironment --httprouteconfig-name configname --yaml config.yaml
522+
"""
523+
524+
helps['containerapp env httprouteconfig update'] = """
525+
type: command
526+
short-summary: Update a http route config.
527+
examples:
528+
- name: Updates a route in the environment from a yaml file.
529+
text: |
530+
az containerapp env httprouteconfig update -g MyResourceGroup -n MyEnvironment --httprouteconfig-name configname --yaml config.yaml
531+
"""
532+
533+
helps['containerapp env httprouteconfig show'] = """
534+
type: command
535+
short-summary: Show a http route config.
536+
examples:
537+
- name: Shows a route from the environment.
538+
text: |
539+
az containerapp env httprouteconfig show -g MyResourceGroup -n MyEnvironment --httprouteconfig-name configname
540+
"""
541+
542+
helps['containerapp env httprouteconfig delete'] = """
543+
type: command
544+
short-summary: Delete a http route config.
545+
examples:
546+
- name: Deletes a route from the environment.
547+
text: |
548+
az containerapp env httprouteconfig delete -g MyResourceGroup -n MyEnvironment --httprouteconfig-name configname
549+
"""
550+
501551
helps['containerapp env storage'] = """
502552
type: group
503553
short-summary: Commands to manage storage for the Container Apps environment.

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ def load_command_table(self, _):
4949
g.custom_command('update', 'update_managed_environment', supports_no_wait=True, exception_handler=ex_handler_factory())
5050
g.custom_command('list-usages', 'list_environment_usages', table_transformer=transform_usages_output)
5151

52+
with self.command_group('containerapp env httprouteconfig') as g:
53+
g.custom_show_command('show', 'show_httprouteconfig')
54+
g.custom_command('list', 'list_httprouteconfigs')
55+
g.custom_command('create', 'update_httprouteconfig', exception_handler=ex_handler_factory())
56+
g.custom_command('update', 'update_httprouteconfig', exception_handler=ex_handler_factory())
57+
g.custom_command('delete', 'delete_httprouteconfig', confirmation=True, exception_handler=ex_handler_factory())
58+
5259
with self.command_group('containerapp job') as g:
5360
g.custom_show_command('show', 'show_containerappsjob')
5461
g.custom_command('list', 'list_containerappsjob')

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,46 @@ def delete_managed_environment(cmd, name, resource_group_name, no_wait=False):
955955
return containerapp_env_decorator.delete()
956956

957957

958+
def update_httprouteconfig(cmd, resource_group_name, name, httprouteconfig_name, yaml):
959+
yaml_httprouteconfig = load_yaml_file(yaml)
960+
# check if the type is dict
961+
if not isinstance(yaml_httprouteconfig, dict):
962+
raise ValidationError('Invalid YAML provided. Please see https://aka.ms/azure-container-apps-job-yaml for a valid YAML spec.')
963+
964+
httprouteconfig_envelope = {}
965+
966+
httprouteconfig_envelope["properties"] = yaml_httprouteconfig
967+
968+
try:
969+
return ManagedEnvironmentClient.update_httprouteconfig(cmd, resource_group_name, name, httprouteconfig_name, httprouteconfig_envelope)
970+
except Exception as e:
971+
handle_raw_exception(e)
972+
973+
974+
def list_httprouteconfigs(cmd, resource_group_name, name):
975+
_validate_subscription_registered(cmd, CONTAINER_APPS_RP)
976+
try:
977+
return ManagedEnvironmentClient.list_httprouteconfigs(cmd, resource_group_name, name)
978+
except Exception as e:
979+
handle_raw_exception(e)
980+
981+
982+
def show_httprouteconfig(cmd, resource_group_name, name, httprouteconfig_name):
983+
_validate_subscription_registered(cmd, CONTAINER_APPS_RP)
984+
try:
985+
return ManagedEnvironmentClient.show_httprouteconfig(cmd, resource_group_name, name, httprouteconfig_name)
986+
except Exception as e:
987+
handle_raw_exception(e)
988+
989+
990+
def delete_httprouteconfig(cmd, resource_group_name, name, httprouteconfig_name):
991+
_validate_subscription_registered(cmd, CONTAINER_APPS_RP)
992+
try:
993+
return ManagedEnvironmentClient.delete_httprouteconfig(cmd, resource_group_name, name, httprouteconfig_name)
994+
except Exception as e:
995+
handle_raw_exception(e)
996+
997+
958998
def create_containerappsjob(cmd,
959999
name,
9601000
resource_group_name,

0 commit comments

Comments
 (0)