diff options
author | Clark Boylan <clark.boylan@gmail.com> | 2022-03-31 17:19:21 -0700 |
---|---|---|
committer | Clark Boylan <clark.boylan@gmail.com> | 2022-04-05 16:35:25 -0700 |
commit | c393e41d00814a7ad56a79475bd3faaf87cd72cd (patch) | |
tree | 79532a5b7a32474cb023f4a9f08eebe2eee1aca5 | |
parent | 08348143f5c438547b3b4b73f6af7ff7e753e013 (diff) | |
download | zuul-c393e41d00814a7ad56a79475bd3faaf87cd72cd.tar.gz |
Handle greedy project name regexes
Some users (and our documentation [0]) may want to have project name
regexes that match all projects: ^.*$. If the zuul installation has
colliding project names this is always an error because we evaluate the
non canonical names first then check for collisions.
We have realized the point of the regex system is to simplify
configuration and apply configs to any projects that match. Collisions
don't impact this. Stop returning an error if there are collisions and
instead apply the configs to those projects.
[0] https://zuul-ci.org/docs/zuul/latest/tutorials/quick-start.html#configure-zuul-pipelines
Change-Id: I48fbab74fb42ba7c8005ef1a07b61c090acc154d
-rw-r--r-- | releasenotes/notes/project-regex-update-dcc183d923a6acdd.yaml | 8 | ||||
-rw-r--r-- | zuul/model.py | 17 |
2 files changed, 13 insertions, 12 deletions
diff --git a/releasenotes/notes/project-regex-update-dcc183d923a6acdd.yaml b/releasenotes/notes/project-regex-update-dcc183d923a6acdd.yaml new file mode 100644 index 000000000..87c0e3fb1 --- /dev/null +++ b/releasenotes/notes/project-regex-update-dcc183d923a6acdd.yaml @@ -0,0 +1,8 @@ +--- +fixes: + - | + Project name regex handling has been updated to return all possible + matches. Previously if there were collisions with short names it was an + error. The point of the regex system is to simplify configuration and + apply configs to all projects that match. Collisions don't impact this + behavior so we don't need to raise an error in these cases. diff --git a/zuul/model.py b/zuul/model.py index f5604f196..888575393 100644 --- a/zuul/model.py +++ b/zuul/model.py @@ -7467,8 +7467,7 @@ class Tenant(object): :arg str regex: The regex to match :returns: A list of tuples (trusted, project) describing the found - projects. Raises an exception if the same project name is found - several times across multiple hostnames. + projects. """ matcher = re2.compile(regex) @@ -7476,18 +7475,12 @@ class Tenant(object): result = [] for name, hostname_dict in self.projects.items(): - if matcher.fullmatch(name): - # validate that this match is unambiguous - values = list(hostname_dict.values()) - if len(values) > 1: - raise Exception("Project name '%s' is ambiguous, " - "please fully qualify the project " - "with a hostname. Valid hostnames " - "are %s." % (name, hostname_dict.keys())) - projects.append(values[0]) + projects.extend(hostname_dict.values()) else: - # try to match canonical project names + # It is possible for the regex to match specific connection + # prefixes. Check these more specific names if we didn't add + # all of the possible canonical names already. for project in hostname_dict.values(): if matcher.fullmatch(project.canonical_name): projects.append(project) |