Skip to content

Commit

Permalink
Added subgroups (Ingress, Registry, Secret) and updated revisions (#18)
Browse files Browse the repository at this point in the history
* Added ingress subgroup.

* Added help for ingress.

* Fixed ingress traffic help.

* Added registry commands.

* Updated registry remove util to clear secrets if none remaining. Added warning when updating existing registry. Added registry help.

* Changed registry delete to remove.

* Added error message if user tries to remove non assigned registry.

* Changed registry add back to registry set.

* Added secret subgroup commands.

* Removed yaml support from secret set.

* Changed secret add to secret set. Updated consistency between secret set and secret delete. Added secret help. Require at least one secret passed with --secrets for secret commands.

* Changed param name for secret delete from --secrets to --secret-names. Updated help.

* Changed registry remove to registry delete.

* Fixed bug in registry delete.

* Added revision mode set and revision copy.

* Modified update_containerapp_yaml to support updating from non-current revision.

Authored-by: Haroon Feisal <haroonfeisal@microsoft.com>
  • Loading branch information
runefa authored and calvinsID committed Mar 24, 2022
1 parent 6bf5a56 commit 25e1250
Show file tree
Hide file tree
Showing 6 changed files with 830 additions and 4 deletions.
171 changes: 171 additions & 0 deletions src/containerapp/azext_containerapp/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,24 @@
az containerapp revision deactivate --revision-name MyContainerappRevision -g MyResourceGroup
"""

helps['containerapp revision mode set'] = """
type: command
short-summary: Set the revision mode of a Containerapp.
examples:
- name: Set the revision mode of a Containerapp.
text: |
az containerapp revision set --mode Single -n MyContainerapp -g MyResourceGroup
"""

helps['containerapp revision copy'] = """
type: command
short-summary: Create a revision based on a previous revision.
examples:
- name: Create a revision based on a previous revision.
text: |
az containerapp revision copy -n MyContainerapp -g MyResourceGroup --cpu 0.75 --memory 1.5Gi
"""

# Environment Commands
helps['containerapp env'] = """
type: group
Expand Down Expand Up @@ -244,6 +262,159 @@
text: |
az containerapp env list -g MyResourceGroup
"""

# Ingress Commands
helps['containerapp ingress'] = """
type: group
short-summary: Commands to manage Containerapp ingress.
"""

helps['containerapp ingress traffic'] = """
type: subgroup
short-summary: Commands to manage Containerapp ingress traffic.
"""

helps['containerapp ingress show'] = """
type: command
short-summary: Show details of a Containerapp ingress.
examples:
- name: Show the details of a Containerapp ingress.
text: |
az containerapp ingress show -n MyContainerapp -g MyResourceGroup
"""

helps['containerapp ingress enable'] = """
type: command
short-summary: Enable Containerapp ingress.
examples:
- name: Enable Containerapp ingress.
text: |
az containerapp ingress enable -n MyContainerapp -g MyResourceGroup --type external --allow-insecure --target-port 80 --transport auto
"""

helps['containerapp ingress disable'] = """
type: command
short-summary: Disable Containerapp ingress.
examples:
- name: Disable Containerapp ingress.
text: |
az containerapp ingress disable -n MyContainerapp -g MyResourceGroup
"""

helps['containerapp ingress traffic'] = """
type: group
short-summary: Commands to manage Containerapp ingress traffic.
"""

helps['containerapp ingress traffic set'] = """
type: command
short-summary: Set Containerapp ingress traffic.
examples:
- name: Set Containerapp ingress traffic.
text: |
az containerapp ingress traffic set -n MyContainerapp -g MyResourceGroup --traffic-weight latest=100
"""

helps['containerapp ingress traffic show'] = """
type: command
short-summary: Show Containerapp ingress traffic.
examples:
- name: Show Containerapp ingress traffic.
text: |
az containerapp ingress traffic show -n MyContainerapp -g MyResourceGroup
"""

# Registry Commands
helps['containerapp registry'] = """
type: group
short-summary: Commands to manage Containerapp registries.
"""

helps['containerapp registry show'] = """
type: command
short-summary: Show details of a Containerapp registry.
examples:
- name: Show the details of a Containerapp registry.
text: |
az containerapp registry show -n MyContainerapp -g MyResourceGroup --server MyContainerappRegistry.azurecr.io
"""

helps['containerapp registry list'] = """
type: command
short-summary: List registries assigned to a Containerapp.
examples:
- name: Show the details of a Containerapp registry.
text: |
az containerapp registry list -n MyContainerapp -g MyResourceGroup
"""

helps['containerapp registry set'] = """
type: command
short-summary: Add or update a Containerapp registry.
examples:
- name: Add a registry to a Containerapp.
text: |
az containerapp registry set -n MyContainerapp -g MyResourceGroup --server MyContainerappRegistry.azurecr.io
- name: Update a Containerapp registry.
text: |
az containerapp registry set -n MyContainerapp -g MyResourceGroup --server MyExistingContainerappRegistry.azurecr.io --username MyRegistryUsername --password MyRegistryPassword
"""

helps['containerapp registry delete'] = """
type: command
short-summary: Delete a registry from a Containerapp.
examples:
- name: Delete a registry from a Containerapp.
text: |
az containerapp registry delete -n MyContainerapp -g MyResourceGroup --server MyContainerappRegistry.azurecr.io
"""

# Secret Commands
helps['containerapp secret'] = """
type: group
short-summary: Commands to manage Containerapp secrets.
"""

helps['containerapp secret show'] = """
type: command
short-summary: Show details of a Containerapp secret.
examples:
- name: Show the details of a Containerapp secret.
text: |
az containerapp secret show -n MyContainerapp -g MyResourceGroup --secret-name MySecret
"""

helps['containerapp secret list'] = """
type: command
short-summary: List the secrets of a Containerapp.
examples:
- name: List the secrets of a Containerapp.
text: |
az containerapp secret list -n MyContainerapp -g MyResourceGroup
"""

helps['containerapp secret delete'] = """
type: command
short-summary: Delete secrets from a Containerapp.
examples:
- name: Delete secrets from a Containerapp.
text: |
az containerapp secret delete -n MyContainerapp -g MyResourceGroup --secret-names MySecret MySecret2
"""

helps['containerapp secret set'] = """
type: command
short-summary: Create/update Containerapp secrets.
examples:
- name: Add a secret to a Containerapp.
text: |
az containerapp secret set -n MyContainerapp -g MyResourceGroup --secrets MySecretName=MySecretValue
- name: Update a Containerapp secret.
text: |
az containerapp secret set -n MyContainerapp -g MyResourceGroup --secrets MyExistingSecretName=MyNewSecretValue
"""

helps['containerapp github-action add'] = """
type: command
short-summary: Adds GitHub Actions to the Containerapp
Expand Down
2 changes: 1 addition & 1 deletion src/containerapp/azext_containerapp/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
"transport": None, # 'auto', 'http', 'http2'
"traffic": None, # TrafficWeight
"customDomains": None, # [CustomDomain]
# "allowInsecure": None
"allowInsecure": None # Boolean
}

