From nobody Thu Apr 25 14:53:25 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=patchew-devel-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=patchew-devel-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1556795900; cv=none; d=zoho.com; s=zohoarc; b=SGfyqJMiHUK7ZDSiN66BNWkylkH/aywGJzpczmwTyt9WE+7TGM8qlbi0Y+MWk5dO8fYKhQoWezLB10yxGNTUne4Zj+r6bddr+UtsZI91gvw0SkfItqGHRPYmZCuXhwv9guTDxXaxHL8+IdcqxzW3wPYvF12FG/oMjGr0g+hltlU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556795900; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=vHK8CHz6a0IALHExgYcCfzbbDjduyOAE4KbrYwKawhQ=; b=og9GbiEn2S2t4DKGd6i4eZHd9vcLNVHFlzEQmYRvM7oGgJIUqYPixSxawrDP9QHOGXFh4rpNdI4Z6oFwJpHT+YUxAHjf9X65FBHuEg1ZjtdUklaW1u1v+fmthgybufocbY6rPrg0K548iqxs0pp+6/exdNXft/qMwBp8Koa6prk= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=patchew-devel-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1556795900455818.881888588602; Thu, 2 May 2019 04:18:20 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 350ED30832D1; Thu, 2 May 2019 11:18:19 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 29B8C7C375; Thu, 2 May 2019 11:18:19 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 211AE18089CA; Thu, 2 May 2019 11:18:19 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x42BIIrL009015 for ; Thu, 2 May 2019 07:18:18 -0400 Received: by smtp.corp.redhat.com (Postfix) id 93B647C5ED; Thu, 2 May 2019 11:18:18 +0000 (UTC) Received: from mx1.redhat.com (ext-mx01.extmail.prod.ext.phx2.redhat.com [10.5.110.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8BFC47EE8B for ; Thu, 2 May 2019 11:18:18 +0000 (UTC) Received: from mail-ot1-f48.google.com (mail-ot1-f48.google.com [209.85.210.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7587281DE5 for ; Thu, 2 May 2019 11:18:17 +0000 (UTC) Received: by mail-ot1-f48.google.com with SMTP id d24so1662629otl.11 for ; Thu, 02 May 2019 04:18:17 -0700 (PDT) Received: from localhost.localdomain ([198.59.53.9]) by smtp.gmail.com with ESMTPSA id o1sm19095697otj.11.2019.05.02.04.18.15 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 May 2019 04:18:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mAXHt+UG+djo4PG8GG660rEv3mrM1zd8PbWzq4ZdgVE=; b=oBzo/rxo6B8+R4JAs0Esd/Lr5RVgd67KzU/g4yaNG4Zxejgd2EKW57Vn5Gqt2XA2RO AiH3lU+Evl2mGggERLn3UbWKWRQbenPJUrdNOWIDSAoXEVdy+aLfZis9MWj8zX9I4Zsq GpHKZkF1k00IKhynRi2uPuI/u7dleNOWAmwfguL2wOQyuMW/yFoM61bip5W7VMo9kPbC XsRKk1LXh5u21nbWVHYeArimYiOHpiqQ03ONGI6RAMzEJy8vzc70bYv1c1VbX2Df+cly WXHSZ4ShUoxpSzOCZFNYCZ36XnNx7uEXgic/ek5t205eTBc9Yd/XJBSTjOw+Pd6rDAue G8Ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=mAXHt+UG+djo4PG8GG660rEv3mrM1zd8PbWzq4ZdgVE=; b=J/WAXitN+WZ0WzbeMPeEKOfMogo9GcmR0nSiU/fT7+i/Hwx9N3/qq0RQurHKiQkQN0 kfMmalZ7wTj0NC7lBlViOukgx92goy21VppCUBlxeeU4fD+oCGKiHUlGXpFiuiVXHy15 AF4iYr4Wt/6Kr3BDTEL5Y05bFk+nl4ecmbMiJO48Mlawya7df4yFKxhWZmFyHYqUVlBB 26nDNspAj0xcKFCdIZocynD67wuq9/6FdI0cMX819xpnhqF4ygNiLooFECplt2EkC+4I Asohb4Tjg416SYpwMvCrOTpBad4SkzDSc/e+AKQdaJnLAxgCMaWVcBAXNoY27JF9Esc8 I8vA== X-Gm-Message-State: APjAAAUaAnVh7wvlLq1AP2uqDsfdI5l/9J5ujlSHFTXWP6hLE6sMFroV YAdLu37UF8MPT5agHGwXPzILUrr0G1M= X-Google-Smtp-Source: APXvYqyTFoYcveVfYt29lcwnYq10IMc47MOF+IX8Q5Ib6vtmLHUZ8lyS7824aDGmbGsmlFOQcXH6Pw== X-Received: by 2002:a9d:5a0d:: with SMTP id v13mr2063679oth.345.1556795896717; Thu, 02 May 2019 04:18:16 -0700 (PDT) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Thu, 2 May 2019 05:18:00 -0600 Message-Id: <20190502111804.15843-14-pbonzini@redhat.com> In-Reply-To: <20190502111804.15843-1-pbonzini@redhat.com> References: <20190502111804.15843-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 02 May 2019 11:18:17 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 02 May 2019 11:18:17 +0000 (UTC) for IP:'209.85.210.48' DOMAIN:'mail-ot1-f48.google.com' HELO:'mail-ot1-f48.google.com' FROM:'paolo.bonzini@gmail.com' RCPT:'' X-RedHat-Spam-Score: 0.126 (DKIM_SIGNED, DKIM_VALID, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, SPF_PASS) 209.85.210.48 mail-ot1-f48.google.com 209.85.210.48 mail-ot1-f48.google.com X-RedHat-Possible-Forgery: Paolo Bonzini X-Scanned-By: MIMEDefang 2.83 on 10.5.110.25 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH 13/17] rest: allow accessing the configuration via the REST API X-BeenThere: patchew-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Patchew development and discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: patchew-devel-bounces@redhat.com Errors-To: patchew-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Thu, 02 May 2019 11:18:19 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Add a new endpoint /projects/ID/config/ that allows retrieving and setting = the project's module configuration. The endpoint is only accessible to maintai= ners, because it could contain secrets. Signed-off-by: Paolo Bonzini --- api/rest.py | 18 +++++++++++++++++- tests/test_rest.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/api/rest.py b/api/rest.py index 041e82d..982cb6e 100644 --- a/api/rest.py +++ b/api/rest.py @@ -46,6 +46,9 @@ class PatchewPermission(permissions.BasePermission): def is_superuser(self, request): return request.user and request.user.is_superuser =20 + def is_safe_method(self, request): + return request.method in permissions.SAFE_METHODS + def has_project_permission(self, request, view, obj): return obj.maintained_by(request.user) =20 @@ -56,7 +59,7 @@ class PatchewPermission(permissions.BasePermission): return False =20 def has_generic_permission(self, request, view): - return (request.method in permissions.SAFE_METHODS) or \ + return self.is_safe_method(request) or \ self.is_superuser(request) or \ self.has_group_permission(request, view, self.allowed_groups) =20 @@ -93,6 +96,11 @@ class PatchewPermission(permissions.BasePermission): self.has_project_permission(request, view, obj) =20 =20 +class MaintainerPermission(PatchewPermission): + def is_safe_method(self, request): + return False + + class ImportPermission(PatchewPermission): allowed_groups =3D ('importers',) =20 @@ -198,6 +206,14 @@ class ProjectsViewSet(viewsets.ModelViewSet): serializer_class =3D ProjectSerializer permission_classes =3D (PatchewPermission,) =20 + @action(methods=3D['get', 'put'], detail=3DTrue, permission_classes=3D= [MaintainerPermission]) + def config(self, request, pk=3DNone): + project =3D self.get_object() + if request.method =3D=3D 'PUT': + project.config =3D request.data + project.save() + return Response(project.config) + @action(methods=3D['post'], detail=3DTrue, permission_classes=3D[Impor= tPermission]) def update_project_head(self, request, pk=3DNone): """ diff --git a/tests/test_rest.py b/tests/test_rest.py index 4ed9c07..906f651 100755 --- a/tests/test_rest.py +++ b/tests/test_rest.py @@ -92,6 +92,36 @@ class RestTest(PatchewTestCase): self.assertEquals(resp.data['name'], "QEMU") self.assertEquals(resp.data['mailing_list'], "qemu-devel@nongnu.or= g") =20 + def test_project_config_get(self): + self.p.config =3D { + "git": { + "push_to": "/tmp/aaa" + } + } + self.p.save() + resp =3D self.api_client.get(self.PROJECT_BASE + 'config/') + self.assertEquals(resp.status_code, 403) + self.api_client.login(username=3Dself.user, password=3Dself.passwo= rd) + resp =3D self.api_client.get(self.PROJECT_BASE + 'config/') + self.assertEquals(resp.status_code, 200) + self.assertEquals(resp.data['git']['push_to'], '/tmp/aaa') + + def test_project_config_put(self): + new_config =3D { + "git": { + "push_to": "/tmp/bbb" + } + } + resp =3D self.api_client.put(self.PROJECT_BASE + 'config/', new_co= nfig, format=3D'json') + self.assertEquals(resp.status_code, 403) + self.api_client.login(username=3Dself.user, password=3Dself.passwo= rd) + resp =3D self.api_client.put(self.PROJECT_BASE + 'config/', new_co= nfig, format=3D'json') + self.assertEquals(resp.status_code, 200) + self.assertEquals(resp.data['git']['push_to'], '/tmp/bbb') + resp =3D self.api_client.get(self.PROJECT_BASE + 'config/') + self.assertEquals(resp.status_code, 200) + self.assertEquals(resp.data['git']['push_to'], '/tmp/bbb') + def test_update_project_head(self): resp =3D self.apply_and_retrieve('0001-simple-patch.mbox.gz', self.p.id, '20160628014747.20971-1-= famz@redhat.com') --=20 2.21.0 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel