From b9ba3a9aa1eb91d5e12df05d093a6e87c5c93836 Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Mon, 30 Apr 2018 13:13:46 -0700 Subject: [PATCH] Freeze regex projects Add a copy method to ProjectConfig objects so that we can return a frozen ProjectConfig from the ProjectParser, but then make an unfrozen copy so that we can change its name (and then freeze the copy) when treating it as a regex project. Change-Id: I2f39d9a33b9282e44daf5e9a0af3fd35e87e844e --- zuul/configloader.py | 9 ++------- zuul/model.py | 9 +++++++++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/zuul/configloader.py b/zuul/configloader.py index 4cd92fe9cc..0d1a535de2 100644 --- a/zuul/configloader.py +++ b/zuul/configloader.py @@ -930,8 +930,6 @@ class ProjectParser(object): # of the project where it is defined. project_name = (conf['_source_context'].project.canonical_name) - # regex matched projects need to be validatd later - regex = False if project_name.startswith('^'): # regex matching is designed to match other projects so disallow # in untrusted contexts @@ -940,7 +938,6 @@ class ProjectParser(object): # Parse the project as a template since they're mostly the # same. - regex = True project_config = self.pcontext.project_template_parser. \ fromYaml(conf, validate=False, freeze=False) @@ -978,9 +975,7 @@ class ProjectParser(object): default_branch = conf.get('default-branch', 'master') project_config.default_branch = default_branch - # we need to freeze regex projects later - if not regex: - project_config.freeze() + project_config.freeze() return project_config @@ -1739,7 +1734,7 @@ class TenantParser(object): for config_project in config_projects: # we just override the project name here so a simple copy # should be enough - conf = copy.copy(config_project) + conf = config_project.copy() name = project.canonical_name conf.name = name conf.freeze() diff --git a/zuul/model.py b/zuul/model.py index 2d2be97cf5..c1e3ab4560 100644 --- a/zuul/model.py +++ b/zuul/model.py @@ -2511,6 +2511,15 @@ class ProjectConfig(ConfigObject): self.pipelines = {} self.branch_matcher = None + def copy(self): + r = self.__class__(self.name) + r.source_context = self.source_context + r.start_mark = self.start_mark + r.templates = self.templates + r.pipelines = self.pipelines + r.branch_matcher = self.branch_matcher + return r + def addImpliedBranchMatcher(self, branch): self.branch_matcher = change_matcher.ImpliedBranchMatcher(branch)