Skip to content

Commit 80a128b

Browse files
author
Simon Jakesch
committed
fixing error for secrets, suppressing wrong logging
1 parent 638b6b1 commit 80a128b

File tree

3 files changed

+41
-26
lines changed

3 files changed

+41
-26
lines changed

src/containerapp/azext_containerapp/_compose_utils.py

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1940,7 +1940,8 @@ def get_mcp_gateway_configuration(service):
19401940

19411941
def enable_managed_identity(cmd, resource_group_name, app_name):
19421942
"""
1943-
Enable system-assigned managed identity for a container app.
1943+
Enable system-assigned managed identity for a container app using a scoped PATCH
1944+
so that existing secrets (which are write-only) are not re-sent without values.
19441945
19451946
Args:
19461947
cmd: Azure CLI command context
@@ -1950,36 +1951,42 @@ def enable_managed_identity(cmd, resource_group_name, app_name):
19501951
Returns:
19511952
Dictionary with identity information including principal_id
19521953
"""
1954+
import json
19531955
from knack.log import get_logger
1954-
from ._clients import ContainerAppClient
1955-
1956-
logger = get_logger(__name__)
1956+
from azure.cli.core.commands.client_factory import get_subscription_id
1957+
from azure.cli.core.util import send_raw_request
19571958

1958-
logger.info(f"Enabling system-assigned managed identity for '{app_name}'")
1959+
from ._clients import PREVIEW_API_VERSION
19591960

1960-
try:
1961-
# Get current app using show classmethod
1962-
app = ContainerAppClient.show(cmd, resource_group_name, app_name)
1961+
logger = get_logger(__name__)
19631962

1964-
# Set identity type to SystemAssigned
1965-
if 'identity' not in app:
1966-
app['identity'] = {}
1963+
logger.info(f"Enabling system-assigned managed identity for '{app_name}' via PATCH")
19671964

1968-
app['identity']['type'] = 'SystemAssigned'
1965+
management_hostname = cmd.cli_ctx.cloud.endpoints.resource_manager
1966+
subscription_id = get_subscription_id(cmd.cli_ctx)
1967+
request_url = "{}/subscriptions/{}/resourceGroups/{}/providers/Microsoft.App/containerApps/{}?api-version={}".format(
1968+
management_hostname.strip('/'),
1969+
subscription_id,
1970+
resource_group_name,
1971+
app_name,
1972+
PREVIEW_API_VERSION)
19691973

1970-
# Update the app using create_or_update classmethod
1971-
updated_app = ContainerAppClient.create_or_update(
1972-
cmd, resource_group_name, app_name, app)
1974+
payload = {
1975+
"identity": {
1976+
"type": "SystemAssigned"
1977+
}
1978+
}
19731979

1980+
try:
1981+
response = send_raw_request(cmd.cli_ctx, "PATCH", request_url, body=json.dumps(payload))
1982+
updated_app = response.json()
19741983
identity = updated_app.get('identity', {})
19751984
principal_id = identity.get('principalId')
19761985

19771986
if principal_id:
1978-
logger.info(
1979-
f"Successfully enabled managed identity. Principal ID: {principal_id}")
1987+
logger.info(f"Successfully enabled managed identity. Principal ID: {principal_id}")
19801988
else:
1981-
logger.warning(
1982-
"Managed identity enabled but principal ID not yet available")
1989+
logger.warning("Managed identity enabled but principal ID not yet available")
19831990

19841991
return identity
19851992

src/containerapp/azext_containerapp/containerapp_decorator.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ def get_argument_from_revision(self):
133133
def get_argument_target_label(self):
134134
return self.get_param("target_label")
135135

136+
def get_argument_suppress_ingress_warning(self):
137+
return self.get_param("suppress_ingress_warning")
138+
136139
def validate_arguments(self):
137140
self.containerapp_def = None
138141
try:
@@ -1089,15 +1092,18 @@ def post_process(self, r):
10891092
if "properties" in r and "provisioningState" in r["properties"] and r["properties"]["provisioningState"].lower() == "waiting" and not self.get_argument_no_wait():
10901093
not self.get_argument_disable_warnings() and logger.warning('Containerapp creation in progress. Please monitor the creation using `az containerapp show -n {} -g {}`'.format(self.get_argument_name(), self.get_argument_resource_group_name()))
10911094

1095+
suppress_ingress_warning = bool(self.get_argument_suppress_ingress_warning())
1096+
10921097
if "configuration" in r["properties"] and "ingress" in r["properties"]["configuration"] and \
10931098
r["properties"]["configuration"]["ingress"] and "fqdn" in r["properties"]["configuration"]["ingress"]:
10941099
not self.get_argument_disable_warnings() and logger.warning("\nContainer app created. Access your app at https://{}/\n".format(r["properties"]["configuration"]["ingress"]["fqdn"]))
10951100
else:
1096-
target_port = self.get_argument_target_port() or "<port>"
1097-
not self.get_argument_disable_warnings() and logger.warning(
1098-
"\nContainer app created. To access it over HTTPS, enable ingress: "
1099-
"az containerapp ingress enable -n %s -g %s --type external --target-port %s"
1100-
" --transport auto\n", self.get_argument_name(), self.get_argument_resource_group_name(), target_port)
1101+
if not suppress_ingress_warning:
1102+
target_port = self.get_argument_target_port() or "<port>"
1103+
not self.get_argument_disable_warnings() and logger.warning(
1104+
"\nContainer app created. To access it over HTTPS, enable ingress: "
1105+
"az containerapp ingress enable -n %s -g %s --type external --target-port %s"
1106+
" --transport auto\n", self.get_argument_name(), self.get_argument_resource_group_name(), target_port)
11011107

11021108
if self.get_argument_service_connectors_def_list() is not None:
11031109
linker_client = get_linker_client(self.cmd)

src/containerapp/azext_containerapp/custom.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,8 @@ def create_containerapp(cmd,
773773
runtime=None,
774774
enable_java_metrics=None,
775775
enable_java_agent=None,
776-
kind=None):
776+
kind=None,
777+
suppress_ingress_warning=False):
777778
raw_parameters = locals()
778779

779780
containerapp_create_decorator = ContainerAppPreviewCreateDecorator(
@@ -2759,7 +2760,8 @@ def create_containerapps_from_compose(cmd, # pylint: disable=R0914
27592760
env_vars=env_vars_cli_format,
27602761
secrets=secret_vars,
27612762
min_replicas=final_min_replicas,
2762-
max_replicas=final_max_replicas, )
2763+
max_replicas=final_max_replicas,
2764+
suppress_ingress_warning=True)
27632765
)
27642766

27652767
# Phase 5: Dry-run mode - collect service config instead of deploying

0 commit comments

Comments
 (0)