Skip to content

Commit

Permalink
[No-Issue] Add namespace parameter in legacy config
Browse files Browse the repository at this point in the history
  • Loading branch information
chouetz committed Sep 26, 2023
1 parent 2c5c7c0 commit af2422f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions galaxy_importer/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@
# uppercase letters, numbers, underscores, and hyphens with
# a length in the inclusive range [1, 55].
LEGACY_ROLE_NAME_REGEXP = re.compile("^[a-zA-Z0-9-_]{1,55}$")
# Matches namespaces: Namespace names in Galaxy are limited to
# lowercase word characters (i.e., a-z, 0-9) and ‘_’, must have
# a minimum length of 2 characters, and cannot start with an ‘_’.
# No other characters are allowed, including ‘.’, ‘-‘, and space
LEGACY_NAMESPACE_REGEXP = re.compile("^[a-z0-9][a-z0-9_]{1,54}$")


class ContentCategory(enum.Enum):
Expand Down
9 changes: 9 additions & 0 deletions galaxy_importer/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ class LegacyGalaxyInfo(object):
"""Represents legacy role metadata galaxy_info field."""

role_name = attr.ib(default=None)
namespace = attr.ib(default=None)
author = attr.ib(default=None)
description = attr.ib(default=None)
company = attr.ib(default=None)
Expand All @@ -400,6 +401,7 @@ class LegacyGalaxyInfo(object):
galaxy_tags = attr.ib(factory=list)

@role_name.validator
@namespace.validator
@author.validator
@description.validator
@company.validator
Expand Down Expand Up @@ -439,6 +441,13 @@ def _validate_role_name(self, attribute, value):
if value is not None and not constants.LEGACY_ROLE_NAME_REGEXP.match(value):
raise exc.LegacyRoleSchemaError(f"role name {value} is invalid")

@namespace.validator
def _validate_namespace(self, attribute, value):
"""Ensure role name matches the regular expression."""

if value is not None and not constants.LEGACY_NAMESPACE_REGEXP.match(value):
raise exc.LegacyRoleSchemaError(f"namespace {value} is invalid")

@author.validator
def _validate_author(self, attribute, value):
"""Ensure the author value is not too long."""
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/test_loader_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
galaxy_info:
role_name: my_role
namespace: my_namespace
author: John Doe
description: Some generic role description
platforms:
Expand Down Expand Up @@ -96,6 +97,7 @@ def test_load_values(populated_role_root):

galaxy_info = data.metadata.galaxy_info
assert galaxy_info.role_name == "my_role"
assert galaxy_info.namespace == "my_namespace"
assert galaxy_info.author == "John Doe"
assert galaxy_info.description == "Some generic role description"
assert galaxy_info.platforms == [
Expand Down

0 comments on commit af2422f

Please sign in to comment.