Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Nexus Image Version Must be Semver #149

Merged
merged 5 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion src/aosm/azext_aosm/common/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ class ManifestsExist(str, Enum):
CNF_VALUES_SCHEMA_FILENAME = "values.schema.json"
CNF_TEMPLATE_FOLDER_NAME = "cnf"

SEMVER_REGEX = r"^(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)(?:-(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$"
NEXUS_IMAGE_REGEX = r"^[\~]?(\d+)\.(\d+)\.(\d+)$"
# SEMVER_REGEX = r"^(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)(?:-(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$"
#################
# OLD CONSTANTS #
#################
Expand Down
12 changes: 9 additions & 3 deletions src/aosm/azext_aosm/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import tempfile

from knack.log import get_logger
from azext_aosm.common.constants import SEMVER_REGEX
from azext_aosm.common.constants import NEXUS_IMAGE_REGEX
from azext_aosm.common.exceptions import InvalidFileTypeError, MissingDependency

logger = get_logger(__name__)
Expand Down Expand Up @@ -130,5 +130,11 @@ def split_image_path(image) -> "tuple[str, str, str]":
(name, version) = name_and_version.split(":", 2)
return (source_acr_registry, name, version)

def is_semver(string):
return re.match(SEMVER_REGEX, string) is not None
def is_valid_nexus_image_version(string):
"""Check if image version is valid.

This is based on validation in pez repo.
It requires the image version to be major.minor.path,
jordlay marked this conversation as resolved.
Show resolved Hide resolved
but does enforce full semver validation.
jordlay marked this conversation as resolved.
Show resolved Hide resolved
"""
return re.match(NEXUS_IMAGE_REGEX, string) is not None
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from azext_aosm.configuration_models.onboarding_nfd_base_input_config import (
OnboardingNFDBaseInputConfig,
)
from azext_aosm.common.utils import split_image_path, is_semver
from azext_aosm.common.utils import split_image_path, is_valid_nexus_image_version


@dataclass
Expand Down Expand Up @@ -233,7 +233,7 @@ def validate(self):
raise ValidationError("You must include at least one image")
for image in self.images:
(_, _, version) = split_image_path(image)
if not is_semver(version):
if not is_valid_nexus_image_version(version):
raise ValidationError(f"{image} has invalid version '{version}'.\n"
"Allowed formats are major.minor.patch")
jordlay marked this conversation as resolved.
Show resolved Hide resolved
jordlay marked this conversation as resolved.
Show resolved Hide resolved
if not self.arm_templates:
Expand Down