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 5 commits into
base: main
Choose a base branch
from

Conversation

Tratcher
Copy link

This adds list/create/update/show/delete commands for the new httprouteconfig feature area. For now create/update uses YAML input because the object model is quite complex. We may add more granular input in the future.


Related command

az containerapp env httprouteconfig

General Guidelines

  • Have you run azdev style <YOUR_EXT> locally? (pip install azdev required)
  • Have you run python scripts/ci/test_index.py -q locally? (pip install wheel==0.30.0 required)
  • My extension version conforms to the Extension version schema

About Extension Publish

There is a pipeline to automatically build, upload and publish extension wheels.
Once your pull request is merged into main branch, a new pull request will be created to update src/index.json automatically.
You only need to update the version information in file setup.py and historical information in file HISTORY.rst in your PR but do not modify src/index.json.

Copy link

Validation for Breaking Change Starting...

Thanks for your contribution!

Copy link

Hi @Tratcher,
Please write the description of changes which can be perceived by customers into HISTORY.rst.
If you want to release a new extension version, please update the version in setup.py as well.

@yonzhan
Copy link
Collaborator

yonzhan commented Nov 21, 2024

Thank you for your contribution! We will review the pull request and get back to you soon.

Copy link

CodeGen Tools Feedback Collection

Thank you for using our CodeGen tool. We value your feedback, and we would like to know how we can improve our product. Please take a few minutes to fill our codegen survey

Copy link

github-actions bot commented Nov 21, 2024

Hi @Tratcher

Release Suggestions

Module: containerapp

  • Update VERSION to 1.1.0b2 in src/containerapp/setup.py

Notes

@tdaroly
Copy link
Contributor

tdaroly commented Nov 21, 2024

Can you add a test?

This was for maintenance config which was also env level resource similar to httpRouteConfig. Can we do something similar?
env create:

self.cmd('containerapp env create -g {} -n {} --location {} --logs-destination none --enable-workload-profiles'.format(resource_group, env_name, TEST_LOCATION))

list:

self.cmd("az containerapp env maintenance-config list --resource-group {} --environment {}".format(resource_group, env_name), checks=[

update:

self.cmd("az containerapp env maintenance-config update --resource-group {} --environment {} -d {} -w {}".format(resource_group, env_name, updatedDuration, updatedWeekday), checks=[

delete:

self.cmd("az containerapp env maintenance-config remove --resource-group {} --environment {} -y".format(resource_group, env_name))

@yonzhan yonzhan added this to the Backlog milestone Nov 22, 2024
@@ -37,6 +37,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 httprouteconfig') as g:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
with self.command_group('containerapp env httprouteconfig') as g:
with self.command_group('containerapp env http-route-config') as g:
Suggested change
with self.command_group('containerapp env httprouteconfig') as g:
with self.command_group('containerapp env httprouteconfig') as g:

@@ -37,6 +37,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 httprouteconfig') as g:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
with self.command_group('containerapp env httprouteconfig') as g:
with self.command_group('containerapp env httprouteconfig', is_preview=True) as g:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For new commands, we always recommend to support in preview mode first

@@ -3322,3 +3322,43 @@ def list_maintenance_config(cmd, resource_group_name, env_name):
)
r = maintenance_config_decorator.list()
return r


def update_httprouteconfig(cmd, resource_group_name, name, httprouteconfig_name, yaml):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JMESPathCheck('properties.rules[0].targets[0].containerApp', "app1"),
])

self.cmd("az containerapp env httprouteconfig show -g {} -n {} --httprouteconfig-name {}".format(resource_group, env_name, route_name), checks=[
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add short name for --httproutconfig-name for better user experience according to https://github.com/Azure/azure-cli/blob/main/doc/authoring_command_modules/authoring_commands.md#customize-arguments

Comment on lines +362 to +430
@classmethod
def update_httprouteconfig(cls, cmd, resource_group_name, name, httprouteconfig_name, httprouteconfig_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,
httprouteconfig_name,
cls.api_version)

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

@classmethod
def list_httprouteconfigs(cls, cmd, resource_group_name, name, formatter=lambda x: x):
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"]:
formatted = formatter(route)
route_list.append(formatted)
return route_list

@classmethod
def show_httprouteconfig(cls, cmd, resource_group_name, name, httprouteconfig_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,
httprouteconfig_name,
cls.api_version)

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

@classmethod
def delete_httprouteconfig(cls, cmd, resource_group_name, name, httprouteconfig_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,
httprouteconfig_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

Copy link
Contributor

@Greedygre Greedygre Nov 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommend using a separate Client for /httpRouteConfigs, you can refer class StorageClient()


r = send_raw_request(cmd.cli_ctx, "GET", request_url, body=None)
j = r.json()
for route in j["value"]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may throw None Error if j["value"] is None.

return r.json()

@classmethod
def delete_httprouteconfig(cls, cmd, resource_group_name, name, httprouteconfig_name):
Copy link
Contributor

@Greedygre Greedygre Nov 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def delete_httprouteconfig(cls, cmd, resource_group_name, name, httprouteconfig_name):
def delete(cls, cmd, resource_group_name, name, httprouteconfig_name):

return r.json()

@classmethod
def list_httprouteconfigs(cls, cmd, resource_group_name, name, formatter=lambda x: x):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def list_httprouteconfigs(cls, cmd, resource_group_name, name, formatter=lambda x: x):
def list(cls, cmd, resource_group_name, name, formatter=lambda x: x):

@@ -4,6 +4,7 @@ Release History
===============
upcoming
++++++
* 'az containerapp env httprouteconfig' Add comands for the httprouteconfig feature area.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* 'az containerapp env httprouteconfig' Add comands for the httprouteconfig feature area.
* 'az containerapp env httprouteconfig': Add comands for the httprouteconfig feature area.

return r.json()

@classmethod
def list_httprouteconfigs(cls, cmd, resource_group_name, name, formatter=lambda x: x):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why you need the formatter here? Seems lambda x: x do nothing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auto-Assign Auto assign by bot ContainerApp
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants