From 4d59d30ed8b95f7b30bb356b4027dd543d1b114f Mon Sep 17 00:00:00 2001 From: Colby Williams Date: Thu, 17 Aug 2023 18:36:38 -0500 Subject: [PATCH 1/3] support osx with (arm) apple chips (M1, M2, etc.) --- src/azure-cli/azure/cli/command_modules/resource/_bicep.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/azure-cli/azure/cli/command_modules/resource/_bicep.py b/src/azure-cli/azure/cli/command_modules/resource/_bicep.py index d5579eb4947..e96127926b5 100644 --- a/src/azure-cli/azure/cli/command_modules/resource/_bicep.py +++ b/src/azure-cli/azure/cli/command_modules/resource/_bicep.py @@ -282,6 +282,8 @@ def _get_bicep_download_url(system, release_tag, target_platform=None): return download_url.format("bicep-linux-musl-x64") return download_url.format("bicep-linux-x64") if system == "Darwin": + if platform.processor() == 'arm': + return download_url.format("bicep-osx-arm64") return download_url.format("bicep-osx-x64") raise ValidationError(f'The platform "{system}" is not supported.') From fe6353d4a95d7472dadc17900d27c07fc8f257c3 Mon Sep 17 00:00:00 2001 From: Colby Williams Date: Thu, 17 Aug 2023 18:38:06 -0500 Subject: [PATCH 2/3] respect bicep.use_binary_from_path in all commands --- .../cli/command_modules/resource/_bicep.py | 68 ++++++++++++------- .../cli/command_modules/resource/custom.py | 16 ++--- .../tests/latest/test_resource_custom.py | 2 +- 3 files changed, 53 insertions(+), 33 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/resource/_bicep.py b/src/azure-cli/azure/cli/command_modules/resource/_bicep.py index e96127926b5..f7e64ac2f0a 100644 --- a/src/azure-cli/azure/cli/command_modules/resource/_bicep.py +++ b/src/azure-cli/azure/cli/command_modules/resource/_bicep.py @@ -58,24 +58,17 @@ def validate_bicep_target_scope(template_schema, deployment_scope): def run_bicep_command(cli_ctx, args, auto_install=True): - if _use_binary_from_path(cli_ctx): - from shutil import which - - if which("bicep") is None: - raise ValidationError( - 'Could not find the "bicep" executable on PATH. To install Bicep via Azure CLI, set the "bicep.use_binary_from_path" configuration to False and run "az bicep install".' # pylint: disable=line-too-long - ) + system = platform.system() + bicep_executable_path = _get_bicep_executable_path(cli_ctx, system) - bicep_version_message = _run_command("bicep", ["--version"]) + if bicep_executable_path and not _is_bicep_installation_path(bicep_executable_path, system): + bicep_version_message = _get_bicep_installed_version(bicep_executable_path) _logger.debug("Using Bicep CLI from PATH. %s", bicep_version_message) - return _run_command("bicep", args) - - installation_path = _get_bicep_installation_path(platform.system()) - _logger.debug("Bicep CLI installation path: %s", installation_path) + return _run_command(bicep_executable_path, args) - installed = os.path.isfile(installation_path) + installed = os.path.isfile(bicep_executable_path) _logger.debug("Bicep CLI installed: %s.", installed) check_version = cli_ctx.config.getboolean("bicep", "check_version", True) @@ -91,7 +84,7 @@ def run_bicep_command(cli_ctx, args, auto_install=True): with suppress(ClientRequestError): # Checking upgrade should ignore connection issues. # Users may continue using the current installed version. - installed_version = _get_bicep_installed_version(installation_path) + installed_version = _get_bicep_installed_version(bicep_executable_path) latest_release_tag = get_bicep_latest_release_tag() if cache_expired else latest_release_tag latest_version = _extract_version(latest_release_tag) @@ -104,12 +97,12 @@ def run_bicep_command(cli_ctx, args, auto_install=True): if cache_expired: _refresh_bicep_version_check_cache(latest_release_tag) - return _run_command(installation_path, args) + return _run_command(bicep_executable_path, args) def ensure_bicep_installation(cli_ctx, release_tag=None, target_platform=None, stdout=True): system = platform.system() - installation_path = _get_bicep_installation_path(system) + installation_path = _get_bicep_executable_path(cli_ctx, system) if os.path.isfile(installation_path): if not release_tag: @@ -120,6 +113,9 @@ def ensure_bicep_installation(cli_ctx, release_tag=None, target_platform=None, s if installed_version and target_version and installed_version == target_version: return + if not _is_bicep_installation_path(installation_path, system): + installation_path = _get_bicep_installation_path(system) + installation_dir = os.path.dirname(installation_path) if not os.path.exists(installation_dir): os.makedirs(installation_dir) @@ -156,10 +152,15 @@ def ensure_bicep_installation(cli_ctx, release_tag=None, target_platform=None, s def remove_bicep_installation(cli_ctx): system = platform.system() - installation_path = _get_bicep_installation_path(system) + bicep_executable_path = _get_bicep_executable_path(cli_ctx, system) + + if not _is_bicep_installation_path(bicep_executable_path, system): + raise ValidationError( + f'The bicep executable "{bicep_executable_path}" is not managed by Azure CLI. To install Bicep via Azure CLI, set the "bicep.use_binary_from_path" configuration to False and run "az bicep install".' # pylint: disable=line-too-long + ) - if os.path.exists(installation_path): - os.remove(installation_path) + if os.path.exists(bicep_executable_path): + os.remove(bicep_executable_path) if os.path.exists(_bicep_version_check_file_path): os.remove(_bicep_version_check_file_path) @@ -196,10 +197,10 @@ def get_bicep_latest_release_tag(): raise ClientRequestError(f"Error while attempting to retrieve the latest Bicep version: {err}.") -def bicep_version_greater_than_or_equal_to(version): +def bicep_version_greater_than_or_equal_to(cli_ctx, version): system = platform.system() - installation_path = _get_bicep_installation_path(system) - installed_version = _get_bicep_installed_version(installation_path) + bicep_executable_path = _get_bicep_executable_path(cli_ctx, system) + installed_version = _get_bicep_installed_version(bicep_executable_path) parsed_version = semver.VersionInfo.parse(version) return installed_version >= parsed_version @@ -288,6 +289,25 @@ def _get_bicep_download_url(system, release_tag, target_platform=None): raise ValidationError(f'The platform "{system}" is not supported.') +def _get_bicep_executable_path(cli_ctx, system): + if _use_binary_from_path(cli_ctx): + from shutil import which + + bicep_executable_path = which("bicep") + + if bicep_executable_path is None: + raise ValidationError( + 'Could not find the "bicep" executable on PATH. To install Bicep via Azure CLI, set the "bicep.use_binary_from_path" configuration to False and run "az bicep install".' # pylint: disable=line-too-long + ) + + return bicep_executable_path + + bicep_executable_path = _get_bicep_installation_path(system) + _logger.debug("Bicep CLI installation path: %s", bicep_executable_path) + + +def _is_bicep_installation_path(bicep_executable_path, system): + return bicep_executable_path == _get_bicep_installation_path(system) def _get_bicep_installation_path(system): if system == "Windows": @@ -303,8 +323,8 @@ def _extract_version(text): return semver.VersionInfo.parse(semver_match.group(0)) if semver_match else None -def _run_command(bicep_installation_path, args): - process = subprocess.run([rf"{bicep_installation_path}"] + args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) +def _run_command(bicep_executable_path, args): + process = subprocess.run([rf"{bicep_executable_path}"] + args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) try: process.check_returncode() diff --git a/src/azure-cli/azure/cli/command_modules/resource/custom.py b/src/azure-cli/azure/cli/command_modules/resource/custom.py index 56d12e6d592..91b1e2d6449 100644 --- a/src/azure-cli/azure/cli/command_modules/resource/custom.py +++ b/src/azure-cli/azure/cli/command_modules/resource/custom.py @@ -972,7 +972,7 @@ def _prepare_deployment_properties_unmodified(cmd, deployment_scope, template_fi ensure_bicep_installation(cli_ctx) minimum_supported_version = "0.14.85" - if not bicep_version_greater_than_or_equal_to(minimum_supported_version): + if not bicep_version_greater_than_or_equal_to(cli_ctx, minimum_supported_version): raise ArgumentUsageError(f"Unable to compile .bicepparam file with the current version of Bicep CLI. Please upgrade Bicep CLI to {minimum_supported_version} or later.") if len(parameters) > 1: raise ArgumentUsageError("Can not use --parameters argument more than once when using a .bicepparam file") @@ -1175,7 +1175,7 @@ def _prepare_stacks_templates_and_parameters(cmd, rcf, deployment_stack_model, t ensure_bicep_installation(cmd.cli_ctx) minimum_supported_version = "0.14.85" - if not bicep_version_greater_than_or_equal_to(minimum_supported_version): + if not bicep_version_greater_than_or_equal_to(cmd.cli_ctx, minimum_supported_version): raise ArgumentUsageError( "Unable to compile .bicepparam file with the current version of Bicep CLI. Please use az bicep upgrade to upgrade Bicep CLI.") if len(parameters) > 1: @@ -4289,7 +4289,7 @@ def format_bicep_file(cmd, file, stdout=None, outdir=None, outfile=None, newline ensure_bicep_installation(cmd.cli_ctx) minimum_supported_version = "0.12.1" - if bicep_version_greater_than_or_equal_to(minimum_supported_version): + if bicep_version_greater_than_or_equal_to(cmd.cli_ctx, minimum_supported_version): args = ["format", file] if outdir: args += ["--outdir", outdir] @@ -4318,17 +4318,17 @@ def publish_bicep_file(cmd, file, target, documentationUri=None, force=None): ensure_bicep_installation(cmd.cli_ctx) minimum_supported_version = "0.4.1008" - if bicep_version_greater_than_or_equal_to(minimum_supported_version): + if bicep_version_greater_than_or_equal_to(cmd.cli_ctx, minimum_supported_version): args = ["publish", file, "--target", target] if documentationUri: minimum_supported_version_for_documentationUri_parameter = "0.14.46" - if bicep_version_greater_than_or_equal_to(minimum_supported_version_for_documentationUri_parameter): + if bicep_version_greater_than_or_equal_to(cmd.cli_ctx, minimum_supported_version_for_documentationUri_parameter): args += ["--documentationUri", documentationUri] else: logger.error("az bicep publish with --documentationUri/-d parameter could not be executed with the current version of Bicep CLI. Please upgrade Bicep CLI to v%s or later.", minimum_supported_version_for_documentationUri_parameter) if force: minimum_supported_version_for_publish_force = "0.17.1" - if bicep_version_greater_than_or_equal_to(minimum_supported_version_for_publish_force): + if bicep_version_greater_than_or_equal_to(cmd.cli_ctx, minimum_supported_version_for_publish_force): args += ["--force"] else: logger.error("az bicep publish with --force parameter could not be executed with the current version of Bicep CLI. Please upgrade Bicep CLI to v%s or later.", minimum_supported_version_for_publish_force) @@ -4341,7 +4341,7 @@ def restore_bicep_file(cmd, file, force=None): ensure_bicep_installation(cmd.cli_ctx) minimum_supported_version = "0.4.1008" - if bicep_version_greater_than_or_equal_to(minimum_supported_version): + if bicep_version_greater_than_or_equal_to(cmd.cli_ctx, minimum_supported_version): args = ["restore", file] if force: args += ["--force"] @@ -4369,7 +4369,7 @@ def generate_params_file(cmd, file, no_restore=None, outdir=None, outfile=None, ensure_bicep_installation(cmd.cli_ctx) minimum_supported_version = "0.7.4" - if bicep_version_greater_than_or_equal_to(minimum_supported_version): + if bicep_version_greater_than_or_equal_to(cmd.cli_ctx, minimum_supported_version): args = ["generate-params", file] if no_restore: args += ["--no-restore"] diff --git a/src/azure-cli/azure/cli/command_modules/resource/tests/latest/test_resource_custom.py b/src/azure-cli/azure/cli/command_modules/resource/tests/latest/test_resource_custom.py index 46badb0d93e..c76a6dbccb2 100644 --- a/src/azure-cli/azure/cli/command_modules/resource/tests/latest/test_resource_custom.py +++ b/src/azure-cli/azure/cli/command_modules/resource/tests/latest/test_resource_custom.py @@ -555,7 +555,7 @@ def test_format_bicep_file(self, mock_print, mock_run_bicep_command, mock_bicep_ format_bicep_file(cmd, file_path, stdout=stdout) # Assert. - mock_bicep_version_greater_than_or_equal_to.assert_called_once_with("0.12.1") + mock_bicep_version_greater_than_or_equal_to.assert_called_once_with(cmd.cli_ctx, "0.12.1") mock_run_bicep_command.assert_called_once_with(cmd.cli_ctx, ["format", file_path, "--stdout"]) if __name__ == '__main__': From b985ec04694e350493d825ff2b3c5078faacc62c Mon Sep 17 00:00:00 2001 From: Colby Williams Date: Tue, 2 Apr 2024 16:26:04 -0500 Subject: [PATCH 3/3] fix merge conflicts --- .gitignore | 2 + .../cli/command_modules/resource/_bicep.py | 33 ++++------ .../cli/command_modules/resource/custom.py | 63 ++----------------- .../tests/latest/test_resource_custom.py | 13 ++-- 4 files changed, 23 insertions(+), 88 deletions(-) diff --git a/.gitignore b/.gitignore index 7af160a1183..bf5d43da596 100644 --- a/.gitignore +++ b/.gitignore @@ -117,3 +117,5 @@ pip.log az_command_coverage.txt +.venv +.local \ No newline at end of file diff --git a/src/azure-cli/azure/cli/command_modules/resource/_bicep.py b/src/azure-cli/azure/cli/command_modules/resource/_bicep.py index 971120781b3..a50a2e2e00e 100644 --- a/src/azure-cli/azure/cli/command_modules/resource/_bicep.py +++ b/src/azure-cli/azure/cli/command_modules/resource/_bicep.py @@ -56,22 +56,16 @@ def validate_bicep_target_scope(template_schema, deployment_scope): f'The target scope "{target_scope}" does not match the deployment scope "{deployment_scope}".' ) -# TODO: colby -# def run_bicep_command(cli_ctx, args, auto_install=True): -# system = platform.system() -# bicep_executable_path = _get_bicep_executable_path(cli_ctx, system) def run_bicep_command(cli_ctx, args, auto_install=True, custom_env=None): - if _use_binary_from_path(cli_ctx): - from shutil import which + system = platform.system() + bicep_executable_path = _get_bicep_executable_path(cli_ctx, system) if bicep_executable_path and not _is_bicep_installation_path(bicep_executable_path, system): - bicep_version_message = _get_bicep_installed_version(bicep_executable_path) _logger.debug("Using Bicep CLI from PATH. %s", bicep_version_message) - # return _run_command(bicep_executable_path, args) - return _run_command("bicep", args, custom_env) + return _run_command(bicep_executable_path, args, custom_env) installed = os.path.isfile(bicep_executable_path) _logger.debug("Bicep CLI installed: %s.", installed) @@ -102,9 +96,7 @@ def run_bicep_command(cli_ctx, args, auto_install=True, custom_env=None): if cache_expired: _refresh_bicep_version_check_cache(latest_release_tag) - # TODO: colby - # return _run_command(bicep_executable_path, args) - return _run_command(installation_path, args, custom_env) + return _run_command(bicep_executable_path, args, custom_env) def ensure_bicep_installation(cli_ctx, release_tag=None, target_platform=None, stdout=True): @@ -165,7 +157,6 @@ def remove_bicep_installation(cli_ctx): raise ValidationError( f'The bicep executable "{bicep_executable_path}" is not managed by Azure CLI. To install Bicep via Azure CLI, set the "bicep.use_binary_from_path" configuration to False and run "az bicep install".' # pylint: disable=line-too-long ) - if os.path.exists(bicep_executable_path): os.remove(bicep_executable_path) if os.path.exists(_bicep_version_check_file_path): @@ -290,12 +281,11 @@ def _get_bicep_download_url(system, release_tag, target_platform=None): return download_url.format("bicep-linux-musl-x64") return download_url.format("bicep-linux-x64") if system == "Darwin": - if platform.processor() == 'arm': - return download_url.format("bicep-osx-arm64") - return download_url.format("bicep-osx-x64") + return download_url.format("bicep-osx-arm64") if platform.processor() == 'arm' else download_url.format("bicep-osx-x64") raise ValidationError(f'The platform "{system}" is not supported.') + def _get_bicep_executable_path(cli_ctx, system): if _use_binary_from_path(cli_ctx): from shutil import which @@ -312,10 +302,13 @@ def _get_bicep_executable_path(cli_ctx, system): bicep_executable_path = _get_bicep_installation_path(system) _logger.debug("Bicep CLI installation path: %s", bicep_executable_path) + return bicep_executable_path + def _is_bicep_installation_path(bicep_executable_path, system): return bicep_executable_path == _get_bicep_installation_path(system) + def _get_bicep_installation_path(system): if system == "Windows": return os.path.join(_bicep_installation_dir, "bicep.exe") @@ -330,13 +323,9 @@ def _extract_version(text): return semver.VersionInfo.parse(semver_match.group(0)) if semver_match else None -# TODO: colby -# def _run_command(bicep_executable_path, args): -# process = subprocess.run([rf"{bicep_executable_path}"] + args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - -def _run_command(bicep_installation_path, args, custom_env=None): +def _run_command(bicep_executable_path, args, custom_env=None): process = subprocess.run( - [rf"{bicep_installation_path}"] + args, + [rf"{bicep_executable_path}"] + args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=custom_env) diff --git a/src/azure-cli/azure/cli/command_modules/resource/custom.py b/src/azure-cli/azure/cli/command_modules/resource/custom.py index 10f62c3012c..2747e033c92 100644 --- a/src/azure-cli/azure/cli/command_modules/resource/custom.py +++ b/src/azure-cli/azure/cli/command_modules/resource/custom.py @@ -1062,11 +1062,11 @@ def _parse_bicepparam_file(cmd, template_file, parameters): ensure_bicep_installation(cmd.cli_ctx, stdout=False) minimum_supported_version_bicepparam_compilation = "0.14.85" - if not bicep_version_greater_than_or_equal_to(minimum_supported_version_bicepparam_compilation): + if not bicep_version_greater_than_or_equal_to(cmd.cli_ctx, minimum_supported_version_bicepparam_compilation): raise ArgumentUsageError(f"Unable to compile .bicepparam file with the current version of Bicep CLI. Please upgrade Bicep CLI to {minimum_supported_version_bicepparam_compilation} or later.") minimum_supported_version_supplemental_param = "0.22.6" - if len(parameters) > 1 and not bicep_version_greater_than_or_equal_to(minimum_supported_version_supplemental_param): + if len(parameters) > 1 and not bicep_version_greater_than_or_equal_to(cmd.cli_ctx, minimum_supported_version_supplemental_param): raise ArgumentUsageError(f"Current version of Bicep CLI does not support supplemental parameters with .bicepparam file. Please upgrade Bicep CLI to {minimum_supported_version_supplemental_param} or later.") bicepparam_file = _get_bicepparam_file_path(parameters) @@ -1122,30 +1122,6 @@ def _prepare_deployment_properties_unmodified(cmd, deployment_scope, template_fi template_obj = _remove_comments_from_json(_urlretrieve(template_uri).decode('utf-8'), file_path=template_uri) elif template_spec: template_link = TemplateLink(id=template_spec) - # TODO: colby - # The api-version for ResourceType.MGMT_RESOURCE_RESOURCES may get updated and point to another (newer) version of the api version for - # # ResourceType.MGMT_RESOURCE_TEMPLATESPECS than our designated version. This ensures the api-version of all the rest requests for - # # template_spec are consistent in the same profile: - # api_version = get_api_version(cli_ctx, ResourceType.MGMT_RESOURCE_TEMPLATESPECS) - # template_obj = show_resource(cmd=cmd, resource_ids=[template_spec], api_version=api_version).properties['mainTemplate'] - # else: - # if _is_bicepparam_file_provided(parameters): - # ensure_bicep_installation(cli_ctx) - - # minimum_supported_version = "0.14.85" - # if not bicep_version_greater_than_or_equal_to(cli_ctx, minimum_supported_version): - # raise ArgumentUsageError(f"Unable to compile .bicepparam file with the current version of Bicep CLI. Please upgrade Bicep CLI to {minimum_supported_version} or later.") - # if len(parameters) > 1: - # raise ArgumentUsageError("Can not use --parameters argument more than once when using a .bicepparam file") - # bicepparam_file = parameters[0][0] - # if not is_bicep_file(template_file): - # raise ArgumentUsageError("Only a .bicep template is allowed with a .bicepparam parameter file") - - # build_bicepparam_output = run_bicep_command(cmd.cli_ctx, ["build-params", bicepparam_file, "--bicep-file", template_file, "--stdout"]) - # build_bicepparam_output_json = json.loads(build_bicepparam_output) - # template_content = build_bicepparam_output_json["templateJson"] - # bicepparam_json_content = build_bicepparam_output_json["parametersJson"] - template_obj = _load_template_spec_template(cmd, template_spec) elif _is_bicepparam_file_provided(parameters): template_content, template_spec_id, bicepparam_json_content = _parse_bicepparam_file(cmd, template_file, parameters) @@ -1355,27 +1331,6 @@ def _prepare_stacks_templates_and_parameters(cmd, rcf, deployment_scope, deploym deployment_stacks_template_link = DeploymentStacksTemplateLink(uri=t_uri) deployment_stack_model.template_link = deployment_stacks_template_link template_obj = _remove_comments_from_json(_urlretrieve(t_uri).decode('utf-8'), file_path=t_uri) - # TODO: colby - # else: - # if _is_bicepparam_file_provided(parameters): - # ensure_bicep_installation(cmd.cli_ctx) - - # minimum_supported_version = "0.14.85" - # if not bicep_version_greater_than_or_equal_to(cmd.cli_ctx, minimum_supported_version): - # raise ArgumentUsageError( - # "Unable to compile .bicepparam file with the current version of Bicep CLI. Please use az bicep upgrade to upgrade Bicep CLI.") - # if len(parameters) > 1: - # raise ArgumentUsageError( - # "Can not use --parameters argument more than once when using a .bicepparam file") - # bicepparam_file = parameters[0][0] - # if not is_bicep_file(template_file): - # raise ArgumentUsageError("Only a .bicep template is allowed with a .bicepparam parameter file") - - # build_bicepparam_output = run_bicep_command( - # cmd.cli_ctx, ["build-params", bicepparam_file, "--bicep-file", template_file, "--stdout"]) - # build_bicepparam_output_json = json.loads(build_bicepparam_output) - # template_content = build_bicepparam_output_json["templateJson"] - # bicepparam_json_content = build_bicepparam_output_json["parametersJson"] elif _is_bicepparam_file_provided(parameters): template_content, template_spec_id, bicepparam_json_content = _parse_bicepparam_file(cmd, template_file, parameters) if template_spec_id: @@ -4546,7 +4501,7 @@ def publish_bicep_file(cmd, file, target, documentationUri=None, with_source=Non logger.error("az bicep publish with --documentationUri/-d parameter could not be executed with the current version of Bicep CLI. Please upgrade Bicep CLI to v%s or later.", minimum_supported_version_for_documentationUri_parameter) if with_source: minimum_supported_version_for_publish_with_source = "0.23.1" - if bicep_version_greater_than_or_equal_to(minimum_supported_version_for_publish_with_source): + if bicep_version_greater_than_or_equal_to(cmd.cli_ctx, minimum_supported_version_for_publish_with_source): args += ["--with-source"] else: logger.error("az bicep publish with --with-source/-s parameter could not be executed with the current version of Bicep CLI. Please upgrade Bicep CLI to v%s or later.", minimum_supported_version_for_publish_with_source) @@ -4584,14 +4539,8 @@ def decompile_bicep_file(cmd, file, force=None): def decompileparams_bicep_file(cmd, file, bicep_file=None, outdir=None, outfile=None, stdout=None): ensure_bicep_installation(cmd.cli_ctx) - # TODO: colby - # minimum_supported_version = "0.7.4" - # if bicep_version_greater_than_or_equal_to(cmd.cli_ctx, minimum_supported_version): - # args = ["generate-params", file] - # if no_restore: - # args += ["--no-restore"] minimum_supported_version = "0.18.4" - if bicep_version_greater_than_or_equal_to(minimum_supported_version): + if bicep_version_greater_than_or_equal_to(cmd.cli_ctx, minimum_supported_version): args = ["decompile-params", file] if bicep_file: args += ["--bicep-file", bicep_file] @@ -4622,7 +4571,7 @@ def generate_params_file(cmd, file, no_restore=None, outdir=None, outfile=None, ensure_bicep_installation(cmd.cli_ctx, stdout=False) minimum_supported_version = "0.7.4" - if bicep_version_greater_than_or_equal_to(minimum_supported_version): + if bicep_version_greater_than_or_equal_to(cmd.cli_ctx, minimum_supported_version): args = ["generate-params", file] if no_restore: args += ["--no-restore"] @@ -4649,7 +4598,7 @@ def lint_bicep_file(cmd, file, no_restore=None, diagnostics_format=None): ensure_bicep_installation(cmd.cli_ctx, stdout=False) minimum_supported_version = "0.7.4" - if bicep_version_greater_than_or_equal_to(minimum_supported_version): + if bicep_version_greater_than_or_equal_to(cmd.cli_ctx, minimum_supported_version): args = ["lint", file] if no_restore: args += ["--no-restore"] diff --git a/src/azure-cli/azure/cli/command_modules/resource/tests/latest/test_resource_custom.py b/src/azure-cli/azure/cli/command_modules/resource/tests/latest/test_resource_custom.py index 4c36cc2a8ca..f770acc9488 100644 --- a/src/azure-cli/azure/cli/command_modules/resource/tests/latest/test_resource_custom.py +++ b/src/azure-cli/azure/cli/command_modules/resource/tests/latest/test_resource_custom.py @@ -672,12 +672,7 @@ def test_format_bicep_file(self, mock_print, mock_run_bicep_command, mock_bicep_ format_bicep_file(cmd, file_path, stdout=stdout) # Assert. - - # TODO: colby - # mock_bicep_version_greater_than_or_equal_to.assert_called_once_with(cmd.cli_ctx, "0.12.1") - # mock_run_bicep_command.assert_called_once_with(cmd.cli_ctx, ["format", file_path, "--stdout"]) - - mock_bicep_version_greater_than_or_equal_to.assert_called_once_with("0.12.1") + mock_bicep_version_greater_than_or_equal_to.assert_called_once_with(cmd.cli_ctx, "0.12.1") mock_run_bicep_command.assert_called_once_with(cmd.cli_ctx, ["format", file_path, "--stdout"]) class TestPublishWithSource(unittest.TestCase): @@ -693,7 +688,7 @@ def test_publish_withsource(self, mock_run_bicep_command, mock_bicep_version_gre # Assert. mock_bicep_version_greater_than_or_equal_to.assert_has_calls([ - mock.call("0.4.1008"), # Min version for 'bicep publish' + mock.call(cmd.cli_ctx, "0.4.1008"), # Min version for 'bicep publish' ]) mock_run_bicep_command.assert_called_once_with(cmd.cli_ctx, ['publish', file_path, '--target', 'br:contoso.azurecr.io/bicep/mymodule:v1']) @@ -709,8 +704,8 @@ def test_publish_without_source(self, mock_run_bicep_command, mock_bicep_version # Assert. mock_bicep_version_greater_than_or_equal_to.assert_has_calls([ - mock.call("0.4.1008"), # Min version for 'bicep publish' - mock.call("0.23.1") # Min version for 'bicep publish --with-source' + mock.call(cmd.cli_ctx, "0.4.1008"), # Min version for 'bicep publish' + mock.call(cmd.cli_ctx, "0.23.1") # Min version for 'bicep publish --with-source' ]) mock_run_bicep_command.assert_called_once_with(cmd.cli_ctx, ['publish', file_path, '--target', 'br:contoso.azurecr.io/bicep/mymodule:v1', '--with-source'])