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

Add namespace parameter in legacy config #241

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 9 additions & 1 deletion galaxy_importer/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,15 @@
# Matches role names with any combination of lowercase letters,
# 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}$")
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
# Some roles may contain underscores
# Maximum of 39 char tested in the validator
# For retrocompatibility with legacy role, allow names
# finishing with hyphen or underscores, and names containing dots
LEGACY_NAMESPACE_REGEXP = re.compile("^([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: 1 addition & 1 deletion tests/integration/test_eda.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def test_eda_import(workdir, local_image_config):
assert "Running pylint on /extensions/eda/plugins/event_source..." in log
assert "aws_sqs_queue.py:29: [E0401" in log
assert "Running pylint on /extensions/eda/plugins/event_filter..." in log
assert "insert_hosts_to_meta.py:53: [C0103" in log
assert "insert_hosts_to_meta.py:31: [E0401" in log
assert "EDA linting complete." in log

assert "Removing temporary files, image and container" in log
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