-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -359,6 +359,75 @@ def list_usages(cls, cmd, resource_group_name, name): | |||||
r = send_raw_request(cmd.cli_ctx, "GET", request_url) | ||||||
return r.json() | ||||||
|
||||||
@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): | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why you need the formatter here? Seems |
||||||
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"]: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It may throw None Error if |
||||||
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): | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
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 | ||||||
|
||||||
Comment on lines
+362
to
+430
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Recommend using a separate Client for |
||||||
|
||||||
class AuthPreviewClient(AuthClient): | ||||||
api_version = PREVIEW_API_VERSION | ||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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: | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For new commands, we always recommend to support in preview mode first |
||||||||||||||
g.custom_show_command('show', 'show_httprouteconfig') | ||||||||||||||
g.custom_command('list', 'list_httprouteconfigs') | ||||||||||||||
g.custom_command('create', 'update_httprouteconfig', exception_handler=ex_handler_factory()) | ||||||||||||||
g.custom_command('update', 'update_httprouteconfig', exception_handler=ex_handler_factory()) | ||||||||||||||
g.custom_command('delete', 'delete_httprouteconfig', 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') | ||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add help description for your command parameters according to https://github.com/Azure/azure-cli/blob/main/doc/authoring_command_modules/authoring_commands.md#customize-arguments |
||
yaml_httprouteconfig = load_yaml_file(yaml) | ||
# check if the type is dict | ||
if not isinstance(yaml_httprouteconfig, dict): | ||
raise ValidationError('Invalid YAML provided. Please see https://aka.ms/azure-container-apps-yaml for a valid YAML spec.') | ||
|
||
httprouteconfig_envelope = {} | ||
|
||
httprouteconfig_envelope["properties"] = yaml_httprouteconfig | ||
|
||
try: | ||
return ManagedEnvironmentPreviewClient.update_httprouteconfig(cmd, resource_group_name, name, httprouteconfig_name, httprouteconfig_envelope) | ||
except Exception as e: | ||
handle_raw_exception(e) | ||
|
||
|
||
def list_httprouteconfigs(cmd, resource_group_name, name): | ||
_validate_subscription_registered(cmd, CONTAINER_APPS_RP) | ||
try: | ||
return ManagedEnvironmentPreviewClient.list_httprouteconfigs(cmd, resource_group_name, name) | ||
except Exception as e: | ||
handle_raw_exception(e) | ||
|
||
|
||
def show_httprouteconfig(cmd, resource_group_name, name, httprouteconfig_name): | ||
_validate_subscription_registered(cmd, CONTAINER_APPS_RP) | ||
try: | ||
return ManagedEnvironmentPreviewClient.show_httprouteconfig(cmd, resource_group_name, name, httprouteconfig_name) | ||
except Exception as e: | ||
handle_raw_exception(e) | ||
|
||
|
||
def delete_httprouteconfig(cmd, resource_group_name, name, httprouteconfig_name): | ||
_validate_subscription_registered(cmd, CONTAINER_APPS_RP) | ||
try: | ||
return ManagedEnvironmentPreviewClient.delete_httprouteconfig(cmd, resource_group_name, name, httprouteconfig_name) | ||
except Exception as e: | ||
handle_raw_exception(e) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
rules: | ||
- description: "rule 1" | ||
routes: | ||
- match: | ||
prefix: "/1" | ||
action: | ||
PrefixRewrite: "/" | ||
targets: | ||
- ContainerApp: "app1" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
rules: | ||
- description: "rule 2" | ||
routes: | ||
- match: | ||
prefix: "/2" | ||
action: | ||
PrefixRewrite: "/" | ||
targets: | ||
- ContainerApp: "app2" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.