Skip to content

Commit

Permalink
[containerapp] Hide containerapps and jobs env vars on create and upd…
Browse files Browse the repository at this point in the history
…ate (#6867)
  • Loading branch information
p-bouchon authored Oct 25, 2023
1 parent 048fdec commit 106a571
Show file tree
Hide file tree
Showing 9 changed files with 1,697 additions and 1,273 deletions.
2 changes: 2 additions & 0 deletions src/containerapp/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ upcoming
* 'az containerapp compose create': fixed an issue where the environment's resource group was not resolved from --environment when the input value was a resource id.
* 'az containerapp replica count', returns the replica count of a container app
* [Breaking Change] 'az containerapp job create': add default values for container app job properties --replica-completion-count, --replica-retry-limit, --replica-timeout, --parallelism, --min-executions, --max-executions, --polling-interval
* 'az containerapp create/update': hide environment variables, scale rules metadata
* 'az containerapp job create/update': hide environment variables, scale rules metadata, eventTriggerConfig for job
* [Breaking Change] 'az containerapp env create': update the default value of --enable-workload-profiles to `True`
* 'az containerapp compose create': fix containerapp invalid memory resource

Expand Down
21 changes: 21 additions & 0 deletions src/containerapp/azext_containerapp/_transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
from ._utils import safe_get


def transform_containerapp_output(app):
Expand All @@ -17,6 +18,26 @@ def transform_containerapp_output(app):
return result


def transform_sensitive_values(response_json):
for container in safe_get(response_json, "properties", "template", "containers", default=[]):
if "env" in container:
for env in container["env"]:
if env.get("value"):
del env["value"]

if safe_get(response_json, "properties", "template") and "scale" in response_json["properties"]["template"]:
for rule in safe_get(response_json, "properties", "template", "scale", "rules", default=[]):
for (key, val) in rule.items():
if key != "name":
val["metadata"] = dict((k, "") for k, v in val["metadata"].items())

if safe_get(response_json, "properties", "configuration", "eventTriggerConfig") and "scale" in response_json["properties"]["configuration"]["eventTriggerConfig"]:
for rule in safe_get(response_json, "properties", "configuration", "eventTriggerConfig", "scale", "rules", default=[]):
rule["metadata"] = dict((k, "") for k, v in rule["metadata"].items())

return response_json


def transform_containerapp_list_output(apps):
return [transform_containerapp_output(a) for a in apps]

Expand Down
12 changes: 7 additions & 5 deletions src/containerapp/azext_containerapp/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@
transform_job_execution_list_output,
transform_job_execution_show_output,
transform_revision_list_output,
transform_revision_output, transform_usages_output)
transform_revision_output,
transform_usages_output,
transform_sensitive_values)


def load_command_table(self, _):
with self.command_group('containerapp') as g:
g.custom_show_command('show', 'show_containerapp', table_transformer=transform_containerapp_output)
g.custom_command('list', 'list_containerapp', table_transformer=transform_containerapp_list_output)
g.custom_command('create', 'create_containerapp', supports_no_wait=True, exception_handler=ex_handler_factory(), table_transformer=transform_containerapp_output)
g.custom_command('update', 'update_containerapp', supports_no_wait=True, exception_handler=ex_handler_factory(), table_transformer=transform_containerapp_output)
g.custom_command('create', 'create_containerapp', supports_no_wait=True, exception_handler=ex_handler_factory(), table_transformer=transform_containerapp_output, transform=transform_sensitive_values)
g.custom_command('update', 'update_containerapp', supports_no_wait=True, exception_handler=ex_handler_factory(), table_transformer=transform_containerapp_output, transform=transform_sensitive_values)
g.custom_command('delete', 'delete_containerapp', supports_no_wait=True, confirmation=True, exception_handler=ex_handler_factory())
g.custom_command('exec', 'containerapp_ssh', validator=validate_ssh)
g.custom_command('up', 'containerapp_up', supports_no_wait=False, exception_handler=ex_handler_factory())
Expand Down Expand Up @@ -50,9 +52,9 @@ def load_command_table(self, _):
with self.command_group('containerapp job') as g:
g.custom_show_command('show', 'show_containerappsjob')
g.custom_command('list', 'list_containerappsjob')
g.custom_command('create', 'create_containerappsjob', supports_no_wait=True, exception_handler=ex_handler_factory())
g.custom_command('create', 'create_containerappsjob', supports_no_wait=True, exception_handler=ex_handler_factory(), transform=transform_sensitive_values)
g.custom_command('delete', 'delete_containerappsjob', supports_no_wait=True, confirmation=True, exception_handler=ex_handler_factory())
g.custom_command('update', 'update_containerappsjob', supports_no_wait=True, exception_handler=ex_handler_factory())
g.custom_command('update', 'update_containerappsjob', supports_no_wait=True, exception_handler=ex_handler_factory(), transform=transform_sensitive_values)
g.custom_command('start', 'start_containerappsjob', supports_no_wait=True, exception_handler=ex_handler_factory())
g.custom_command('stop', 'stop_containerappsjob', supports_no_wait=True, exception_handler=ex_handler_factory())

Expand Down

Large diffs are not rendered by default.

Loading

0 comments on commit 106a571

Please sign in to comment.