Skip to content
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

Added subgroups (Ingress, Registry, Secret) and updated revisions #18

Merged
merged 17 commits into from
Mar 11, 2022
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
170 changes: 170 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,3 +262,155 @@
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
"""
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 @@ -104,4 +104,22 @@ def load_arguments(self, _):
c.argument('name', name_type, help='Name of the managed Environment.')

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 @@ -293,6 +293,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 @@ -62,3 +62,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