From nobody Fri Apr 19 18:42:10 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=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 153021286503375.44312241079604; Thu, 28 Jun 2018 12:07:45 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6BE4F3078AAA; Thu, 28 Jun 2018 19:07:43 +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 546C04D9E9; Thu, 28 Jun 2018 19:07:43 +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 45CEF18037EC; Thu, 28 Jun 2018 19:07:43 +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 w5SJ7gJj006807 for ; Thu, 28 Jun 2018 15:07:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id 598A318ADF; Thu, 28 Jun 2018 19:07:42 +0000 (UTC) Received: from mx1.redhat.com (ext-mx14.extmail.prod.ext.phx2.redhat.com [10.5.110.43]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 51E6418A4D for ; Thu, 28 Jun 2018 19:07:40 +0000 (UTC) Received: from mail-pl0-f45.google.com (mail-pl0-f45.google.com [209.85.160.45]) (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 E5D2730BF55E for ; Thu, 28 Jun 2018 19:07:28 +0000 (UTC) Received: by mail-pl0-f45.google.com with SMTP id 6-v6so3226263plb.0 for ; Thu, 28 Jun 2018 12:07:28 -0700 (PDT) Received: from localhost.localdomain ([112.196.135.52]) by smtp.gmail.com with ESMTPSA id r65-v6sm13446990pfg.65.2018.06.28.12.07.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 28 Jun 2018 12:07:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=XprxpmaiAAZLYuaa85nG2kE0lhDpbpXl3f218sbddnQ=; b=sFw5Ndg9bYIpjl3nDAgOQwu3fQyUDzrxh5ujAlXR1VNFGXrtHL7023TCeA1YaABECe JSMIRhGghiGey/M3qTjDjrrLnwNo2rnAWPOUgbfC6g3muODJC49x8pkzXrHjH2z76kmc Kii9qGLe6f61qeCZhNWEvEo/OwKuho88IUiJAZNH0+u1koRNtCJMEFqAS0VfVzOdG/WT iBXxq+nRL4G8BZRQjA4dbLhXdzGfpaUeEJfvxTULIfzAUwPQaGZthNUbgz7nFY9YmYXF auCxLUa0zGNi/mp5jIEgEJfdyuNRo+KjPePdpo4NEJU9btA6WJd0XFCaL375Q1OKQVHT 0Xkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=XprxpmaiAAZLYuaa85nG2kE0lhDpbpXl3f218sbddnQ=; b=k9X+isdpUSSfuZRnEHyCub9daIKMgtPmdt5AltBywvHFLhTC+91c21aACgP/IOEbt7 j3GL8o230jI71ou9vAuequatSwfwVV0EJQYfObUdHg8L5cfLEtQylCm6ULR5XeKS8Xuf X//orcuBQ+zlPEgljZDJg09eL+YYjIJWro2TL4yMPoxacEKQ1kn+vxKgEP+kJ0WldTAb wSKjyAObpC1+DchmmE4WaeHWYYWJGzN5I26OgwElM2/levdruhLoGdShiXLlpp4cYy0O dhZDZ25UtyguH6RYeFMaDjtFJ2WU7yKu9oK4wVs36SWSgrMAv5RlXGTTgXnJ2RajH7no zU3w== X-Gm-Message-State: APt69E36yFJMB5Err3v6JPm/qOtTL5coiKGAFILNdnng/a3sV8dJaUWM YajcpKPe9sw8I0XYYrFxJCEzBA== X-Google-Smtp-Source: ADUXVKL+NSocTnYumA5KMlNOOOJ+kv/1pAE5+j7o1mLxFvRHPVplGmIHt0DJDZfCqVGyzaIldZF2xQ== X-Received: by 2002:a17:902:22cc:: with SMTP id o12-v6mr11485533plg.68.1530212847925; Thu, 28 Jun 2018 12:07:27 -0700 (PDT) From: Shubham Jain To: patchew-devel@redhat.com Date: Fri, 29 Jun 2018 00:37:05 +0530 Message-Id: <20180628190706.79163-2-shubhamjain7495@gmail.com> In-Reply-To: <20180628190706.79163-1-shubhamjain7495@gmail.com> References: <20180628190706.79163-1-shubhamjain7495@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Thu, 28 Jun 2018 19:07:29 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Thu, 28 Jun 2018 19:07:29 +0000 (UTC) for IP:'209.85.160.45' DOMAIN:'mail-pl0-f45.google.com' HELO:'mail-pl0-f45.google.com' FROM:'shubhamjain7495@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.551 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, SPF_PASS, T_DKIM_INVALID) 209.85.160.45 mail-pl0-f45.google.com 209.85.160.45 mail-pl0-f45.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.43 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: patchew-devel@redhat.com Cc: Shubham Jain Subject: [Patchew-devel] [PATCH 1/2] Changes in Patchew cli to use 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: , MIME-Version: 1.0 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Thu, 28 Jun 2018 19:07:43 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" - Disabled CSRF authentication until OAuth authentication, since DRF leads= to csrf error while handling sessionauthentication. - Added general rest_api function to make request to apis and get response. --- api/rest.py | 11 +++++++++-- patchew-cli | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/api/rest.py b/api/rest.py index 084dbbc..8961811 100644 --- a/api/rest.py +++ b/api/rest.py @@ -25,6 +25,12 @@ from rest_framework.response import Response import rest_framework from mbox import addr_db_to_rest, MboxMessage from rest_framework.parsers import JSONParser, BaseParser +from rest_framework.authentication import SessionAuthentication + +class CsrfExemptSessionAuthentication(SessionAuthentication): + + def enforce_csrf(self, request): + return # To not perform the csrf check previously happening =20 SEARCH_PARAM =3D 'q' =20 @@ -140,7 +146,8 @@ class ProjectsViewSet(viewsets.ModelViewSet): queryset =3D Project.objects.all().order_by('id') serializer_class =3D ProjectSerializer permission_classes =3D (PatchewPermission,) - + authentication_classes =3D (CsrfExemptSessionAuthentication, ) + =20 @action(methods=3D['post'], detail=3DTrue, permission_classes=3D[Impor= tPermission]) def update_project_head(self, request, pk=3DNone): """ @@ -414,7 +421,7 @@ class MessagesViewSet(BaseMessageViewSet): serializer_class =3D MessageSerializer permission_classes =3D (permissions.IsAuthenticatedOrReadOnly,) parser_classes =3D (JSONParser, MessagePlainTextParser, ) - =20 + authentication_classes =3D (CsrfExemptSessionAuthentication,) def create(self, request, *args, **kwargs): m =3D MboxMessage(request.data['mbox']) projects =3D [p for p in Project.objects.all() if p.recognizes(m)] diff --git a/patchew-cli b/patchew-cli index 174d1e6..c53526b 100755 --- a/patchew-cli +++ b/patchew-cli @@ -92,6 +92,41 @@ class SubCommand(object): r =3D None return r =20 + def rest_api_do(self, url_cmd, request_method=3D'get', content_type=3D= None, data=3DNone): + logging.debug("API call '%s':" % url_cmd) + logging.debug("data:\n%s" % data) + cookie =3D http.cookiejar.MozillaCookieJar(COOKIE_FILENAME) + try: + cookie.load() + except IOError: + pass + except http.cookiejar.LoadError: + print("Error while loading cookie", COOKIE_FILENAME) + pass + handler =3D urllib.request.HTTPCookieProcessor(cookie) + opener =3D urllib.request.build_opener(handler) + if url_cmd.startswith("http"): + url =3D url_cmd + else: + url =3D self.base_url + '/api/v1/' + url_cmd + '/' + if data is None: + post_data =3D "" + else: + post_data =3D data + req =3D urllib.request.Request(url, data=3Dbytes(post_data, encodi= ng=3D"utf-8")) + if content_type is not None: + req.add_header('Content-Type', content_type) + req.get_method =3D lambda: request_method.upper() + resp =3D opener.open(req) + cookie.save(ignore_discard=3DTrue, ignore_expires=3DTrue) + respdata =3D resp.read() + logging.debug("Server response:\n%s" % (respdata or "")) + if respdata: + r =3D json.loads(respdata.decode("utf-8")) + else: + r =3D None + return r + def do(self, args, argv): """Do command""" print("Not implemented") --=20 2.15.1 (Apple Git-101) _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel From nobody Fri Apr 19 18:42:10 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=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1530212868992833.587309621801; Thu, 28 Jun 2018 12:07:48 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 760C887650; Thu, 28 Jun 2018 19:07:48 +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 645C4309128B; Thu, 28 Jun 2018 19:07:48 +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 5862718037EC; Thu, 28 Jun 2018 19:07:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w5SJ7lJG006818 for ; Thu, 28 Jun 2018 15:07:47 -0400 Received: by smtp.corp.redhat.com (Postfix) id F2F3C1992A; Thu, 28 Jun 2018 19:07:46 +0000 (UTC) Received: from mx1.redhat.com (ext-mx16.extmail.prod.ext.phx2.redhat.com [10.5.110.45]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EA1A829A7C for ; Thu, 28 Jun 2018 19:07:44 +0000 (UTC) Received: from mail-pl0-f52.google.com (mail-pl0-f52.google.com [209.85.160.52]) (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 4AB533082A2C for ; Thu, 28 Jun 2018 19:07:33 +0000 (UTC) Received: by mail-pl0-f52.google.com with SMTP id w8-v6so3224292ply.8 for ; Thu, 28 Jun 2018 12:07:33 -0700 (PDT) Received: from localhost.localdomain ([112.196.135.52]) by smtp.gmail.com with ESMTPSA id r65-v6sm13446990pfg.65.2018.06.28.12.07.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 28 Jun 2018 12:07:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=xbfo8MRudxocCVmkf+EfcTtO2VrbwzC6cgaxwUfGM0s=; b=EV9ToD9Sg+nOhCtolIyKrKsz8kefm39k0bR91K3zgL98UKdfSysW2mAi/zeVLm/Dco 3HXrxuY4ERnXgP16iPb5SdvcdIgVXBuqynZOH5mj9suy2kMM7vVJnSoHwiRk6hYG2vLk QEsBTDbvLOzEEqzjz9WfU39Q/szn+RtrbpKQQLGnUbmXl5jCT5yCpwz29v+Ddxel5PN4 oLMBvLnDG529fRjI44Tr1OVRv7d+UzJA9MDDpOu8vpu0ajLH6Alc8izHHraUIlI6sv59 9JSYNVbCWoPR7YuZtOzanU5P83notSaxLD2VX5ZMXIki5DsjX6S20XOzIKgqBAlwz2WB 69jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=xbfo8MRudxocCVmkf+EfcTtO2VrbwzC6cgaxwUfGM0s=; b=lyUU0ju2Cxj88wHeinv/T8BEkwd+M9xWrQupd9rC0ImPhvs+mtHAhqLeRGRS+ivvwS DZp719BMAF1AQlWVcZURpXDHqFX7sqUNISYkA2CWIZeAwfm7wA+48RJ2vf2qDAlFjXyg zgu4NbZK6Ndzmlf9qWwDZCb4HQ2Ifllv9+CQBRhKpolWYsGACVg2rcw3J3nFtQ+Vo7lS ZuKTCO1B09WDweK9zAU1RFqsXdg9Y4o69ySYa962UOgaIaeJ04mTkNI0ZVny9uKk3MOS ZLl0ghPEldosq9BExS/KBZJwVw8MODaTWZ4S3ZR9p7zJLmb6BJqvHeyxooxlJru+IK5h MhWg== X-Gm-Message-State: APt69E3WDVj5TBPC8PZQwoAJ4aICck4GGPyxOhtIGWc/UJN0RFi9/g08 0jmFzy2S/+IzeODaU8oKyTq4mA== X-Google-Smtp-Source: AAOMgpeDPsY3znSgWmOgHWfhaWNvdz3GM4G+z1ognj+64YddL3c+w8rgF9jSgVYZuAqeqrqjtp16/Q== X-Received: by 2002:a17:902:6047:: with SMTP id a7-v6mr4104226plt.188.1530212852325; Thu, 28 Jun 2018 12:07:32 -0700 (PDT) From: Shubham Jain To: patchew-devel@redhat.com Date: Fri, 29 Jun 2018 00:37:06 +0530 Message-Id: <20180628190706.79163-3-shubhamjain7495@gmail.com> In-Reply-To: <20180628190706.79163-1-shubhamjain7495@gmail.com> References: <20180628190706.79163-1-shubhamjain7495@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Thu, 28 Jun 2018 19:07:33 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Thu, 28 Jun 2018 19:07:33 +0000 (UTC) for IP:'209.85.160.52' DOMAIN:'mail-pl0-f52.google.com' HELO:'mail-pl0-f52.google.com' FROM:'shubhamjain7495@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.551 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, SPF_PASS, T_DKIM_INVALID) 209.85.160.52 mail-pl0-f52.google.com 209.85.160.52 mail-pl0-f52.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.45 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: patchew-devel@redhat.com Cc: Shubham Jain Subject: [Patchew-devel] [PATCH 2/2] Make Patchew cli use 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: patchew-devel-bounces@redhat.com Errors-To: patchew-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 28 Jun 2018 19:07:48 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Make project functions use the rest_api_do instead of api_do --- patchew-cli | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/patchew-cli b/patchew-cli index c53526b..cde2386 100755 --- a/patchew-cli +++ b/patchew-cli @@ -256,11 +256,11 @@ class ProjectCommand(SubCommand): parser.add_argument("--verbose", "-v", action=3D"store_true", help=3D"Show details about projects") args =3D parser.parse_args(argv) - r =3D self.api_do("get-projects") + r =3D self.rest_api_do(url_cmd=3D"projects", request_method=3D'get= ') if args.raw: print(json.dumps(r, indent=3D2, separators=3D",:")) return 0 - for p in r: + for p in r['results']: print(p["name"]) if args.verbose: for k, v in p.items(): @@ -274,8 +274,8 @@ class ProjectCommand(SubCommand): parser.add_argument("name", nargs=3D"+", help=3D"The name of project to show info") args =3D parser.parse_args(argv) - r =3D self.api_do("get-projects") - for p in r: + r =3D self.rest_api_do(url_cmd=3D"projects", request_method=3D'get= ') + for p in r['results']: if not p["name"] in args.name: continue if len(args.name) > 1: @@ -298,12 +298,15 @@ class ProjectCommand(SubCommand): parser.add_argument("--desc", "-d", default=3D"", help=3D"Project short discription") args =3D parser.parse_args(argv) - self.api_do("add-project", - name=3Dargs.name, - mailing_list=3Dargs.mailing_list, - url=3Dargs.url, - git=3Dargs.git, - description=3Dargs.desc) + data =3D {'name':args.name, + 'mailing_list':args.mailing_list, + 'url':args.url, + 'git':args.git, + 'description':args.desc} + self.rest_api_do(url_cmd=3D"projects", + request_method=3D'post', + content_type=3D'application/json', + data=3Djson.dumps(data)) =20 def update_one_project(self, wd, project): logging.info("Updating project '%s'", project["name"]) @@ -355,16 +358,17 @@ class ProjectCommand(SubCommand): except Exception as e: logging.warn("Failed to push the new head to patchew mirro= r: %s", str(e)) - self.api_do("update-project-head", project=3Dproject["name"], - old_head=3Dold_head, - new_head=3Dnew_head, - message_ids=3Dmsgids) + url =3D project['resource_uri'] + "/update_project_head/" + self.rest_api_do(url, old_head=3Dold_head, + new_head=3Dnew_head, + message_ids=3Dmsgids) =20 def update_project(self, argv): parser =3D argparse.ArgumentParser() parser.add_argument("--name", "-n", help=3D"Name of the project") args =3D parser.parse_args(argv) - projects =3D self.api_do("get-projects", name=3Dargs.name) + projects =3D self.rest_api_do("projects") + projects =3D [p for p in projects['results'] if p['name'] =3D=3D a= rgs.name] wd =3D tempfile.mkdtemp() logging.debug("TMPDIR: %s", wd) try: @@ -415,6 +419,7 @@ class ProjectCommand(SubCommand): return self.update_project(argv[1:]) return self.list_projects(argv) =20 + class SearchCommand(SubCommand): name =3D "search" =20 --=20 2.15.1 (Apple Git-101) _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel