Skip to content

Commit

Permalink
Added environment as flag for list_containerapp. (Azure#114)
Browse files Browse the repository at this point in the history
* Added environment as flag for list_containerapp.

* Fixed logic error in RID case.

* Check if rg exists.

* Validate managed env exists if group is passed or rid is passed.

Co-authored-by: Haroon Feisal <haroonfeisal@microsoft.com>
  • Loading branch information
haroonf and Haroon Feisal committed May 25, 2022
1 parent 85f8fd3 commit e0b2805
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/containerapp/azext_containerapp/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
_update_revision_env_secretrefs, _get_acr_cred, safe_get, await_github_action, repo_url_to_name,
validate_container_app_name, _update_weights, get_vnet_location, register_provider_if_needed,
generate_randomized_cert_name, _get_name, load_cert_file, check_cert_name_availability,
validate_hostname, patch_new_custom_domain, get_custom_domains)
validate_hostname, patch_new_custom_domain, get_custom_domains, get_resource_group)

from ._ssh_utils import (SSH_DEFAULT_ENCODING, WebSocketConnection, read_ssh, get_stdin_writer, SSH_CTRL_C_MSG,
SSH_BACKUP_ENCODING)
Expand Down Expand Up @@ -724,7 +724,7 @@ def show_containerapp(cmd, name, resource_group_name):
handle_raw_exception(e)


def list_containerapp(cmd, resource_group_name=None):
def list_containerapp(cmd, resource_group_name=None, managed_env=None):
_validate_subscription_registered(cmd, CONTAINER_APPS_RP)

try:
Expand All @@ -734,6 +734,14 @@ def list_containerapp(cmd, resource_group_name=None):
else:
containerapps = ContainerAppClient.list_by_resource_group(cmd=cmd, resource_group_name=resource_group_name)

if managed_env:
env_name = parse_resource_id(managed_env)["name"].lower()
if "resource_group" in parse_resource_id(managed_env):
ManagedEnvironmentClient.show(cmd, parse_resource_id(managed_env)["resource_group"], parse_resource_id(managed_env)["name"])
containerapps = [c for c in containerapps if c["properties"]["managedEnvironmentId"].lower() == managed_env.lower()]
else:
containerapps = [c for c in containerapps if parse_resource_id(c["properties"]["managedEnvironmentId"])["name"].lower() == env_name]

return containerapps
except CLIError as e:
handle_raw_exception(e)
Expand Down

0 comments on commit e0b2805

Please sign in to comment.