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

[containerapp] Add new commands for httprouteconfig #8302

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
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
3 changes: 2 additions & 1 deletion src/containerapp/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Release History
upcoming
++++++
* 'az containerapp debug': Open an SSH-like interactive shell within a container app debug console.
* 'az containerapp env http-route-config': Add commands for the http-route-config feature area.

1.1.0b1
++++++
Expand All @@ -13,7 +14,7 @@ upcoming
* 'az containerapp create/update': `--yaml` support property pollingInterval and cooldownPeriod
* '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
* 'az containerapp session code-interpreter': Update response payload format for api-version 2024-10-02-preview
* 'az containerapp env maintenance-config add/update/list/remove': Support environment maintenance config management
* 'az containerapp env maintenance-config add/update/list/remove': Support environment maintenance config management
* 'az containerapp sessionpool create': Support managed identity when create session pool with --mi-system-assigned --mi-user-assigned

1.0.0b4
Expand Down
88 changes: 88 additions & 0 deletions src/containerapp/azext_containerapp/_clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,94 @@ def list_usages(cls, cmd, resource_group_name, name):
return r.json()


class HttpRouteConfigPreviewClient:
api_version = PREVIEW_API_VERSION

@classmethod
def create(cls, cmd, resource_group_name, name, http_route_config_name, http_route_config_envelope):
management_hostname = cmd.cli_ctx.cloud.endpoints.resource_manager
sub_id = get_subscription_id(cmd.cli_ctx)
url_fmt = "{}/subscriptions/{}/resourceGroups/{}/providers/Microsoft.App/managedEnvironments/{}/httpRouteConfigs/{}?api-version={}"
request_url = url_fmt.format(
management_hostname.strip('/'),
sub_id,
resource_group_name,
name,
http_route_config_name,
cls.api_version)

r = send_raw_request(cmd.cli_ctx, "PUT", request_url, body=json.dumps(http_route_config_envelope))
return r.json()

@classmethod
def update(cls, cmd, resource_group_name, name, http_route_config_name, http_route_config_envelope):
management_hostname = cmd.cli_ctx.cloud.endpoints.resource_manager
sub_id = get_subscription_id(cmd.cli_ctx)
url_fmt = "{}/subscriptions/{}/resourceGroups/{}/providers/Microsoft.App/managedEnvironments/{}/httpRouteConfigs/{}?api-version={}"
request_url = url_fmt.format(
management_hostname.strip('/'),
sub_id,
resource_group_name,
name,
http_route_config_name,
cls.api_version)

r = send_raw_request(cmd.cli_ctx, "PATCH", request_url, body=json.dumps(http_route_config_envelope))
return r.json()

@classmethod
def list(cls, cmd, resource_group_name, name):
route_list = []
management_hostname = cmd.cli_ctx.cloud.endpoints.resource_manager
sub_id = get_subscription_id(cmd.cli_ctx)
url_fmt = "{}/subscriptions/{}/resourceGroups/{}/providers/Microsoft.App/managedEnvironments/{}/httpRouteConfigs?api-version={}"
request_url = url_fmt.format(
management_hostname.strip('/'),
sub_id,
resource_group_name,
name,
cls.api_version)

r = send_raw_request(cmd.cli_ctx, "GET", request_url, body=None)
j = r.json()
for route in j["value"]:
Tratcher marked this conversation as resolved.
Show resolved Hide resolved
route_list.append(route)
return route_list

@classmethod
def show(cls, cmd, resource_group_name, name, http_route_config_name):
management_hostname = cmd.cli_ctx.cloud.endpoints.resource_manager
sub_id = get_subscription_id(cmd.cli_ctx)
url_fmt = "{}/subscriptions/{}/resourceGroups/{}/providers/Microsoft.App/managedEnvironments/{}/httpRouteConfigs/{}?api-version={}"
request_url = url_fmt.format(
management_hostname.strip('/'),
sub_id,
resource_group_name,
name,
http_route_config_name,
cls.api_version)

r = send_raw_request(cmd.cli_ctx, "GET", request_url, body=None)
return r.json()

@classmethod
def delete(cls, cmd, resource_group_name, name, http_route_config_name):
management_hostname = cmd.cli_ctx.cloud.endpoints.resource_manager
sub_id = get_subscription_id(cmd.cli_ctx)
url_fmt = "{}/subscriptions/{}/resourceGroups/{}/providers/Microsoft.App/managedEnvironments/{}/httpRouteConfigs/{}?api-version={}"
request_url = url_fmt.format(
management_hostname.strip('/'),
sub_id,
resource_group_name,
name,
http_route_config_name,
cls.api_version)

send_raw_request(cmd.cli_ctx, "DELETE", request_url, body=None)
# API doesn't return JSON (it returns no content)
return


class AuthPreviewClient(AuthClient):
api_version = PREVIEW_API_VERSION

