From 6a3d8b8d41dbf97020abfd3a0adc52e981d2531a Mon Sep 17 00:00:00 2001 From: Ryan K Date: Thu, 6 Jun 2024 09:19:12 -0700 Subject: [PATCH] feat: Remove ADU client-side validation of first party handlers (#704) * Remove validation of first party handlers * Add test for first party custom handlers --- azext_iot/deviceupdate/commands_update.py | 8 +-- .../deviceupdate/test_adu_manifest_int.py | 56 +++++++++++++------ 2 files changed, 42 insertions(+), 22 deletions(-) diff --git a/azext_iot/deviceupdate/commands_update.py b/azext_iot/deviceupdate/commands_update.py index e7794c19a..a0addc949 100644 --- a/azext_iot/deviceupdate/commands_update.py +++ b/azext_iot/deviceupdate/commands_update.py @@ -236,8 +236,8 @@ def manifest_init_v5( ): from datetime import datetime from pathlib import PurePath - from azure.cli.core.azclierror import ArgumentUsageError, InvalidArgumentValueError - from azext_iot.deviceupdate.common import FP_HANDLERS, FP_HANDLERS_REQUIRE_CRITERIA + from azure.cli.core.azclierror import ArgumentUsageError + from azext_iot.deviceupdate.common import FP_HANDLERS_REQUIRE_CRITERIA from azext_iot.deviceupdate.providers.utility import parse_manifest_json def _sanitize_safe_params(safe_params: list, keep: list) -> list: @@ -323,10 +323,6 @@ def _associate_related(sanitized_params: list, key: str) -> dict: "handler": assembled_step["handler"], } - if step["handler"].lower().startswith("microsoft") and step["handler"] not in FP_HANDLERS: - if not no_validation: - raise InvalidArgumentValueError(f"Valid Microsoft handlers: {', '.join(FP_HANDLERS)}") - step["files"] = ( list(set([f.strip() for f in assembled_step["files"].split(",")])) if "files" in assembled_step else [] ) diff --git a/azext_iot/tests/deviceupdate/test_adu_manifest_int.py b/azext_iot/tests/deviceupdate/test_adu_manifest_int.py index 54dd9877f..d52667a4d 100644 --- a/azext_iot/tests/deviceupdate/test_adu_manifest_int.py +++ b/azext_iot/tests/deviceupdate/test_adu_manifest_int.py @@ -424,6 +424,46 @@ "manifestVersion": "5.0", }, ), + ( + "--update-provider digimaun0 --update-name customhandler --update-version 0.1 " + "--compat manufacturer=Contoso model=Vacuum " + "--compat ring=0 tier=test " + "--step handler=microsoft/customhandler:2 " + f"--file path=\"{get_context_path(__file__, 'manifests', 'libcurl4-doc-apt-manifest.json')}\" " + f"--related-file path=\"{get_context_path(__file__, 'manifests', 'surface15', 'parent.importmanifest.json')}\" ", + { + "updateId": {"provider": "digimaun0", "name": "customhandler", "version": "0.1"}, + "compatibility": [ + {"manufacturer": "Contoso", "model": "Vacuum"}, + {"ring": "0", "tier": "test"}, + ], + "instructions": { + # no first party handler validation + "steps": [ + { + "handler": "microsoft/customhandler:2", + "files": ["libcurl4-doc-apt-manifest.json"], + "type": "inline", + }, + ] + }, + "files": [ + { + "filename": "libcurl4-doc-apt-manifest.json", + "sizeInBytes": 163, + "hashes": {"sha256": "iFWTIaxp33tf5BR1w0fMmnnHpjsUjLRQ9eZFjw74LbU="}, + "relatedFiles": [ + { + "filename": "parent.importmanifest.json", + "sizeInBytes": 1390, + "hashes": {"sha256": "hos1UvCk66WmtL/SPNUmub+k302BM4gtWYtAF7tOCb4="}, + } + ], + } + ], + "manifestVersion": "5.0", + }, + ), ], ) def test_adu_manifest_init_v5(options, expected): @@ -514,22 +554,6 @@ def test_adu_manifest_init_v5_invalid_path_required(options): "downloadHandler=abc", True, ), - ( - # If content handler starts with microsoft (case-insensitive) enforce valid value. - "--update-provider digimaun --update-name invalid --update-version 1.0 " - "--compat deviceManufacturer=Contoso deviceModel=Vacuum " - "--step handler=microsoft/fake:1 " - f"--file path=\"{get_context_path(__file__, 'manifests', 'libcurl4-doc-apt-manifest.json')}\" ", - False, - ), - ( - # Same as prior test case but ensure escape hatch with --no-validation - "--update-provider digimaun --update-name invalid --update-version 1.0 " - "--compat deviceManufacturer=Contoso deviceModel=Vacuum " - "--step handler=microsoft/fake:1 " - f"--file path=\"{get_context_path(__file__, 'manifests', 'libcurl4-doc-apt-manifest.json')}\" ", - False, - ), ], ) def test_adu_manifest_init_v5_validate_errors(options, no_validation):