Skip to content

Commit

Permalink
Specific Error Types + Bugfixes (Help, remove app-subnet-resource-id,…
Browse files Browse the repository at this point in the history
… removed env-var alias, added help text for --name) (#28)

* Moved dapr arguments to env as a subgroup.

* Added env variable options.

* Changed revision mode set to revision set-mode.

* Added env var options to revision copy.

* Fixed revision copy bug related to env secret refs.

* Changed registry and secret delete to remove. Added registry param helps. Removed replica from table output and added trafficWeight.

* Updating warning text.

* Updated warning text once more.

* Made name optional for revision copy if from-revision flag is passed.

* Fixed whitespace style issues.

* Styled clients and utils to pass pylint.

* Finished client.py pylint fixes.

* Fixed pylint issues.

* Fixed flake8 commands and custom.

* Fixed flake issues in src.

* Added license header to _sdk_models.

* Added confirmation for containerapp delete.

* Update helps for identity, revision. Removed env-var alias for set-env-vars. Added name param help.

* Removed app-subnet-resource-id.

* Updated infrastructure subnet param help.

* Check if containerapp resource exists before attempting to delete.

* Added check before deleting managed env.

* Changed error types to be more specific.

* Removed check before deletion. Removed comments.

Co-authored-by: Haroon Feisal <[email protected]>
  • Loading branch information
2 people authored and calvinsID committed Mar 24, 2022
1 parent a607ed9 commit 9652f3e
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 98 deletions.
11 changes: 5 additions & 6 deletions src/containerapp/azext_containerapp/_client_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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


Expand Down
18 changes: 13 additions & 5 deletions src/containerapp/azext_containerapp/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'] = """
Expand All @@ -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'] = """
Expand All @@ -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'] = """
Expand All @@ -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'] = """
Expand Down Expand Up @@ -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'] = """
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/containerapp/azext_containerapp/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand All @@ -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.")
Expand Down Expand Up @@ -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')
Expand Down
Loading

0 comments on commit 9652f3e

Please sign in to comment.