Skip to content

Commit ae8fb6a

Browse files
authored
Added subgroups (Ingress, Registry, Secret) and updated revisions (Azure#18)
* 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>
1 parent e20d8d4 commit ae8fb6a

6 files changed

Lines changed: 830 additions & 4 deletions

File tree

src/containerapp/azext_containerapp/_help.py

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,24 @@
189189
az containerapp revision deactivate --revision-name MyContainerappRevision -g MyResourceGroup
190190
"""
191191

192+
helps['containerapp revision mode set'] = """
193+
type: command
194+
short-summary: Set the revision mode of a Containerapp.
195+
examples:
196+
- name: Set the revision mode of a Containerapp.
197+
text: |
198+
az containerapp revision set --mode Single -n MyContainerapp -g MyResourceGroup
199+
"""
200+
201+
helps['containerapp revision copy'] = """
202+
type: command
203+
short-summary: Create a revision based on a previous revision.
204+
examples:
205+
- name: Create a revision based on a previous revision.
206+
text: |
207+
az containerapp revision copy -n MyContainerapp -g MyResourceGroup --cpu 0.75 --memory 1.5Gi
208+
"""
209+
192210
# Environment Commands
193211
helps['containerapp env'] = """
194212
type: group
@@ -244,6 +262,159 @@
244262
text: |
245263
az containerapp env list -g MyResourceGroup
246264
"""
265+
266+
# Ingress Commands
267+
helps['containerapp ingress'] = """
268+
type: group
269+
short-summary: Commands to manage Containerapp ingress.
270+
"""
271+
272+
helps['containerapp ingress traffic'] = """
273+
type: subgroup
274+
short-summary: Commands to manage Containerapp ingress traffic.
275+
"""
276+
277+
helps['containerapp ingress show'] = """
278+
type: command
279+
short-summary: Show details of a Containerapp ingress.
280+
examples:
281+
- name: Show the details of a Containerapp ingress.
282+
text: |
283+
az containerapp ingress show -n MyContainerapp -g MyResourceGroup
284+
"""
285+
286+
helps['containerapp ingress enable'] = """
287+
type: command
288+
short-summary: Enable Containerapp ingress.
289+
examples:
290+
- name: Enable Containerapp ingress.
291+
text: |
292+
az containerapp ingress enable -n MyContainerapp -g MyResourceGroup --type external --allow-insecure --target-port 80 --transport auto
293+
"""
294+
295+
helps['containerapp ingress disable'] = """
296+
type: command
297+
short-summary: Disable Containerapp ingress.
298+
examples:
299+
- name: Disable Containerapp ingress.
300+
text: |
301+
az containerapp ingress disable -n MyContainerapp -g MyResourceGroup
302+
"""
303+
304+
helps['containerapp ingress traffic'] = """
305+
type: group
306+
short-summary: Commands to manage Containerapp ingress traffic.
307+
"""
308+
309+
helps['containerapp ingress traffic set'] = """
310+
type: command
311+
short-summary: Set Containerapp ingress traffic.
312+
examples:
313+
- name: Set Containerapp ingress traffic.
314+
text: |
315+
az containerapp ingress traffic set -n MyContainerapp -g MyResourceGroup --traffic-weight latest=100
316+
"""
317+
318+
helps['containerapp ingress traffic show'] = """
319+
type: command
320+
short-summary: Show Containerapp ingress traffic.
321+
examples:
322+
- name: Show Containerapp ingress traffic.
323+
text: |
324+
az containerapp ingress traffic show -n MyContainerapp -g MyResourceGroup
325+
"""
326+
327+
# Registry Commands
328+
helps['containerapp registry'] = """
329+
type: group
330+
short-summary: Commands to manage Containerapp registries.
331+
"""
332+
333+
helps['containerapp registry show'] = """
334+
type: command
335+
short-summary: Show details of a Containerapp registry.
336+
examples:
337+
- name: Show the details of a Containerapp registry.
338+
text: |
339+
az containerapp registry show -n MyContainerapp -g MyResourceGroup --server MyContainerappRegistry.azurecr.io
340+
"""
341+
342+
helps['containerapp registry list'] = """
343+
type: command
344+
short-summary: List registries assigned to a Containerapp.
345+
examples:
346+
- name: Show the details of a Containerapp registry.
347+
text: |
348+
az containerapp registry list -n MyContainerapp -g MyResourceGroup
349+
"""
350+
351+
helps['containerapp registry set'] = """
352+
type: command
353+
short-summary: Add or update a Containerapp registry.
354+
examples:
355+
- name: Add a registry to a Containerapp.
356+
text: |
357+
az containerapp registry set -n MyContainerapp -g MyResourceGroup --server MyContainerappRegistry.azurecr.io
358+
- name: Update a Containerapp registry.
359+
text: |
360+
az containerapp registry set -n MyContainerapp -g MyResourceGroup --server MyExistingContainerappRegistry.azurecr.io --username MyRegistryUsername --password MyRegistryPassword
361+
362+
"""
363+
364+
helps['containerapp registry delete'] = """
365+
type: command
366+
short-summary: Delete a registry from a Containerapp.
367+
examples:
368+
- name: Delete a registry from a Containerapp.
369+
text: |
370+
az containerapp registry delete -n MyContainerapp -g MyResourceGroup --server MyContainerappRegistry.azurecr.io
371+
"""
372+
373+
# Secret Commands
374+
helps['containerapp secret'] = """
375+
type: group
376+
short-summary: Commands to manage Containerapp secrets.
377+
"""
378+
379+
helps['containerapp secret show'] = """
380+
type: command
381+
short-summary: Show details of a Containerapp secret.
382+
examples:
383+
- name: Show the details of a Containerapp secret.
384+
text: |
385+
az containerapp secret show -n MyContainerapp -g MyResourceGroup --secret-name MySecret
386+
"""
387+
388+
helps['containerapp secret list'] = """
389+
type: command
390+
short-summary: List the secrets of a Containerapp.
391+
examples:
392+
- name: List the secrets of a Containerapp.
393+
text: |
394+
az containerapp secret list -n MyContainerapp -g MyResourceGroup
395+
"""
396+
397+
helps['containerapp secret delete'] = """
398+
type: command
399+
short-summary: Delete secrets from a Containerapp.
400+
examples:
401+
- name: Delete secrets from a Containerapp.
402+
text: |
403+
az containerapp secret delete -n MyContainerapp -g MyResourceGroup --secret-names MySecret MySecret2
404+
"""
405+
406+
helps['containerapp secret set'] = """
407+
type: command
408+
short-summary: Create/update Containerapp secrets.
409+
examples:
410+
- name: Add a secret to a Containerapp.
411+
text: |
412+
az containerapp secret set -n MyContainerapp -g MyResourceGroup --secrets MySecretName=MySecretValue
413+
- name: Update a Containerapp secret.
414+
text: |
415+
az containerapp secret set -n MyContainerapp -g MyResourceGroup --secrets MyExistingSecretName=MyNewSecretValue
416+
"""
417+
247418
helps['containerapp github-action add'] = """
248419
type: command
249420
short-summary: Adds GitHub Actions to the Containerapp

src/containerapp/azext_containerapp/_models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@
137137
"transport": None, # 'auto', 'http', 'http2'
138138
"traffic": None, # TrafficWeight
139139
"customDomains": None, # [CustomDomain]
140-
# "allowInsecure": None
140+
"allowInsecure": None # Boolean
141141
}
142142

