Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ jobs:
- task: UsePythonVersion@0
displayName: 'Use Python 3'
inputs:
versionSpec: 3.x
versionSpec: 3.8

- task: BatchScript@1
inputs:
Expand Down
4 changes: 4 additions & 0 deletions src/azure-cli-core/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
Release History
===============

2.14.1
++++++
* Minor fixes

2.14.0
++++++
* Minor fixes
Expand Down
2 changes: 1 addition & 1 deletion src/azure-cli-core/azure/cli/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from __future__ import print_function

__version__ = "2.14.0"
__version__ = "2.14.1"

import os
import sys
Expand Down
2 changes: 1 addition & 1 deletion src/azure-cli-core/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from codecs import open
from setuptools import setup

VERSION = "2.14.0"
VERSION = "2.14.1"

# If we have source, validate that our version numbers match
# This should prevent uploading releases with mismatched versions.
Expand Down
7 changes: 7 additions & 0 deletions src/azure-cli/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
Release History
===============

2.14.1
++++++

**ARM**

* Hotfix: Add TS multiline string support for template inputs

2.14.0
++++++

Expand Down
2 changes: 1 addition & 1 deletion src/azure-cli/azure/cli/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from knack.log import get_logger

__author__ = "Microsoft Corporation <[email protected]>"
__version__ = "2.14.0"
__version__ = "2.14.1"


# A workaround for https://bugs.python.org/issue32502 (https://github.com/Azure/azure-cli/issues/5184)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
import os
import re
import json
from knack.util import CLIError
from azure.cli.core.util import read_file_content
from azure.cli.core.util import read_file_content, shell_safe_json_parse
from azure.cli.command_modules.resource.custom import _remove_comments_from_json
from azure.cli.core.profiles import ResourceType, get_sdk

Expand All @@ -23,6 +24,28 @@ def __init__(self, root_template_directory):
self.Artifact = []


# pylint: disable=redefined-outer-name
def process_template(template, preserve_order=True, file_path=None):
from jsmin import jsmin

# When commenting at the bottom of all elements in a JSON object, jsmin has a bug that will wrap lines.
# It will affect the subsequent multi-line processing logic, so deal with this situation in advance here.
template = re.sub(r'(^[\t ]*//[\s\S]*?\n)|(^[\t ]*/\*{1,2}[\s\S]*?\*/)', '', template, flags=re.M)
minified = jsmin(template)

# Remove extra spaces, compress multiline string(s)
result = re.sub(r'\s\s+', ' ', minified, flags=re.DOTALL)

try:
return shell_safe_json_parse(result, preserve_order)
except CLIError:
# Because the processing of removing comments and compression will lead to misplacement of error location,
# so the error message should be wrapped.
if file_path:
raise CLIError("Failed to parse '{}', please check whether it is a valid JSON format".format(file_path))
raise CLIError("Failed to parse the JSON data, please check whether it is a valid JSON format")


def pack(cmd, template_file):
"""
Packs the specified template and its referenced artifacts for use in a Template Spec.
Expand All @@ -32,8 +55,7 @@ def pack(cmd, template_file):
root_template_file_path = os.path.abspath(template_file)
context = PackingContext(os.path.dirname(root_template_file_path))
template_content = read_file_content(template_file)
sanitized_template = _remove_comments_from_json(template_content)
template_json = json.loads(json.dumps(sanitized_template))
template_json = json.loads(json.dumps(process_template(template_content)))
_pack_artifacts(cmd, root_template_file_path, context)
return PackagedTemplate(template_json, getattr(context, 'Artifact'))

Expand All @@ -54,8 +76,7 @@ def _pack_artifacts(cmd, template_abs_file_path, context):
try:
context.CurrentDirectory = os.path.dirname(template_abs_file_path)
template_content = read_file_content(template_abs_file_path)
artifactable_template_obj = sanitized_template = _remove_comments_from_json(template_content)
template_json = json.loads(json.dumps(sanitized_template))
artifactable_template_obj = _remove_comments_from_json(template_content)
template_link_to_artifact_objs = _get_template_links_to_artifacts(cmd, artifactable_template_obj,
includeNested=True)

Expand Down Expand Up @@ -94,8 +115,7 @@ def _pack_artifacts(cmd, template_abs_file_path, context):
TemplateSpecTemplateArtifact = get_sdk(cmd.cli_ctx, ResourceType.MGMT_RESOURCE_TEMPLATESPECS,
'TemplateSpecTemplateArtifact', mod='models')
template_content = read_file_content(abs_local_path)
sanitized_template = _remove_comments_from_json(template_content)
template_json = json.loads(json.dumps(sanitized_template))
template_json = json.loads(json.dumps(process_template(template_content)))
artifact = TemplateSpecTemplateArtifact(path=as_relative_path, template=template_json)
context.Artifact.append(artifact)
finally:
Expand Down
Loading