RegistryCredentials = {
Expand Down
20 changes: 19 additions & 1 deletion src/containerapp/azext_containerapp/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,22 @@ def load_arguments(self, _):
c.argument('login_with_github', help='Interactively log in with Github to retrieve the Personal Access Token')

with self.argument_context('containerapp revision') as c:
c.argument('revision_name', type=str, help='Name of the revision')
c.argument('revision_name', options_list=['--revision'], type=str, help='Name of the revision.')

with self.argument_context('containerapp revision copy') as c:
c.argument('from_revision', type=str, help='Revision to copy from. Default: latest revision.')

with self.argument_context('containerapp ingress') as c:
c.argument('allow_insecure', help='Allow insecure connections for ingress traffic.')
c.argument('type', validator=validate_ingress, arg_type=get_enum_type(['internal', 'external']), help="Ingress type that allows either internal or external traffic to the Containerapp.")
c.argument('transport', arg_type=get_enum_type(['auto', 'http', 'http2']), help="The transport protocol used for ingress traffic.")
c.argument('target_port', type=int, validator=validate_target_port, help="The application port used for ingress traffic.")

with self.argument_context('containerapp ingress traffic') as c:
c.argument('traffic_weights', nargs='*', options_list=['--traffic-weight'], help="A list of revision weight(s) for the Containerapp. Space-separated values in 'revision_name=weight' format. For latest revision, use 'latest=weight'")

with self.argument_context('containerapp secret set') as c:
c.argument('secrets', nargs='+', options_list=['--secrets', '-s'], help="A list of secret(s) for the containerapp. Space-separated values in 'key=value' format.")

with self.argument_context('containerapp secret delete') as c:
c.argument('secret_names', nargs='+', help="A list of secret(s) for the containerapp. Space-separated secret values names.")
17 changes: 17 additions & 0 deletions src/containerapp/azext_containerapp/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,23 @@ def _add_or_update_secrets(containerapp_def, add_secrets):
if not is_existing:
containerapp_def["properties"]["configuration"]["secrets"].append(new_secret)

def _remove_registry_secret(containerapp_def, server, username):
if (urlparse(server).hostname is not None):
registry_secret_name = "{server}-{user}".format(server=urlparse(server).hostname.replace('.', ''), user=username.lower())
else:
registry_secret_name = "{server}-{user}".format(server=server.replace('.', ''), user=username.lower())

_remove_secret(containerapp_def, secret_name=registry_secret_name)

def _remove_secret(containerapp_def, secret_name):
if "secrets" not in containerapp_def["properties"]["configuration"]:
containerapp_def["properties"]["configuration"]["secrets"] = []

for i in range(0, len(containerapp_def["properties"]["configuration"]["secrets"])):
existing_secret = containerapp_def["properties"]["configuration"]["secrets"][i]
if existing_secret["name"].lower() == secret_name.lower():
containerapp_def["properties"]["configuration"]["secrets"].pop(i)
break

def _add_or_update_env_vars(existing_env_vars, new_env_vars):
for new_env_var in new_env_vars:
Expand Down
25 changes: 25 additions & 0 deletions src/containerapp/azext_containerapp/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,28 @@ def load_command_table(self, _):
g.custom_command('list', 'list_revisions', table_transformer=transform_revision_list_output, exception_handler=ex_handler_factory())
g.custom_command('restart', 'restart_revision')
g.custom_command('show', 'show_revision', table_transformer=transform_revision_output, exception_handler=ex_handler_factory())
g.custom_command('copy', 'copy_revision', exception_handler=ex_handler_factory())

with self.command_group('containerapp revision mode') as g:
g.custom_command('set', 'set_revision_mode', exception_handler=ex_handler_factory())

with self.command_group('containerapp ingress') as g:
g.custom_command('enable', 'enable_ingress', exception_handler=ex_handler_factory())
g.custom_command('disable', 'disable_ingress', exception_handler=ex_handler_factory())
g.custom_command('show', 'show_ingress')

with self.command_group('containerapp ingress traffic') as g:
g.custom_command('set', 'set_ingress_traffic', exception_handler=ex_handler_factory())
g.custom_command('show', 'show_ingress_traffic')

with self.command_group('containerapp registry') as g:
g.custom_command('set', 'set_registry', exception_handler=ex_handler_factory())
g.custom_command('show', 'show_registry')
g.custom_command('list', 'list_registry')
g.custom_command('delete', 'delete_registry', exception_handler=ex_handler_factory())

with self.command_group('containerapp secret') as g:
g.custom_command('list', 'list_secrets')
g.custom_command('show', 'show_secret')
g.custom_command('delete', 'delete_secrets', exception_handler=ex_handler_factory())
g.custom_command('set', 'set_secrets', exception_handler=ex_handler_factory())
Loading

0 comments on commit 25e1250

Please sign in to comment.