Expand Down
50 changes: 50 additions & 0 deletions src/containerapp/azext_containerapp/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -2198,3 +2198,53 @@
text: |
az containerapp debug -n MyContainerapp -g MyResourceGroup --revision MyRevision --replica MyReplica --container MyContainer
"""

helps['containerapp env http-route-config'] = """
type: group
short-summary: Commands to manage environment level http routing.
"""

helps['containerapp env http-route-config list'] = """
type: command
short-summary: List the http route configs in the environment.
examples:
- name: List the http route configs in the environment.
text: |
az containerapp env http-route-config list -g MyResourceGroup -n MyEnvironment
"""

helps['containerapp env http-route-config create'] = """
type: command
short-summary: Create a new http route config.
examples:
- name: Create a new route from a yaml file.
text: |
az containerapp env http-route-config create -g MyResourceGroup -n MyEnvironment -r configname --yaml config.yaml
"""

helps['containerapp env http-route-config update'] = """
type: command
short-summary: Update a http route config.
examples:
- name: Update a route in the environment from a yaml file.
text: |
az containerapp env http-route-config update -g MyResourceGroup -n MyEnvironment -r configname --yaml config.yaml
"""

helps['containerapp env http-route-config show'] = """
type: command
short-summary: Show a http route config.
examples:
- name: Show a route in the environment.
text: |
az containerapp env http-route-config show -g MyResourceGroup -n MyEnvironment -r configname
"""

helps['containerapp env http-route-config delete'] = """
type: command
short-summary: Delete a http route config.
examples:
- name: Delete a route from the environment.
text: |
az containerapp env http-route-config delete -g MyResourceGroup -n MyEnvironment -r configname
"""
5 changes: 5 additions & 0 deletions src/containerapp/azext_containerapp/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ def load_arguments(self, _):
c.argument('logs_dynamic_json_columns', options_list=['--logs-dynamic-json-columns', '-j'], arg_type=get_three_state_flag(),
help='Boolean indicating whether to parse json string log into dynamic json columns. Only work for destination log-analytics.', is_preview=True)

# HttpRouteConfig
with self.argument_context('containerapp env http-route-config') as c:
c.argument('http_route_config_name', options_list=['--http-route-config-name', '-r'], help="The name of the http route configuration.")
c.argument('yaml', help="The path to the YAML input file.")

# Telemetry
with self.argument_context('containerapp env telemetry') as c:
c.argument('name', id_part=None)
Expand Down
7 changes: 7 additions & 0 deletions src/containerapp/azext_containerapp/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ def load_command_table(self, args):
g.custom_command('delete', 'delete_managed_environment', supports_no_wait=True, confirmation=True, exception_handler=ex_handler_factory())
g.custom_command('update', 'update_managed_environment', supports_no_wait=True, exception_handler=ex_handler_factory())

with self.command_group('containerapp env http-route-config', is_preview=True) as g:
g.custom_show_command('show', 'show_http_route_config')
g.custom_command('list', 'list_http_route_configs')
g.custom_command('create', 'create_http_route_config', exception_handler=ex_handler_factory())
g.custom_command('update', 'update_http_route_config', exception_handler=ex_handler_factory())
g.custom_command('delete', 'delete_http_route_config', confirmation=True, exception_handler=ex_handler_factory())

with self.command_group('containerapp job') as g:
g.custom_show_command('show', 'show_containerappsjob')
g.custom_command('list', 'list_containerappsjob')
Expand Down
57 changes: 56 additions & 1 deletion src/containerapp/azext_containerapp/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@
SessionPoolPreviewClient,
SessionCodeInterpreterPreviewClient,
DotNetComponentPreviewClient,
MaintenanceConfigPreviewClient
MaintenanceConfigPreviewClient,
HttpRouteConfigPreviewClient
)
from ._dev_service_utils import DevServiceUtils
from ._models import (
Expand Down Expand Up @@ -3359,3 +3360,57 @@ def containerapp_debug(cmd, resource_group_name, name, container=None, revision=
if conn.is_connected:
logger.info("Caught KeyboardInterrupt. Sending ctrl+c to server")
conn.send(SSH_CTRL_C_MSG)


def create_http_route_config(cmd, resource_group_name, name, http_route_config_name, yaml):
_validate_subscription_registered(cmd, CONTAINER_APPS_RP)
yaml_http_route_config = load_yaml_file(yaml)
# check if the type is dict
if not isinstance(yaml_http_route_config, dict):
raise ValidationError('Invalid YAML provided. Please see https://aka.ms/azure-container-apps-yaml for a valid YAML spec.')
Tratcher marked this conversation as resolved.
Show resolved Hide resolved

http_route_config_envelope = {"properties": yaml_http_route_config}

try:
return HttpRouteConfigPreviewClient.create(cmd, resource_group_name, name, http_route_config_name, http_route_config_envelope)
except Exception as e:
handle_raw_exception(e)


def update_http_route_config(cmd, resource_group_name, name, http_route_config_name, yaml):
_validate_subscription_registered(cmd, CONTAINER_APPS_RP)
yaml_http_route_config = load_yaml_file(yaml)
# check if the type is dict
if not isinstance(yaml_http_route_config, dict):
raise ValidationError('Invalid YAML provided. Please see https://aka.ms/azure-container-apps-yaml for a valid YAML spec.')

http_route_config_envelope = {"properties": yaml_http_route_config}

try:
return HttpRouteConfigPreviewClient.update(cmd, resource_group_name, name, http_route_config_name, http_route_config_envelope)
except Exception as e:
handle_raw_exception(e)


def list_http_route_configs(cmd, resource_group_name, name):
_validate_subscription_registered(cmd, CONTAINER_APPS_RP)
Tratcher marked this conversation as resolved.
Show resolved Hide resolved
try:
return HttpRouteConfigPreviewClient.list(cmd, resource_group_name, name)
except Exception as e:
handle_raw_exception(e)


def show_http_route_config(cmd, resource_group_name, name, http_route_config_name):
_validate_subscription_registered(cmd, CONTAINER_APPS_RP)
try:
return HttpRouteConfigPreviewClient.show(cmd, resource_group_name, name, http_route_config_name)
except Exception as e:
handle_raw_exception(e)


def delete_http_route_config(cmd, resource_group_name, name, http_route_config_name):
_validate_subscription_registered(cmd, CONTAINER_APPS_RP)
try:
return HttpRouteConfigPreviewClient.delete(cmd, resource_group_name, name, http_route_config_name)
except Exception as e:
handle_raw_exception(e)
Loading
Loading