diff --git a/src/containerapp/azext_containerapp/_client_factory.py b/src/containerapp/azext_containerapp/_client_factory.py index 9a249cdbe7e..4e8ad424138 100644 --- a/src/containerapp/azext_containerapp/_client_factory.py +++ b/src/containerapp/azext_containerapp/_client_factory.py @@ -6,8 +6,7 @@ from azure.cli.core.commands.client_factory import get_mgmt_service_client from azure.cli.core.profiles import ResourceType - -from knack.util import CLIError +from azure.cli.core.azclierror import CLIInternalError # pylint: disable=inconsistent-return-statements @@ -21,7 +20,7 @@ def _polish_bad_errors(ex): elif 'Message' in content: detail = content['Message'] - ex = CLIError(detail) + ex = CLIInternalError(detail) except Exception: # pylint: disable=broad-except pass if no_throw: @@ -45,13 +44,13 @@ def handle_raw_exception(e): if 'code' in jsonError and 'message' in jsonError: code = jsonError['code'] message = jsonError['message'] - raise CLIError('({}) {}'.format(code, message)) + raise CLIInternalError('({}) {}'.format(code, message)) elif "Message" in jsonError: message = jsonError["Message"] - raise CLIError(message) + raise CLIInternalError(message) elif "message" in jsonError: message = jsonError["message"] - raise CLIError(message) + raise CLIInternalError(message) raise e diff --git a/src/containerapp/azext_containerapp/_help.py b/src/containerapp/azext_containerapp/_help.py index a4a71960f02..a306f2f6bd7 100644 --- a/src/containerapp/azext_containerapp/_help.py +++ b/src/containerapp/azext_containerapp/_help.py @@ -124,7 +124,7 @@ examples: - name: Restart a revision. text: | - az containerapp revision restart -n MyContainerapp -g MyResourceGroup --revision-name MyContainerappRevision + az containerapp revision restart -n MyContainerapp -g MyResourceGroup --revision MyContainerappRevision """ helps['containerapp revision activate'] = """ @@ -133,7 +133,7 @@ examples: - name: Activate a revision. text: | - az containerapp revision activate -n MyContainerapp -g MyResourceGroup --revision-name MyContainerappRevision + az containerapp revision activate -g MyResourceGroup --revision MyContainerappRevision """ helps['containerapp revision deactivate'] = """ @@ -142,7 +142,7 @@ examples: - name: Deactivate a revision. text: | - az containerapp revision deactivate -n MyContainerapp -g MyResourceGroup --revision-name MyContainerappRevision + az containerapp revision deactivate -g MyResourceGroup --revision MyContainerappRevision """ helps['containerapp revision set-mode'] = """ @@ -158,10 +158,15 @@ type: command short-summary: Create a revision based on a previous revision. examples: - - name: Create a revision based on a previous revision. + - name: Create a revision based on the latest revision. text: | az containerapp revision copy -n MyContainerapp -g MyResourceGroup \\ + --cpu 0.75 --memory 1.5Gi + - name: Create a revision based on a previous revision. + text: | + az containerapp revision copy -g MyResourceGroup \\ --from-revision PreviousRevisionName --cpu 0.75 --memory 1.5Gi + """ helps['containerapp revision copy'] = """ @@ -231,7 +236,7 @@ helps['containerapp env dapr-component'] = """ type: group - short-summary: Commands to manage Container App environment dapr components. + short-summary: Commmands to manage dapr components on the Container App environment. """ helps['containerapp env dapr-component list'] = """ @@ -284,6 +289,9 @@ - name: Assign system identity. text: | az containerapp identity assign + - name: Assign user identity. + text: | + az containerapp identity assign --identities myAssignedId - name: Assign system and user identity. text: | az containerapp identity assign --identities [system] myAssignedId diff --git a/src/containerapp/azext_containerapp/_params.py b/src/containerapp/azext_containerapp/_params.py index 169b65edbe5..0179e1f77f7 100644 --- a/src/containerapp/azext_containerapp/_params.py +++ b/src/containerapp/azext_containerapp/_params.py @@ -21,7 +21,7 @@ def load_arguments(self, _): with self.argument_context('containerapp') as c: # Base arguments - c.argument('name', name_type, metavar='NAME', id_part='name') + c.argument('name', name_type, metavar='NAME', id_part='name', help="The name of the Containerapp.") c.argument('resource_group_name', arg_type=resource_group_name_type) c.argument('location', arg_type=get_location_type(self.cli_ctx)) @@ -43,7 +43,7 @@ def load_arguments(self, _): # Env vars with self.argument_context('containerapp', arg_group='Environment variables (Creates new revision)') as c: - c.argument('set_env_vars', options_list=['--set-env-vars, --env-vars'], nargs='*', help="A list of environment variable(s) to add to the container. Space-separated values in 'key=value' format. If stored as a secret, value must start with \'secretref:\' followed by the secret name.") + c.argument('set_env_vars', nargs='*', help="A list of environment variable(s) to add to the container. Space-separated values in 'key=value' format. If stored as a secret, value must start with \'secretref:\' followed by the secret name.") c.argument('remove_env_vars', nargs='*', help="A list of environment variable(s) to remove from container. Space-separated env var name values.") c.argument('replace_env_vars', nargs='*', help="A list of environment variable(s) to replace from the container. Space-separated values in 'key=value' format. If stored as a secret, value must start with \'secretref:\' followed by the secret name.") c.argument('remove_all_env_vars', help="Option to remove all environment variable(s) from the container.") @@ -97,7 +97,7 @@ def load_arguments(self, _): c.argument('instrumentation_key', options_list=['--dapr-instrumentation-key'], help='Azure Monitor instrumentation key used by Dapr to export Service to Service communication telemetry') with self.argument_context('containerapp env', arg_group='Virtual Network') as c: - c.argument('infrastructure_subnet_resource_id', type=str, options_list=['--infrastructure-subnet-resource-id'], help='Resource ID of a subnet for infrastructure components. This subnet must be in the same VNET as the subnet defined in appSubnetResourceId.') + c.argument('infrastructure_subnet_resource_id', type=str, options_list=['--infrastructure-subnet-resource-id'], help='Resource ID of a subnet for infrastructure components and user app containers.') c.argument('app_subnet_resource_id', type=str, options_list=['--app-subnet-resource-id'], help='Resource ID of a subnet that Container App containers are injected into. This subnet must be in the same VNET as the subnet defined in infrastructureSubnetResourceId.') c.argument('docker_bridge_cidr', type=str, options_list=['--docker-bridge-cidr'], help='CIDR notation IP range assigned to the Docker bridge. It must not overlap with any Subnet IP ranges or the IP range defined in Platform Reserved CIDR, if defined') c.argument('platform_reserved_cidr', type=str, options_list=['--platform-reserved-cidr'], help='IP range in CIDR notation that can be reserved for environment infrastructure IP addresses. It must not overlap with any other Subnet IP ranges') diff --git a/src/containerapp/azext_containerapp/custom.py b/src/containerapp/azext_containerapp/custom.py index d19ff49ea69..657b5995e03 100644 --- a/src/containerapp/azext_containerapp/custom.py +++ b/src/containerapp/azext_containerapp/custom.py @@ -6,9 +6,8 @@ from urllib.parse import urlparse from azure.cli.command_modules.appservice.custom import (_get_acr_cred) -from azure.cli.core.azclierror import (RequiredArgumentMissingError, ValidationError) +from azure.cli.core.azclierror import (RequiredArgumentMissingError, ValidationError, ResourceNotFoundError, CLIInternalError, InvalidArgumentValueError) from azure.cli.core.commands.client_factory import get_subscription_id -from knack.util import CLIError from knack.log import get_logger from msrestazure.tools import parse_resource_id, is_valid_resource_id @@ -72,10 +71,10 @@ def load_yaml_file(file_name): return yaml.safe_load(stream) except (IOError, OSError) as ex: if getattr(ex, 'errno', 0) == errno.ENOENT: - raise CLIError('{} does not exist'.format(file_name)) from ex + raise ValidationError('{} does not exist'.format(file_name)) from ex raise except (yaml.parser.ParserError, UnicodeDecodeError) as ex: - raise CLIError('Error parsing {} ({})'.format(file_name, str(ex))) from ex + raise ValidationError('Error parsing {} ({})'.format(file_name, str(ex))) from ex def create_deserializer(): @@ -123,7 +122,7 @@ def update_containerapp_yaml(cmd, name, resource_group_name, file_name, from_rev if from_revision: try: r = ContainerAppClient.show_revision(cmd=cmd, resource_group_name=resource_group_name, container_app_name=name, name=from_revision) - except CLIError as e: + except CLIInternalError as e: handle_raw_exception(e) _update_revision_env_secretrefs(r["properties"]["template"]["containers"], name) current_containerapp_def["properties"]["template"] = r["properties"]["template"] @@ -483,7 +482,7 @@ def update_containerapp(cmd, pass if not containerapp_def: - raise CLIError("The containerapp '{}' does not exist".format(name)) + raise ResourceNotFoundError("The containerapp '{}' does not exist".format(name)) # Doing this while API has bug. If env var is an empty string, API doesn't return "value" even though the "value" should be an empty string if "properties" in containerapp_def and "template" in containerapp_def["properties"] and "containers" in containerapp_def["properties"]["template"]: @@ -695,7 +694,7 @@ def show_containerapp(cmd, name, resource_group_name): try: return ContainerAppClient.show(cmd=cmd, resource_group_name=resource_group_name, name=name) - except CLIError as e: + except CLIInternalError as e: handle_raw_exception(e) @@ -710,7 +709,7 @@ def list_containerapp(cmd, resource_group_name=None): containerapps = ContainerAppClient.list_by_resource_group(cmd=cmd, resource_group_name=resource_group_name) return containerapps - except CLIError as e: + except CLIInternalError as e: handle_raw_exception(e) @@ -719,7 +718,7 @@ def delete_containerapp(cmd, name, resource_group_name): try: return ContainerAppClient.delete(cmd=cmd, name=name, resource_group_name=resource_group_name) - except CLIError as e: + except CLIInternalError as e: handle_raw_exception(e) @@ -731,7 +730,6 @@ def create_managed_environment(cmd, location=None, instrumentation_key=None, infrastructure_subnet_resource_id=None, - app_subnet_resource_id=None, docker_bridge_cidr=None, platform_reserved_cidr=None, platform_reserved_dns_ip=None, @@ -744,15 +742,6 @@ def create_managed_environment(cmd, _validate_subscription_registered(cmd, "Microsoft.App") _ensure_location_allowed(cmd, location, "Microsoft.App", "managedEnvironments") - # Microsoft.ContainerService RP registration is required for vnet enabled environments - if infrastructure_subnet_resource_id is not None or app_subnet_resource_id is not None: - if is_valid_resource_id(app_subnet_resource_id): - parsed_app_subnet_resource_id = parse_resource_id(app_subnet_resource_id) - subnet_subscription = parsed_app_subnet_resource_id["subscription"] - _validate_subscription_registered(cmd, "Microsoft.ContainerService", subnet_subscription) - else: - raise ValidationError('Subnet resource ID is invalid.') - if logs_customer_id is None or logs_key is None: logs_customer_id, logs_key = _generate_log_analytics_if_not_provided(cmd, logs_customer_id, logs_key, location, resource_group_name) @@ -773,19 +762,12 @@ def create_managed_environment(cmd, if instrumentation_key is not None: managed_env_def["properties"]["daprAIInstrumentationKey"] = instrumentation_key - if infrastructure_subnet_resource_id or app_subnet_resource_id or docker_bridge_cidr or platform_reserved_cidr or platform_reserved_dns_ip: + if infrastructure_subnet_resource_id or docker_bridge_cidr or platform_reserved_cidr or platform_reserved_dns_ip: vnet_config_def = VnetConfigurationModel if infrastructure_subnet_resource_id is not None: - if not app_subnet_resource_id: - raise ValidationError('App subnet resource ID needs to be supplied with infrastructure subnet resource ID.') vnet_config_def["infrastructureSubnetId"] = infrastructure_subnet_resource_id - if app_subnet_resource_id is not None: - if not infrastructure_subnet_resource_id: - raise ValidationError('Infrastructure subnet resource ID needs to be supplied with app subnet resource ID.') - vnet_config_def["runtimeSubnetId"] = app_subnet_resource_id - if docker_bridge_cidr is not None: vnet_config_def["dockerBridgeCidr"] = docker_bridge_cidr @@ -798,8 +780,8 @@ def create_managed_environment(cmd, managed_env_def["properties"]["vnetConfiguration"] = vnet_config_def if internal_only: - if not infrastructure_subnet_resource_id or not app_subnet_resource_id: - raise ValidationError('Infrastructure subnet resource ID and App subnet resource ID need to be supplied for internal only environments.') + if not infrastructure_subnet_resource_id: + raise ValidationError('Infrastructure subnet resource ID needs to be supplied for internal only environments.') managed_env_def["properties"]["internalLoadBalancerEnabled"] = True try: @@ -819,7 +801,7 @@ def update_managed_environment(cmd, resource_group_name, tags=None, no_wait=False): - raise CLIError('Containerapp env update is not yet supported.') + raise CLIInternalError('Containerapp env update is not yet supported.') def show_managed_environment(cmd, name, resource_group_name): @@ -827,7 +809,7 @@ def show_managed_environment(cmd, name, resource_group_name): try: return ManagedEnvironmentClient.show(cmd=cmd, resource_group_name=resource_group_name, name=name) - except CLIError as e: + except CLIInternalError as e: handle_raw_exception(e) @@ -842,7 +824,7 @@ def list_managed_environments(cmd, resource_group_name=None): managed_envs = ManagedEnvironmentClient.list_by_resource_group(cmd=cmd, resource_group_name=resource_group_name) return managed_envs - except CLIError as e: + except CLIInternalError as e: handle_raw_exception(e) @@ -851,7 +833,7 @@ def delete_managed_environment(cmd, name, resource_group_name, no_wait=False): try: return ManagedEnvironmentClient.delete(cmd=cmd, name=name, resource_group_name=resource_group_name, no_wait=no_wait) - except CLIError as e: + except CLIInternalError as e: handle_raw_exception(e) @@ -876,7 +858,7 @@ def assign_managed_identity(cmd, name, resource_group_name, identities=None, no_ pass if not containerapp_def: - raise CLIError("The containerapp '{}' does not exist".format(name)) + raise ResourceNotFoundError("The containerapp '{}' does not exist".format(name)) _get_existing_secrets(cmd, resource_group_name, name, containerapp_def) @@ -956,7 +938,7 @@ def remove_managed_identity(cmd, name, resource_group_name, identities, no_wait= pass if not containerapp_def: - raise CLIError("The containerapp '{}' does not exist".format(name)) + raise ResourceNotFoundError("The containerapp '{}' does not exist".format(name)) _get_existing_secrets(cmd, resource_group_name, name, containerapp_def) @@ -969,11 +951,11 @@ def remove_managed_identity(cmd, name, resource_group_name, identities, no_wait= containerapp_def["identity"]["type"] = "None" if containerapp_def["identity"]["type"] == "None": - raise CLIError("The containerapp {} has no system or user assigned identities.".format(name)) + raise InvalidArgumentValueError("The containerapp {} has no system or user assigned identities.".format(name)) if remove_system_identity: if containerapp_def["identity"]["type"] == "UserAssigned": - raise CLIError("The containerapp {} has no system assigned identities.".format(name)) + raise InvalidArgumentValueError("The containerapp {} has no system assigned identities.".format(name)) containerapp_def["identity"]["type"] = ("None" if containerapp_def["identity"]["type"] == "SystemAssigned" else "UserAssigned") if remove_user_identities: @@ -994,7 +976,7 @@ def remove_managed_identity(cmd, name, resource_group_name, identities, no_wait= break if not wasRemoved: - raise CLIError("The containerapp does not have specified user identity '{}' assigned, so it cannot be removed.".format(given_id)) + raise InvalidArgumentValueError("The containerapp does not have specified user identity '{}' assigned, so it cannot be removed.".format(given_id)) if containerapp_def["identity"]["userAssignedIdentities"] == {}: containerapp_def["identity"]["userAssignedIdentities"] = None @@ -1012,7 +994,7 @@ def show_managed_identity(cmd, name, resource_group_name): try: r = ContainerAppClient.show(cmd=cmd, resource_group_name=resource_group_name, name=name) - except CLIError as e: + except CLIInternalError as e: handle_raw_exception(e) try: @@ -1061,25 +1043,25 @@ def create_or_update_github_action(cmd, try: github_repo = g.get_repo(repo) if not github_repo.permissions.push or not github_repo.permissions.maintain: - raise CLIError("The token does not have appropriate access rights to repository {}.".format(repo)) + raise ValidationError("The token does not have appropriate access rights to repository {}.".format(repo)) try: github_repo.get_branch(branch=branch) except GithubException as e: error_msg = "Encountered GitHub error when accessing {} branch in {} repo.".format(branch, repo) if e.data and e.data['message']: error_msg += " Error: {}".format(e.data['message']) - raise CLIError(error_msg) from e + raise CLIInternalError(error_msg) from e logger.warning('Verified GitHub repo and branch') except BadCredentialsException as e: - raise CLIError("Could not authenticate to the repository. Please create a Personal Access Token and use " + raise ValidationError("Could not authenticate to the repository. Please create a Personal Access Token and use " "the --token argument. Run 'az webapp deployment github-actions add --help' " "for more information.") from e except GithubException as e: error_msg = "Encountered GitHub error when accessing {} repo".format(repo) if e.data and e.data['message']: error_msg += " Error: {}".format(e.data['message']) - raise CLIError(error_msg) from e - except CLIError as clierror: + raise CLIInternalError(error_msg) from e + except CLIInternalError as clierror: raise clierror except Exception: # If exception due to github package missing, etc just continue without validating the repo and rely on api validation @@ -1187,17 +1169,17 @@ def delete_github_action(cmd, name, resource_group_name, token=None, login_with_ try: github_repo = g.get_repo(repo) if not github_repo.permissions.push or not github_repo.permissions.maintain: - raise CLIError("The token does not have appropriate access rights to repository {}.".format(repo)) + raise ValidationError("The token does not have appropriate access rights to repository {}.".format(repo)) except BadCredentialsException as e: - raise CLIError("Could not authenticate to the repository. Please create a Personal Access Token and use " + raise CLIInternalError("Could not authenticate to the repository. Please create a Personal Access Token and use " "the --token argument. Run 'az webapp deployment github-actions add --help' " "for more information.") from e except GithubException as e: error_msg = "Encountered GitHub error when accessing {} repo".format(repo) if e.data and e.data['message']: error_msg += " Error: {}".format(e.data['message']) - raise CLIError(error_msg) from e - except CLIError as clierror: + raise CLIInternalError(error_msg) from e + except CLIInternalError as clierror: raise clierror except Exception: # If exception due to github package missing, etc just continue without validating the repo and rely on api validation @@ -1214,7 +1196,7 @@ def delete_github_action(cmd, name, resource_group_name, token=None, login_with_ def list_revisions(cmd, name, resource_group_name): try: return ContainerAppClient.list_revisions(cmd=cmd, resource_group_name=resource_group_name, name=name) - except CLIError as e: + except CLIInternalError as e: handle_raw_exception(e) @@ -1224,7 +1206,7 @@ def show_revision(cmd, resource_group_name, revision_name, name=None): try: return ContainerAppClient.show_revision(cmd=cmd, resource_group_name=resource_group_name, container_app_name=name, name=revision_name) - except CLIError as e: + except CLIInternalError as e: handle_raw_exception(e) @@ -1234,7 +1216,7 @@ def restart_revision(cmd, resource_group_name, revision_name, name=None): try: return ContainerAppClient.restart_revision(cmd=cmd, resource_group_name=resource_group_name, container_app_name=name, name=revision_name) - except CLIError as e: + except CLIInternalError as e: handle_raw_exception(e) @@ -1244,7 +1226,7 @@ def activate_revision(cmd, resource_group_name, revision_name, name=None): try: return ContainerAppClient.activate_revision(cmd=cmd, resource_group_name=resource_group_name, container_app_name=name, name=revision_name) - except CLIError as e: + except CLIInternalError as e: handle_raw_exception(e) @@ -1254,7 +1236,7 @@ def deactivate_revision(cmd, resource_group_name, revision_name, name=None): try: return ContainerAppClient.deactivate_revision(cmd=cmd, resource_group_name=resource_group_name, container_app_name=name, name=revision_name) - except CLIError as e: + except CLIInternalError as e: handle_raw_exception(e) @@ -1302,12 +1284,12 @@ def copy_revision(cmd, pass if not containerapp_def: - raise CLIError("The containerapp '{}' does not exist".format(name)) + raise ResourceNotFoundError("The containerapp '{}' does not exist".format(name)) if from_revision: try: r = ContainerAppClient.show_revision(cmd=cmd, resource_group_name=resource_group_name, container_app_name=name, name=from_revision) - except CLIError as e: + except CLIInternalError as e: # Error handle the case where revision not found? handle_raw_exception(e) @@ -1470,7 +1452,7 @@ def set_revision_mode(cmd, resource_group_name, name, mode, no_wait=False): pass if not containerapp_def: - raise CLIError("The containerapp '{}' does not exist".format(name)) + raise ResourceNotFoundError("The containerapp '{}' does not exist".format(name)) containerapp_def["properties"]["configuration"]["activeRevisionsMode"] = mode.lower() @@ -1494,12 +1476,12 @@ def show_ingress(cmd, name, resource_group_name): pass if not containerapp_def: - raise CLIError("The containerapp '{}' does not exist".format(name)) + raise ResourceNotFoundError("The containerapp '{}' does not exist".format(name)) try: return containerapp_def["properties"]["configuration"]["ingress"] except Exception as e: - raise CLIError("The containerapp '{}' does not have ingress enabled.".format(name)) from e + raise ValidationError("The containerapp '{}' does not have ingress enabled.".format(name)) from e def enable_ingress(cmd, name, resource_group_name, type, target_port, transport, allow_insecure=False, no_wait=False): # pylint: disable=redefined-builtin @@ -1512,7 +1494,7 @@ def enable_ingress(cmd, name, resource_group_name, type, target_port, transport, pass if not containerapp_def: - raise CLIError("The containerapp '{}' does not exist".format(name)) + raise ResourceNotFoundError("The containerapp '{}' does not exist".format(name)) external_ingress = None if type is not None: @@ -1551,7 +1533,7 @@ def disable_ingress(cmd, name, resource_group_name, no_wait=False): pass if not containerapp_def: - raise CLIError("The containerapp '{}' does not exist".format(name)) + raise ResourceNotFoundError("The containerapp '{}' does not exist".format(name)) containerapp_def["properties"]["configuration"]["ingress"] = None @@ -1576,12 +1558,12 @@ def set_ingress_traffic(cmd, name, resource_group_name, traffic_weights, no_wait pass if not containerapp_def: - raise CLIError("The containerapp '{}' does not exist".format(name)) + raise ResourceNotFoundError("The containerapp '{}' does not exist".format(name)) try: containerapp_def["properties"]["configuration"]["ingress"] except Exception as e: - raise CLIError("Ingress must be enabled to set ingress traffic. Try running `az containerapp ingress -h` for more info.") from e + raise ValidationError("Ingress must be enabled to set ingress traffic. Try running `az containerapp ingress -h` for more info.") from e if traffic_weights is not None: _update_traffic_weights(containerapp_def, traffic_weights) @@ -1606,12 +1588,12 @@ def show_ingress_traffic(cmd, name, resource_group_name): pass if not containerapp_def: - raise CLIError("The containerapp '{}' does not exist".format(name)) + raise ResourceNotFoundError("The containerapp '{}' does not exist".format(name)) try: return containerapp_def["properties"]["configuration"]["ingress"]["traffic"] except Exception as e: - raise CLIError("Ingress must be enabled to show ingress traffic. Try running `az containerapp ingress -h` for more info.") from e + raise ValidationError("Ingress must be enabled to show ingress traffic. Try running `az containerapp ingress -h` for more info.") from e def show_registry(cmd, name, resource_group_name, server): @@ -1624,19 +1606,19 @@ def show_registry(cmd, name, resource_group_name, server): pass if not containerapp_def: - raise CLIError("The containerapp '{}' does not exist".format(name)) + raise ResourceNotFoundError("The containerapp '{}' does not exist".format(name)) try: containerapp_def["properties"]["configuration"]["registries"] except Exception as e: - raise CLIError("The containerapp {} has no assigned registries.".format(name)) from e + raise ValidationError("The containerapp {} has no assigned registries.".format(name)) from e registries_def = containerapp_def["properties"]["configuration"]["registries"] for r in registries_def: if r['server'].lower() == server.lower(): return r - raise CLIError("The containerapp {} does not have specified registry assigned.".format(name)) + raise InvalidArgumentValueError("The containerapp {} does not have specified registry assigned.".format(name)) def list_registry(cmd, name, resource_group_name): @@ -1649,12 +1631,12 @@ def list_registry(cmd, name, resource_group_name): pass if not containerapp_def: - raise CLIError("The containerapp '{}' does not exist".format(name)) + raise ResourceNotFoundError("The containerapp '{}' does not exist".format(name)) try: return containerapp_def["properties"]["configuration"]["registries"] except Exception as e: - raise CLIError("The containerapp {} has no assigned registries.".format(name)) from e + raise ValidationError("The containerapp {} has no assigned registries.".format(name)) from e def set_registry(cmd, name, resource_group_name, server, username=None, password=None, no_wait=False): @@ -1667,7 +1649,7 @@ def set_registry(cmd, name, resource_group_name, server, username=None, password pass if not containerapp_def: - raise CLIError("The containerapp '{}' does not exist".format(name)) + raise ResourceNotFoundError("The containerapp '{}' does not exist".format(name)) _get_existing_secrets(cmd, resource_group_name, name, containerapp_def) @@ -1741,7 +1723,7 @@ def remove_registry(cmd, name, resource_group_name, server, no_wait=False): pass if not containerapp_def: - raise CLIError("The containerapp '{}' does not exist".format(name)) + raise ResourceNotFoundError("The containerapp '{}' does not exist".format(name)) _get_existing_secrets(cmd, resource_group_name, name, containerapp_def) @@ -1750,7 +1732,7 @@ def remove_registry(cmd, name, resource_group_name, server, no_wait=False): try: containerapp_def["properties"]["configuration"]["registries"] except Exception as e: - raise CLIError("The containerapp {} has no assigned registries.".format(name)) from e + raise ValidationError("The containerapp {} has no assigned registries.".format(name)) from e registries_def = containerapp_def["properties"]["configuration"]["registries"] @@ -1764,7 +1746,7 @@ def remove_registry(cmd, name, resource_group_name, server, no_wait=False): break if not wasRemoved: - raise CLIError("Containerapp does not have registry server {} assigned.".format(server)) + raise ValidationError("Containerapp does not have registry server {} assigned.".format(server)) if len(containerapp_def["properties"]["configuration"]["registries"]) == 0: containerapp_def["properties"]["configuration"].pop("registries") @@ -1789,12 +1771,12 @@ def list_secrets(cmd, name, resource_group_name): pass if not containerapp_def: - raise CLIError("The containerapp '{}' does not exist".format(name)) + raise ResourceNotFoundError("The containerapp '{}' does not exist".format(name)) try: return ContainerAppClient.list_secrets(cmd=cmd, resource_group_name=resource_group_name, name=name)["value"] except Exception as e: - raise CLIError("The containerapp {} has no assigned secrets.".format(name)) from e + raise ValidationError("The containerapp {} has no assigned secrets.".format(name)) from e def show_secret(cmd, name, resource_group_name, secret_name): @@ -1807,13 +1789,13 @@ def show_secret(cmd, name, resource_group_name, secret_name): pass if not containerapp_def: - raise CLIError("The containerapp '{}' does not exist".format(name)) + raise ResourceNotFoundError("The containerapp '{}' does not exist".format(name)) r = ContainerAppClient.list_secrets(cmd=cmd, resource_group_name=resource_group_name, name=name) for secret in r["value"]: if secret["name"].lower() == secret_name.lower(): return secret - raise CLIError("The containerapp {} does not have a secret assigned with name {}.".format(name, secret_name)) + raise ValidationError("The containerapp {} does not have a secret assigned with name {}.".format(name, secret_name)) def remove_secrets(cmd, name, resource_group_name, secret_names, no_wait=False): @@ -1826,7 +1808,7 @@ def remove_secrets(cmd, name, resource_group_name, secret_names, no_wait=False): pass if not containerapp_def: - raise CLIError("The containerapp '{}' does not exist".format(name)) + raise ResourceNotFoundError("The containerapp '{}' does not exist".format(name)) _get_existing_secrets(cmd, resource_group_name, name, containerapp_def) @@ -1838,7 +1820,7 @@ def remove_secrets(cmd, name, resource_group_name, secret_names, no_wait=False): wasRemoved = True break if not wasRemoved: - raise CLIError("The containerapp {} does not have a secret assigned with name {}.".format(name, secret_name)) + raise ValidationError("The containerapp {} does not have a secret assigned with name {}.".format(name, secret_name)) try: r = ContainerAppClient.create_or_update( cmd=cmd, resource_group_name=resource_group_name, name=name, container_app_envelope=containerapp_def, no_wait=no_wait) @@ -1868,7 +1850,7 @@ def set_secrets(cmd, name, resource_group_name, secrets, # try: # parse_secret_flags(yaml_secrets) # except: - # raise CLIError("YAML secrets must be a list of secrets in key=value format, delimited by new line.") + # raise ValidationError("YAML secrets must be a list of secrets in key=value format, delimited by new line.") # for secret in yaml_secrets: # secrets.append(secret.strip()) @@ -1879,7 +1861,7 @@ def set_secrets(cmd, name, resource_group_name, secrets, pass if not containerapp_def: - raise CLIError("The containerapp '{}' does not exist".format(name)) + raise ResourceNotFoundError("The containerapp '{}' does not exist".format(name)) _get_existing_secrets(cmd, resource_group_name, name, containerapp_def) _add_or_update_secrets(containerapp_def, parse_secret_flags(secrets)) @@ -1902,7 +1884,7 @@ def enable_dapr(cmd, name, resource_group_name, dapr_app_id=None, dapr_app_port= pass if not containerapp_def: - raise CLIError("The containerapp '{}' does not exist".format(name)) + raise ResourceNotFoundError("The containerapp '{}' does not exist".format(name)) _get_existing_secrets(cmd, resource_group_name, name, containerapp_def) @@ -1938,7 +1920,7 @@ def disable_dapr(cmd, name, resource_group_name, no_wait=False): pass if not containerapp_def: - raise CLIError("The containerapp '{}' does not exist".format(name)) + raise ResourceNotFoundError("The containerapp '{}' does not exist".format(name)) _get_existing_secrets(cmd, resource_group_name, name, containerapp_def) @@ -2006,7 +1988,7 @@ def remove_dapr_component(cmd, resource_group_name, dapr_component_name, environ try: DaprComponentClient.show(cmd, resource_group_name, environment_name, name=dapr_component_name) except Exception as e: - raise CLIError("Dapr component not found.") from e + raise ResourceNotFoundError("Dapr component not found.") from e try: r = DaprComponentClient.delete(cmd, resource_group_name, environment_name, name=dapr_component_name)