From 929417492f525a0dd31505e1a94a29507b99241d Mon Sep 17 00:00:00 2001 From: Ruchi Maheshwari Date: Fri, 7 Mar 2025 12:03:45 -0800 Subject: [PATCH 1/3] added validation for tag-convention allowed values --- src/acrcssc/azext_acrcssc/_validators.py | 3 +++ src/acrcssc/azext_acrcssc/helper/_constants.py | 1 + 2 files changed, 4 insertions(+) diff --git a/src/acrcssc/azext_acrcssc/_validators.py b/src/acrcssc/azext_acrcssc/_validators.py index a753134708e..15294c35daf 100644 --- a/src/acrcssc/azext_acrcssc/_validators.py +++ b/src/acrcssc/azext_acrcssc/_validators.py @@ -18,6 +18,7 @@ CONTINUOUSPATCH_CONFIG_SCHEMA_V1, CONTINUOUSPATCH_CONFIG_SCHEMA_SIZE_LIMIT, CONTINUOUSPATCH_CONFIG_SUPPORTED_VERSIONS, + CONTINUOUSPATCH_CONFIG_SUPPORTED_TAGCONVENTIONS, CONTINUOUSPATCH_ALL_TASK_NAMES, ERROR_MESSAGE_INVALID_TIMESPAN_FORMAT, ERROR_MESSAGE_INVALID_TIMESPAN_VALUE, @@ -76,6 +77,8 @@ def _validate_continuouspatch_config(config): raise InvalidArgumentValueError("Configuration error: Tag '*' is not allowed with other tags in the same repository. Use '*' as the only tag in the repository to avoid overlaps.") if config.get("version", "") not in CONTINUOUSPATCH_CONFIG_SUPPORTED_VERSIONS: raise InvalidArgumentValueError(f"Configuration error: Version {config.get('version', '')} is not supported. Supported versions are {CONTINUOUSPATCH_CONFIG_SUPPORTED_VERSIONS}") + if "tag-convention" in config and config.get("tag-convention", "") not in CONTINUOUSPATCH_CONFIG_SUPPORTED_TAGCONVENTIONS: + raise InvalidArgumentValueError(f"Configuration error: Tag convention {config.get('tag-convention', '')} is not supported. Supported tag conventions are {CONTINUOUSPATCH_CONFIG_SUPPORTED_TAGCONVENTIONS}") # to save on API calls, we the list of tasks found in the registry diff --git a/src/acrcssc/azext_acrcssc/helper/_constants.py b/src/acrcssc/azext_acrcssc/helper/_constants.py index 692cefe7a8b..dbe04444001 100644 --- a/src/acrcssc/azext_acrcssc/helper/_constants.py +++ b/src/acrcssc/azext_acrcssc/helper/_constants.py @@ -95,6 +95,7 @@ class TaskRunStatus(Enum): } CONTINUOUSPATCH_CONFIG_SCHEMA_SIZE_LIMIT = 1024 * 1024 * 10 # 10MB, we don't want to allow huge files CONTINUOUSPATCH_CONFIG_SUPPORTED_VERSIONS = ["v1"] +CONTINUOUSPATCH_CONFIG_SUPPORTED_TAGCONVENTIONS = ["incremental", "floating"] CONTINUOUSPATCH_CONFIG_SCHEMA_V1 = { "type": "object", "properties": { From 8035585bf4e0e7193a7c1059a5f906505932c3e1 Mon Sep 17 00:00:00 2001 From: Ruchi Maheshwari Date: Fri, 7 Mar 2025 12:56:28 -0800 Subject: [PATCH 2/3] Moved version validation check to schema validation and fixed the tag-convention schema validation to strictly allow for only incremental or floating --- src/acrcssc/azext_acrcssc/_validators.py | 6 ------ src/acrcssc/azext_acrcssc/helper/_constants.py | 5 ++--- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/acrcssc/azext_acrcssc/_validators.py b/src/acrcssc/azext_acrcssc/_validators.py index 15294c35daf..244d23cd49d 100644 --- a/src/acrcssc/azext_acrcssc/_validators.py +++ b/src/acrcssc/azext_acrcssc/_validators.py @@ -17,8 +17,6 @@ CONTINUOUSPATCH_OCI_ARTIFACT_CONFIG, CONTINUOUSPATCH_CONFIG_SCHEMA_V1, CONTINUOUSPATCH_CONFIG_SCHEMA_SIZE_LIMIT, - CONTINUOUSPATCH_CONFIG_SUPPORTED_VERSIONS, - CONTINUOUSPATCH_CONFIG_SUPPORTED_TAGCONVENTIONS, CONTINUOUSPATCH_ALL_TASK_NAMES, ERROR_MESSAGE_INVALID_TIMESPAN_FORMAT, ERROR_MESSAGE_INVALID_TIMESPAN_VALUE, @@ -75,10 +73,6 @@ def _validate_continuouspatch_config(config): raise InvalidArgumentValueError(f"Configuration error: Repository '{repository['repository']}' with tag '{tag}' is not allowed. Tags ending with '*-patched' (floating tag) or '*-0' to '*-999' (incremental tag) are reserved for internal use.") if tag == "*" and len(repository.get("tags", [])) > 1: raise InvalidArgumentValueError("Configuration error: Tag '*' is not allowed with other tags in the same repository. Use '*' as the only tag in the repository to avoid overlaps.") - if config.get("version", "") not in CONTINUOUSPATCH_CONFIG_SUPPORTED_VERSIONS: - raise InvalidArgumentValueError(f"Configuration error: Version {config.get('version', '')} is not supported. Supported versions are {CONTINUOUSPATCH_CONFIG_SUPPORTED_VERSIONS}") - if "tag-convention" in config and config.get("tag-convention", "") not in CONTINUOUSPATCH_CONFIG_SUPPORTED_TAGCONVENTIONS: - raise InvalidArgumentValueError(f"Configuration error: Tag convention {config.get('tag-convention', '')} is not supported. Supported tag conventions are {CONTINUOUSPATCH_CONFIG_SUPPORTED_TAGCONVENTIONS}") # to save on API calls, we the list of tasks found in the registry diff --git a/src/acrcssc/azext_acrcssc/helper/_constants.py b/src/acrcssc/azext_acrcssc/helper/_constants.py index dbe04444001..1de36febeca 100644 --- a/src/acrcssc/azext_acrcssc/helper/_constants.py +++ b/src/acrcssc/azext_acrcssc/helper/_constants.py @@ -94,17 +94,16 @@ class TaskRunStatus(Enum): }, } CONTINUOUSPATCH_CONFIG_SCHEMA_SIZE_LIMIT = 1024 * 1024 * 10 # 10MB, we don't want to allow huge files -CONTINUOUSPATCH_CONFIG_SUPPORTED_VERSIONS = ["v1"] -CONTINUOUSPATCH_CONFIG_SUPPORTED_TAGCONVENTIONS = ["incremental", "floating"] CONTINUOUSPATCH_CONFIG_SCHEMA_V1 = { "type": "object", "properties": { "version": { "type": "string", + "pattern": "v1" }, "tag-convention": { "type": "string", - "pattern": "(?i)floating|incremental" + "pattern": "floating|incremental" }, "repositories": { "type": "array", From a007578d09632a7e6379b36d974eb47ff8e861de Mon Sep 17 00:00:00 2001 From: Ruchi Maheshwari Date: Fri, 7 Mar 2025 13:56:37 -0800 Subject: [PATCH 3/3] Taking copilots suggestion for exact match --- src/acrcssc/azext_acrcssc/helper/_constants.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/acrcssc/azext_acrcssc/helper/_constants.py b/src/acrcssc/azext_acrcssc/helper/_constants.py index 1de36febeca..59a0b541bc9 100644 --- a/src/acrcssc/azext_acrcssc/helper/_constants.py +++ b/src/acrcssc/azext_acrcssc/helper/_constants.py @@ -99,11 +99,11 @@ class TaskRunStatus(Enum): "properties": { "version": { "type": "string", - "pattern": "v1" + "pattern": "^(v1)$" }, "tag-convention": { "type": "string", - "pattern": "floating|incremental" + "pattern": "^(floating|incremental)$" }, "repositories": { "type": "array",