From nobody Tue May 13 12:48:28 2025 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 1530870173483268.70770294704096; Fri, 6 Jul 2018 02:42:53 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D29E93082A3B; Fri, 6 Jul 2018 09:42:52 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C4F432010CBC; Fri, 6 Jul 2018 09:42:52 +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 B51054BB78; Fri, 6 Jul 2018 09:42:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w669gqOK011997 for ; Fri, 6 Jul 2018 05:42:52 -0400 Received: by smtp.corp.redhat.com (Postfix) id 441EC2AFD7; Fri, 6 Jul 2018 09:42:52 +0000 (UTC) Received: from mx1.redhat.com (ext-mx18.extmail.prod.ext.phx2.redhat.com [10.5.110.47]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 33B252CFA2 for ; Fri, 6 Jul 2018 09:42:49 +0000 (UTC) Received: from mail-pf0-f195.google.com (mail-pf0-f195.google.com [209.85.192.195]) (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 B8C3F30820E5 for ; Fri, 6 Jul 2018 09:42:38 +0000 (UTC) Received: by mail-pf0-f195.google.com with SMTP id j17-v6so7992609pfn.5 for ; Fri, 06 Jul 2018 02:42:38 -0700 (PDT) Received: from localhost.localdomain ([182.74.40.122]) by smtp.gmail.com with ESMTPSA id r87-v6sm15257688pfb.1.2018.07.06.02.42.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 06 Jul 2018 02:42:36 -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=pA9h1+plKOt+mHUNRVF+QEMpRhSu3h50lxWkQkW8fE8=; b=FC9Tn6vbDF3yeF6TNR5zH2tfY320c7VBm328rvtS3mOc6R4PIL/9yQTrx1Z1zhOrsn k+9AI9gWU0Q7xeuMQMta2tnBq7MIfrRlNM1dB1ciM6kga8C9fenqKFPdWblEvzFZ+v9L lBpW2JLibt+YATbAv5/f8pKe/VtXnW0iLRufHccDafSdLNaELmlC5/dAyO7qt1DAVnfM b4N9ojf7SLQZ+RyaPQbcmMMxEy2+dc3mNIrCOvpNYJqcAPkV7ZnsewrJ2G2oFswwqMMw GTp/TJSqvRe5PZwFe/u7ATCWONDJYtfzXoOLyOFnPsrUtrORpefr00Dm9Av9/d7yZqfP x2qg== 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=pA9h1+plKOt+mHUNRVF+QEMpRhSu3h50lxWkQkW8fE8=; b=E/YaAYJlKV0AFgHTBGKjaHdFIr77BaGGuIuA9tiuySUTc75TD8/5JbME7+kZBqnF0D M2K2dHvOCoSENpylK9/xc/ZlkdK/4EKSknSnOchHAIvfzPr+/Yh7uub7QmSKUVoLr48z Nq8MfqixAEcnvUITf1fkfFOA7z95ieUF7gviSdPakwEWTGOZNl4bfVr2v/4TJ7pgiKn4 k0lvZMYgMuqo+84h7SO7wlJLuhqoCsiZHLSpsdGSPeHY7+eopi/poTVmM8M9Nwh+nnMJ 9PtfW3vh7y793B6dYHjPhES2wpWZnQ1Rcye70Nc0N0JRPauLO3ewvOexCo3vd8qcYi/w D8Rg== X-Gm-Message-State: APt69E1X5zHe+xgVV3swpNAs0Kh9Ew4ZH1y8qTneY2NzUTUJ918Ah2VH EFDBSN5Bo9Xde4If/xaGfnFdfA== X-Google-Smtp-Source: AAOMgpdViZCnvwyAO2Klhrrs0zXK0ksWcQBCim8C4fywYG7wiE12jYCCl4gZdmTet3bns3Kl7E+AfA== X-Received: by 2002:a63:3201:: with SMTP id y1-v6mr8902539pgy.419.1530870157757; Fri, 06 Jul 2018 02:42:37 -0700 (PDT) From: Shubham Jain To: patchew-devel@redhat.com Date: Fri, 6 Jul 2018 15:09:44 +0530 Message-Id: <20180706093947.20025-2-shubhamjain7495@gmail.com> In-Reply-To: <20180706093947.20025-1-shubhamjain7495@gmail.com> References: <20180706093947.20025-1-shubhamjain7495@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Fri, 06 Jul 2018 09:42:38 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Fri, 06 Jul 2018 09:42:38 +0000 (UTC) for IP:'209.85.192.195' DOMAIN:'mail-pf0-f195.google.com' HELO:'mail-pf0-f195.google.com' FROM:'shubhamjain7495@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.55 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_PASS, T_DKIM_INVALID) 209.85.192.195 mail-pf0-f195.google.com 209.85.192.195 mail-pf0-f195.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.47 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: patchew-devel@redhat.com Cc: Shubham Jain Subject: [Patchew-devel] [PATCH v3 1/4] 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.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Fri, 06 Jul 2018 09:42:52 +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 | 6 ++++++ patchew-cli | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/api/rest.py b/api/rest.py index 9ec0ae8..66644ba 100644 --- a/api/rest.py +++ b/api/rest.py @@ -25,7 +25,13 @@ 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 =20 +class CsrfExemptSessionAuthentication(SessionAuthentication): + + def enforce_csrf(self, request): + return # To not perform the csrf check previously happening + =20 SEARCH_PARAM =3D 'q' =20 # patchew-specific permission classes diff --git a/patchew-cli b/patchew-cli index 174d1e6..e510e74 100755 --- a/patchew-cli +++ b/patchew-cli @@ -92,6 +92,40 @@ 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"), method=3Drequest_method.upper()) + if content_type is not None: + req.add_header('Content-Type', content_type) + 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