Skip to content

Commit

Permalink
No-Issue
Browse files Browse the repository at this point in the history
Add namespace parameter in legacy config
  • Loading branch information
chouetz committed Sep 28, 2023
1 parent 2c5c7c0 commit c884de4
Show file tree
Hide file tree
Showing 3 changed files with 19 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 should match any valid
# GitHub username. Username may only contain alphanumeric characters
# or single hyphens, and cannot begin or end with a hyphen
# Maximum of 39 char tested in the validator
LEGACY_NAMESPACE_REGEXP = re.compile("^([a-zA-Z0-9]+-?)+[a-zA-Z0-9]$")


class ContentCategory(enum.Enum):
Expand Down
12 changes: 12 additions & 0 deletions galaxy_importer/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
MAX_LENGTH_AUTHOR = 64
MAX_LENGTH_LICENSE = 32
MAX_LENGTH_NAME = 64
MAX_LENGTH_NAMESPACE = 39
MAX_LENGTH_TAG = 64
MAX_LENGTH_URL = 2000
MAX_LENGTH_VERSION = 128
Expand Down Expand Up @@ -388,6 +389,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 +402,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 +442,15 @@ 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 namespace matches the regular expression."""

if value is not None and (
not constants.LEGACY_NAMESPACE_REGEXP.match(value) or len(value) > MAX_LENGTH_NAMESPACE
):
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 c884de4

Please sign in to comment.