Skip to content

Commit

Permalink
containerapp create refactor (#6397)
Browse files Browse the repository at this point in the history
  • Loading branch information
Greedygre committed Jun 28, 2023
1 parent 23cbb42 commit 8f07729
Show file tree
Hide file tree
Showing 84 changed files with 182,780 additions and 204,084 deletions.
1 change: 1 addition & 0 deletions src/containerapp/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Upcoming
++++++
* 'az containerapp create/update': --termination-grace-period support custom termination grace period
* 'az containerapp env logs show': fix issue of constructing connection url
* 'az containerapp create/show/list/delete': refactor with containerapp decorator

0.3.34
++++++
Expand Down
78 changes: 78 additions & 0 deletions src/containerapp/azext_containerapp/_decorator_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
# pylint: disable=line-too-long, consider-using-f-string, no-else-return, duplicate-string-formatting-argument, expression-not-assigned, too-many-locals, logging-fstring-interpolation, broad-except, pointless-statement, bare-except
import sys

from azure.cli.core.azclierror import (ValidationError)

from ._utils import safe_get


def load_yaml_file(file_name):
import yaml
import errno

try:
with open(file_name) as stream: # pylint: disable=unspecified-encoding
return yaml.safe_load(stream.read().replace('\x00', ''))
except (IOError, OSError) as ex:
if getattr(ex, 'errno', 0) == errno.ENOENT:
raise ValidationError('{} does not exist'.format(file_name)) from ex
raise
except (yaml.parser.ParserError, UnicodeDecodeError) as ex:
raise ValidationError('Error parsing {} ({})'.format(file_name, str(ex))) from ex


def create_deserializer(models):
from msrest import Deserializer
import inspect
from importlib import import_module

import_module(models)

sdkClasses = inspect.getmembers(sys.modules[models])
deserializer = {}

for sdkClass in sdkClasses:
deserializer[sdkClass[0]] = sdkClass[1]

return Deserializer(deserializer)


def process_loaded_yaml(yaml_containerapp):
if not yaml_containerapp.get('properties'):
yaml_containerapp['properties'] = {}

if safe_get(yaml_containerapp, "identity", "userAssignedIdentities"):
for identity in yaml_containerapp['identity']['userAssignedIdentities']:
# properties (principalId and clientId) are readonly and create (PUT) will throw error if they are provided
# Update (PATCH) ignores them, so it's okay to remove them as well
yaml_containerapp['identity']['userAssignedIdentities'][identity] = {}

nested_properties = ["provisioningState",
"managedEnvironmentId",
"environmentId",
"latestRevisionName",
"latestRevisionFqdn",
"customDomainVerificationId",
"configuration",
"template",
"outboundIPAddresses",
"workloadProfileName",
"latestReadyRevisionName",
"eventStreamEndpoint"]
for nested_property in nested_properties:
tmp = yaml_containerapp.get(nested_property)
if nested_property in yaml_containerapp:
yaml_containerapp['properties'][nested_property] = tmp
del yaml_containerapp[nested_property]
# remove property managedEnvironmentId, can not use safe_get()
if "managedEnvironmentId" in yaml_containerapp['properties']:
tmp = yaml_containerapp['properties']['managedEnvironmentId']
if tmp:
yaml_containerapp['properties']["environmentId"] = tmp
del yaml_containerapp['properties']['managedEnvironmentId']

return yaml_containerapp
Loading

0 comments on commit 8f07729

Please sign in to comment.