143143
RegistryCredentials = {

src/containerapp/azext_containerapp/_params.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,22 @@ def load_arguments(self, _):
121121
c.argument('login_with_github', help='Interactively log in with Github to retrieve the Personal Access Token')
122122

123123
with self.argument_context('containerapp revision') as c:
124-
c.argument('revision_name', type=str, help='Name of the revision')
124+
c.argument('revision_name', options_list=['--revision'], type=str, help='Name of the revision.')
125+
126+
with self.argument_context('containerapp revision copy') as c:
127+
c.argument('from_revision', type=str, help='Revision to copy from. Default: latest revision.')
128+
129+
with self.argument_context('containerapp ingress') as c:
130+
c.argument('allow_insecure', help='Allow insecure connections for ingress traffic.')
131+
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.")
132+
c.argument('transport', arg_type=get_enum_type(['auto', 'http', 'http2']), help="The transport protocol used for ingress traffic.")
133+
c.argument('target_port', type=int, validator=validate_target_port, help="The application port used for ingress traffic.")
134+
135+
with self.argument_context('containerapp ingress traffic') as c:
136+
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'")
137+
138+
with self.argument_context('containerapp secret set') as c:
139+
c.argument('secrets', nargs='+', options_list=['--secrets', '-s'], help="A list of secret(s) for the containerapp. Space-separated values in 'key=value' format.")
140+
141+
with self.argument_context('containerapp secret delete') as c:
142+
c.argument('secret_names', nargs='+', help="A list of secret(s) for the containerapp. Space-separated secret values names.")

src/containerapp/azext_containerapp/_utils.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,23 @@ def _add_or_update_secrets(containerapp_def, add_secrets):
300300
if not is_existing:
301301
containerapp_def["properties"]["configuration"]["secrets"].append(new_secret)
302302

303+
def _remove_registry_secret(containerapp_def, server, username):
304+
if (urlparse(server).hostname is not None):
305+
registry_secret_name = "{server}-{user}".format(server=urlparse(server).hostname.replace('.', ''), user=username.lower())
306+
else:
307+
registry_secret_name = "{server}-{user}".format(server=server.replace('.', ''), user=username.lower())
308+
309+
_remove_secret(containerapp_def, secret_name=registry_secret_name)
310+
311+
def _remove_secret(containerapp_def, secret_name):
312+
if "secrets" not in containerapp_def["properties"]["configuration"]:
313+
containerapp_def["properties"]["configuration"]["secrets"] = []
314+
315+
for i in range(0, len(containerapp_def["properties"]["configuration"]["secrets"])):
316+
existing_secret = containerapp_def["properties"]["configuration"]["secrets"][i]
317+
if existing_secret["name"].lower() == secret_name.lower():
318+
containerapp_def["properties"]["configuration"]["secrets"].pop(i)
319+
break
303320

304321
def _add_or_update_env_vars(existing_env_vars, new_env_vars):
305322
for new_env_var in new_env_vars:

src/containerapp/azext_containerapp/commands.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,28 @@ def load_command_table(self, _):
6767
g.custom_command('list', 'list_revisions', table_transformer=transform_revision_list_output, exception_handler=ex_handler_factory())
6868
g.custom_command('restart', 'restart_revision')
6969
g.custom_command('show', 'show_revision', table_transformer=transform_revision_output, exception_handler=ex_handler_factory())
70+
g.custom_command('copy', 'copy_revision', exception_handler=ex_handler_factory())
71+
72+
with self.command_group('containerapp revision mode') as g:
73+
g.custom_command('set', 'set_revision_mode', exception_handler=ex_handler_factory())
74+
75+
with self.command_group('containerapp ingress') as g:
76+
g.custom_command('enable', 'enable_ingress', exception_handler=ex_handler_factory())
77+
g.custom_command('disable', 'disable_ingress', exception_handler=ex_handler_factory())
78+
g.custom_command('show', 'show_ingress')
79+
80+
with self.command_group('containerapp ingress traffic') as g:
81+
g.custom_command('set', 'set_ingress_traffic', exception_handler=ex_handler_factory())
82+
g.custom_command('show', 'show_ingress_traffic')
83+
84+
with self.command_group('containerapp registry') as g:
85+
g.custom_command('set', 'set_registry', exception_handler=ex_handler_factory())
86+
g.custom_command('show', 'show_registry')
87+
g.custom_command('list', 'list_registry')
88+
g.custom_command('delete', 'delete_registry', exception_handler=ex_handler_factory())
89+
90+
with self.command_group('containerapp secret') as g:
91+
g.custom_command('list', 'list_secrets')
92+
g.custom_command('show', 'show_secret')
93+
g.custom_command('delete', 'delete_secrets', exception_handler=ex_handler_factory())
94+
g.custom_command('set', 'set_secrets', exception_handler=ex_handler_factory())

0 commit comments

Comments
 (0)