From ec0ed91d45670fe63ca76894a43141478decce67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Kadl=C4=8D=C3=ADk?= Date: Mon, 27 Mar 2017 13:28:06 +0200 Subject: [PATCH] Allow to submit owner when NO_AUTH --- module_build_service/utils.py | 3 +++ module_build_service/views.py | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/module_build_service/utils.py b/module_build_service/utils.py index 53ac897f..6d6e12aa 100644 --- a/module_build_service/utils.py +++ b/module_build_service/utils.py @@ -731,6 +731,9 @@ def validate_optional_params(params): raise ValidationError('The request contains parameters specific to Copr builder: {} even though {} is used' .format(", ".join(forbidden_params), conf.system)) + if not conf.no_auth and "owner" in params: + raise ValidationError("The request contains 'owner' parameter, however NO_AUTH is not allowed") + def scm_url_schemes(terse=False): """ diff --git a/module_build_service/views.py b/module_build_service/views.py index b4930008..56c36217 100644 --- a/module_build_service/views.py +++ b/module_build_service/views.py @@ -100,6 +100,9 @@ class ModuleBuildAPI(MethodView): else: handler = SCMHandler(request) + if conf.no_auth and handler.username == "anonymous" and "owner" in handler.data: + handler.username = handler.data["owner"] + if conf.allowed_groups and not (conf.allowed_groups & handler.groups): raise Forbidden("%s is not in any of %r, only %r" % ( handler.username, conf.allowed_groups, handler.groups)) @@ -189,7 +192,7 @@ class SCMHandler(BaseHandler): if isinstance(branch, unicode): branch = branch.encode('utf-8') - optional_params = {k: v for k, v in self.data.items() if k not in ["scmurl", "branch"]} + optional_params = {k: v for k, v in self.data.items() if k not in ["owner", "scmurl", "branch"]} return submit_module_build_from_scm(self.username, url, branch, allow_local_url=False, optional_params=optional_params) @@ -209,7 +212,8 @@ class YAMLFileHandler(BaseHandler): def post(self): r = request.files["yaml"] - return submit_module_build_from_yaml(self.username, r.read(), optional_params=self.data) + optional_params = {k: v for k, v in self.data.items() if k not in ["owner"]} + return submit_module_build_from_yaml(self.username, r.read(), optional_params=optional_params) def register_api_v1():