sources: relax "mirror" regexp to follow upstream repo ID

This commit relaxes the "mirror" schema regex from only allow
hashes to the repo ID regex as described in
https://dnf.readthedocs.io/en/latest/conf_ref.html#description

This is needed because in e.g. bootc-image-builder we use
"SetRootDir()" to get the repository information from an existing
bootc image and there the repo_id (that is then used as the mirror_id)
is written in a human friendly way instead of hex.

Thanks to Tomáš Hozza for the suggestions and background info, see
https://github.com/osbuild/osbuild/pull/1974#issuecomment-2579325272
This commit is contained in:
Michael Vogt 2025-01-09 09:45:40 +01:00 committed by Simon de Vlieger
parent b2a34d8b33
commit 65a7ce2461
2 changed files with 11 additions and 5 deletions

View file

@ -22,6 +22,9 @@ from osbuild.util.rhsm import Subscriptions
# NOTE: The top level schema properties are limited to items and options by the
# v2 schema definition
#
# "mirror" pattern follows dnf repo_id as described in:
# https://dnf.readthedocs.io/en/latest/conf_ref.html#description
SCHEMA_2 = """
"properties": {
"items": {
@ -57,7 +60,7 @@ SCHEMA_2 = """
"type": "object",
"additionalProperties": false,
"patternProperties": {
"^[0-9a-f]+$": {
"^[0-9a-zA-Z-._:]+$": {
"required": [
"url",
"type"

View file

@ -140,9 +140,9 @@ def test_librepo_secrets_mtls(mocked_download_pkgs, sources_service, monkeypatch
@pytest.mark.parametrize("test_mirrors,expected_err", [
# bad
(
# only hashes supported for mirror_ids
{"bad_mirror_id": {"url": "http://example.com", "type": "mirrorlist"}},
"'bad_mirror_id' does not match any of the regexes: '^[0-9a-f]+$'",
# no spaces in mirror_id
{"bad mirror": {"url": "http://example.com", "type": "mirrorlist"}},
"'bad mirror' does not match any of the regexes: ",
),
(
{"0123456789abcdef": {"type": "mirrorlist"}},
@ -168,7 +168,10 @@ def test_librepo_secrets_mtls(mocked_download_pkgs, sources_service, monkeypatch
),
(
{"0123": {"url": "http://example.com", "type": "baseurl"}}, "",
)
),
(
{"Com_plex:id.": {"url": "http://x.com", "type": "baseurl"}}, "",
),
])
def test_schema_validation(sources_schema, test_mirrors, expected_err):
test_input = {